Author: tchemit Date: 2010-12-29 18:54:25 +0100 (Wed, 29 Dec 2010) New Revision: 1991 Url: http://nuiton.org/repositories/revision/nuiton-utils/1991 Log: - Depreciates TestUtil - Add some usefull methods on BinderFactory to obtain cached binder model Modified: trunk/src/main/java/org/nuiton/util/TestUtil.java trunk/src/main/java/org/nuiton/util/beans/BinderFactory.java Modified: trunk/src/main/java/org/nuiton/util/TestUtil.java =================================================================== --- trunk/src/main/java/org/nuiton/util/TestUtil.java 2010-12-29 15:30:39 UTC (rev 1990) +++ trunk/src/main/java/org/nuiton/util/TestUtil.java 2010-12-29 17:54:25 UTC (rev 1991) @@ -38,8 +38,9 @@ * Created: 22 juin 2010 * * @author fdesbois <fdesbois@codelutin.com> - * @version $Id$ + * @deprecated since 1.5.3, will not be replaced here and will be removed in 2.0 */ +@Deprecated public class TestUtil { private static Log log = LogFactory.getLog(TestUtil.class); Modified: trunk/src/main/java/org/nuiton/util/beans/BinderFactory.java =================================================================== --- trunk/src/main/java/org/nuiton/util/beans/BinderFactory.java 2010-12-29 15:30:39 UTC (rev 1990) +++ trunk/src/main/java/org/nuiton/util/beans/BinderFactory.java 2010-12-29 17:54:25 UTC (rev 1991) @@ -25,14 +25,14 @@ * <pre> * Binder<BeanA, BeanA> binder = BinderFactory.newBinder(BeanA.class, "mycontext"); * </pre> - * + * <p/> * This is usefull when you register your own binder model in the factory (see * next section) to bind different things from the same type of objects... - * + * <p/> * <h1>Register a new binder model</h1> * To register a new binder's model use one of the method {@code registerBinderModel(XXX)}. * <p/> - * + * <p/> * More documentation will come soon, yu can see the package info javadoc or * unit tests... * @@ -190,7 +190,43 @@ } } + /** + * Tells if there is a cached binder model for the given parameters. + * + * @param sourceType the type of source + * @param targetType the type of target + * @param contextName the context's name of the searched binder + * @param <S> the type of source + * @param <T> the type of target + * @return {@code true} if there is a cached binder model for the given + * parameters, {@code false} otherwise. + */ + public static <S, T> boolean isBinderModelExists(Class<S> sourceType, + Class<T> targetType, + String contextName) { + Binder.BinderModel<S, T> model = + getBinderModels().get(sourceType, targetType, contextName); + return model != null; + } + /** + * Obtain a cached binder model. + * + * @param sourceType the type of source + * @param targetType the type of target + * @param contextName the context's name of the searched binder + * @param <S> the type of source + * @param <T> the type of target + * @return the cached binder model or {@code null} if not found. + */ + public static <S, T> Binder.BinderModel<S, T> getCachedBinderModel(Class<S> sourceType, + Class<T> targetType, + String contextName) { + Binder.BinderModel<S, T> model = + getBinderModels().get(sourceType, targetType, contextName); + return model; + } + protected static BindelModelEntryMap getBinderModels() { if (binderModels == null) { binderModels = new BindelModelEntryMap(); @@ -207,7 +243,10 @@ } /** - * Gets the registred binder given his types and his context's name. + * Instanciate a new binder given his types and his context's name. + * <p/> + * If the corresponding binder model does not exist, then it will be created + * and cached (using the {@link BinderModelBuilder#newDefaultBuilder(Class, Class)} method). * * @param sourceType the type of source * @param targetType the type of target @@ -215,7 +254,7 @@ * @param binderType type of binder required * @param <S> the type of source * @param <T> the type of target - * @return the registred binder or {@code null} if not found. + * @return the new instanciated binder. */ protected static <S, T, B extends Binder<S, T>> Binder<S, T> newBinder0(Class<S> sourceType, Class<T> targetType,