Author: tchemit Date: 2011-08-04 14:48:03 +0200 (Thu, 04 Aug 2011) New Revision: 2162 Url: http://nuiton.org/repositories/revision/nuiton-utils/2162 Log: Evolution #1643: New decorator api (from jaxx-runtime project) Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtil.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/package-info.java Removed: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtils.java Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/Decorator.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorMulti18nProvider.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorProvider.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/JXPathDecorator.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MapPropertyHandler.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MultiJXPathDecorator.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/PropertyDecorator.java trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/Data.java trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorMulti18nProviderTest.java trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorProviderTest.java trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathContextTester.java trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathDecoratorTest.java trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MapPropertyHandlerTest.java trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MultiJXPathDecoratorTest.java Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/Decorator.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/Decorator.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/Decorator.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -29,22 +29,22 @@ /** * A simple contract to define a String decorator on any java object. * + * @param <O> the type of data to decorate * @author tchemit <chemit@codelutin.com> - * @param <O> the type of data to decorate - * @since 2.2.1 + * @since 2.3 */ public abstract class Decorator<O> implements Serializable { private static final long serialVersionUID = -1L; /** Type of the data to decorate */ - protected final Class<O> internalClass; + protected final Class<O> type; - public Decorator(Class<O> internalClass) throws NullPointerException { - if (internalClass == null) { - throw new NullPointerException("internalClass can not be null."); + public Decorator(Class<O> type) throws NullPointerException { + if (type == null) { + throw new NullPointerException("type can not be null."); } - this.internalClass = internalClass; + this.type = type; } /** @@ -53,7 +53,16 @@ */ public abstract String toString(Object bean); + public Class<O> getType() { + return type; + } + + /** + * @return the internal type of object that can be decorated by this decorator. + * @deprecated is remplaced by {@link #getType()} and will be removed soon + */ + @Deprecated public Class<O> getInternalClass() { - return internalClass; + return getType(); } } Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorMulti18nProvider.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorMulti18nProvider.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorMulti18nProvider.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -44,7 +44,7 @@ * <p/> * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public abstract class DecoratorMulti18nProvider { @@ -96,7 +96,7 @@ O object, String name) { Class<O> k = (Class<O>) object.getClass(); - return getDecorator(locale, k, name); + return getDecoratorByType(locale, k, name); } /** @@ -107,9 +107,9 @@ * @param <O> type of decorated object * @return the decorator or {@code null} if not found */ - public <O> Decorator<O> getDecorator(Locale locale, - Class<O> type) { - return getDecorator(locale, type, null); + public <O> Decorator<O> getDecoratorByType(Locale locale, + Class<O> type) { + return getDecoratorByType(locale, type, null); } /** @@ -122,9 +122,9 @@ * @param <O> type of decorated object * @return the decorator or {@code null} if not found */ - public <O> Decorator<O> getDecorator(Locale locale, - Class<O> type, - String name) { + public <O> Decorator<O> getDecoratorByType(Locale locale, + Class<O> type, + String name) { DecoratorContext<O> d = getDecoratorContext(locale, type, name, true); return d == null ? null : d.getDecorator(); } @@ -211,7 +211,7 @@ String name, String expression) { Decorator<?> decorator = - DecoratorUtils.newPropertyDecorator(klass, expression); + DecoratorUtil.newPropertyDecorator(klass, expression); registerDecorator(locale, name, decorator); } @@ -220,7 +220,7 @@ String name, String expression) { Decorator<?> decorator = - DecoratorUtils.newJXPathDecorator(klass, expression); + DecoratorUtil.newJXPathDecorator(klass, expression); registerDecorator(locale, name, decorator); } @@ -230,7 +230,7 @@ String expression, String separator, String separatorReplacement) { - Decorator<?> decorator = DecoratorUtils.newMultiJXPathDecorator( + Decorator<?> decorator = DecoratorUtil.newMultiJXPathDecorator( klass, expression, separator, separatorReplacement ); registerDecorator(locale, name, decorator); Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorProvider.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorProvider.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorProvider.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -40,7 +40,7 @@ * <p/> * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public abstract class DecoratorProvider { @@ -81,7 +81,7 @@ @SuppressWarnings({"unchecked"}) public <O> Decorator<O> getDecorator(O object, String name) { Class<O> k = (Class<O>) object.getClass(); - return getDecorator(k, name); + return getDecoratorByType(k, name); } /** @@ -91,8 +91,8 @@ * @param <O> type of decorated object * @return the decorator or {@code null} if not found */ - public <O> Decorator<O> getDecorator(Class<O> type) { - return getDecorator(type, null); + public <O> Decorator<O> getDecoratorByType(Class<O> type) { + return getDecoratorByType(type, null); } /** @@ -103,7 +103,7 @@ * @param <O> type of decorated object * @return the decorator or {@code null} if not found */ - public <O> Decorator<O> getDecorator(Class<O> type, String name) { + public <O> Decorator<O> getDecoratorByType(Class<O> type, String name) { DecoratorContext<O> d = getDecoratorContext(type, name); return d == null ? null : d.getDecorator(); } @@ -140,7 +140,7 @@ String name, String expression) { Decorator<?> decorator = - DecoratorUtils.newPropertyDecorator(klass, expression); + DecoratorUtil.newPropertyDecorator(klass, expression); registerDecorator(name, decorator); } @@ -148,7 +148,7 @@ String name, String expression) { Decorator<?> decorator = - DecoratorUtils.newJXPathDecorator(klass, expression); + DecoratorUtil.newJXPathDecorator(klass, expression); registerDecorator(name, decorator); } @@ -157,7 +157,7 @@ String expression, String separator, String separatorReplacement) { - Decorator<?> decorator = DecoratorUtils.newMultiJXPathDecorator( + Decorator<?> decorator = DecoratorUtil.newMultiJXPathDecorator( klass, expression, separator, separatorReplacement ); registerDecorator(name, decorator); Copied: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtil.java (from rev 2160, trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtils.java) =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtil.java (rev 0) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtil.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -0,0 +1,300 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Utils + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package org.nuiton.util.decorator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.decorator.JXPathDecorator.Context; +import org.nuiton.util.decorator.JXPathDecorator.JXPathComparator; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Some usefull methods on {@link Decorator} to create, and sort data with + * decorators. + * <p/> + * To create a new decorator, use one of the methods : <ul> <li>{@link + * #newPropertyDecorator(Class, String)}</li> <li>{@link + * #newJXPathDecorator(Class, String)}</li> <li> + * {@link #newMultiJXPathDecorator(Class, String, String)})</li> + * <li>{@link #newMultiJXPathDecorator(Class, String, String, String)})</li> + * </ul> + * <p/> + * To sort a list of data, using a {@link JXPathDecorator}, use the method + * {@link #sort(JXPathDecorator, List, int)}. + * <p/> + * + * @author tchemit <chemit@codelutiln.com> + * @since 2.3 + */ +public class DecoratorUtil { + + /** Logger */ + private static final Log log = LogFactory.getLog(DecoratorUtil.class); + + + /** + * Factory method to instanciate a new {@link PropertyDecorator} for the + * given class {@code internlaClass} and a readable property name. + * + * @param type the class of the objects decorated by the new + * decorator + * @param property the property + * @param <O> the generic type of class to be decorated by the new + * decorator + * @return the new instanciated decorator + * @throws IllegalArgumentException if the expression is not valid, says: + * <p/> + * - a missing right brace was detected. + * <p/> + * - a ${ was found in a jxpath token. + * @throws NullPointerException if type parameter is null. + */ + public static <O> PropertyDecorator<O> newPropertyDecorator( + Class<O> type, + String property) + throws IllegalArgumentException, NullPointerException { + return new PropertyDecorator<O>(type, property); + } + + /** + * Factory method to instanciate a new {@link JXPathDecorator} for the given + * class {@code internalClass} and expression. + * + * @param type the class of the objects decorated by the new + * decorator + * @param expression the expression to use to decorated objects + * @param <O> the generic type of class to be decorated by the new + * decorator + * @return the new instanciated decorator + * @throws IllegalArgumentException if the expression is not valid, says: + * <p/> + * - a missing right brace was detected. + * <p/> + * - a ${ was found in a jxpath token. + * @throws NullPointerException if type parameter is null. + */ + public static <O> JXPathDecorator<O> newJXPathDecorator( + Class<O> type, + String expression) + throws IllegalArgumentException, NullPointerException { + + Context<O> context = createJXPathContext(expression); + return new JXPathDecorator<O>(type, expression, context); + } + + public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator( + Class<O> type, + String expression, + String separator) + throws IllegalArgumentException, NullPointerException { + + MultiJXPathDecorator<O> decorator = newMultiJXPathDecorator( + type, + expression, + separator, + separator); + return decorator; + } + + public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator( + Class<O> type, + String expression, + String separator, + String separatorReplacement) + throws IllegalArgumentException, NullPointerException { + + Context<O>[] contexts = createMultiJXPathContext( + expression, + separator, + separatorReplacement); + + return new MultiJXPathDecorator<O>( + type, + expression, + separator, + separatorReplacement, + contexts); + } + + /** + * Sort a list of data based on the first token property of a given context + * in a given decorator. + * + * @param <O> type of data to sort + * @param decorator the decorator to use to sort + * @param datas the list of data to sort + * @param pos the index of context to used in decorator to obtain + * sorted property. + */ + public static <O> void sort(JXPathDecorator<O> decorator, + List<O> datas, + int pos) { + sort(decorator, datas, pos, false); + } + + /** + * Sort a list of data based on the first token property of a given context + * in a given decorator. + * + * @param <O> type of data to sort + * @param decorator the decorator to use to sort + * @param datas the list of data to sort + * @param pos the index of context to used in decorator to obtain + * sorted property. + * @param reverse flag to sort in reverse order if sets to {@code true} + * @since 2.2 + */ + public static <O> void sort(JXPathDecorator<O> decorator, + List<O> datas, + int pos, + boolean reverse) { + Comparator<O> c = null; + boolean cachedComparator = false; + try { + c = decorator.getComparator(pos); + cachedComparator = c instanceof JXPathComparator<?>; + + if (cachedComparator) { + ((JXPathComparator<O>) c).init(decorator, datas); + } + Collections.sort(datas, c); + if (reverse) { + + // reverse order + Collections.reverse(datas); + } + } finally { + if (cachedComparator) { + ((JXPathComparator<?>) c).clear(); + } + } + } + + public static <O> Context<O> createJXPathContext(String expression) { + List<String> lTokens = new ArrayList<String>(); + StringBuilder buffer = new StringBuilder(); + int size = expression.length(); + int end = -1; + int start; + while ((start = expression.indexOf("${", end + 1)) > -1) { + if (start > end + 1) { + + // prefix of next jxpath token + buffer.append(expression.substring(end + 1, start)); + } + + // seek end of jxpath + end = expression.indexOf("}", start + 1); + if (end == -1) { + throw new IllegalArgumentException( + "could not find the rigth brace starting at car " + + start + " : " + expression.substring(start + 2)); + } + String jxpath = expression.substring(start + 2, end); + + // not allowed ${ inside a jxpath token + if (jxpath.contains("${")) { + throw new IllegalArgumentException( + "could not find a ${ inside a jxpath expression at " + + "car " + (start + 2) + " : " + jxpath); + } + + // save the jxpath token + lTokens.add(jxpath); + + // replace jxpath token in expresion with a string format variable + buffer.append('%').append(lTokens.size()); + } + if (size > end + 1) { + + // suffix after end jxpath (or all expression if no jxpath) + buffer.append(expression.substring(end + 1)); + } + String[] tokens = lTokens.toArray(new String[lTokens.size()]); + return new Context<O>(buffer.toString(), tokens); + } + + public static <O> Context<O>[] createMultiJXPathContext( + String expression, + String separator, + String separatorReplacement) { + int sep = expression.indexOf(separator); + if (sep == -1) { + Context<O>[] result = newInstance(1); + result[0] = createJXPathContext(expression); + return result; + } + + List<String> tokens = new ArrayList<String>(); + StringTokenizer stk = new StringTokenizer(expression, separator); + while (stk.hasMoreTokens()) { + tokens.add(stk.nextToken()); + } + + int nbTokens = tokens.size(); + Context<O>[] contexts = newInstance(nbTokens); + if (log.isDebugEnabled()) { + log.debug("Will prepare " + nbTokens + " contexts from [" + expression + "]"); + } + for (int i = 0; i < nbTokens; i++) { + StringBuilder buffer = new StringBuilder(expression.length()); + for (int j = 0; j < nbTokens; j++) { + int index = (i + j) % nbTokens; + String str = tokens.get(index); + + //replace all '%(index+1)$' pattern with '%(j+1)$' + Pattern p = Pattern.compile("\\%(" + (index + 1) + ")\\$"); + Matcher matcher = p.matcher(str); + String safeStr = matcher.replaceAll("\\%" + (j + 1) + "\\$"); + + if (log.isDebugEnabled()) { + log.debug("[" + (index + 1) + "-->" + (j + 1) + "] " + str + + " transformed to " + safeStr); + } + buffer.append(separatorReplacement).append(safeStr); + } + String expr = buffer.substring(separatorReplacement.length()); + if (log.isDebugEnabled()) { + log.debug("context [" + i + "] : " + expr); + } + contexts[i] = createJXPathContext( + expr); + } + return contexts; + } + + @SuppressWarnings("unchecked") + protected static <O> Context<O>[] newInstance(int size) { + // fixme how to instanciate a typed array with no checking warning ? + return new Context[size]; + } +} Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtil.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtils.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtils.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorUtils.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -1,300 +0,0 @@ -/* - * #%L - * Nuiton Utils :: Nuiton Utils - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 CodeLutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ -package org.nuiton.util.decorator; - -import org.nuiton.util.decorator.JXPathDecorator.Context; -import org.nuiton.util.decorator.JXPathDecorator.JXPathComparator; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Some usefull methods on {@link Decorator} to create, and sort data with - * decorators. - * <p/> - * To create a new decorator, use one of the methods : <ul> <li>{@link - * #newPropertyDecorator(Class, String)}</li> <li>{@link - * #newJXPathDecorator(Class, String)}</li> <li> - * {@link #newMultiJXPathDecorator(Class, String, String)})</li> - * <li>{@link #newMultiJXPathDecorator(Class, String,String, String)})</li> - * </ul> - * <p/> - * To sort a list of data, using a {@link JXPathDecorator}, use the method - * {@link #sort(JXPathDecorator, List, int)}. - * <p/> - * - * @author tchemit <chemit@codelutiln.com> - * @since 2.2.1 - */ -public class DecoratorUtils { - - /** Logger */ - private static final Log log = LogFactory.getLog(DecoratorUtils.class); - - - /** - * Factory method to instanciate a new {@link PropertyDecorator} for the - * given class {@code internlaClass} and a readable property name. - * - * @param internalClass the class of the objects decorated by the new - * decorator - * @param property the property - * @param <O> the generic type of class to be decorated by the new - * decorator - * @return the new instanciated decorator - * @throws IllegalArgumentException if the expression is not valid, says: - * <p/> - * - a missing right brace was detected. - * <p/> - * - a ${ was found in a jxpath token. - * @throws NullPointerException if internalClass parameter is null. - */ - public static <O> PropertyDecorator<O> newPropertyDecorator( - Class<O> internalClass, - String property) - throws IllegalArgumentException, NullPointerException { - return new PropertyDecorator<O>(internalClass, property); - } - - /** - * Factory method to instanciate a new {@link JXPathDecorator} for the given - * class {@code internalClass} and expression. - * - * @param internalClass the class of the objects decorated by the new - * decorator - * @param expression the expression to use to decorated objects - * @param <O> the generic type of class to be decorated by the new - * decorator - * @return the new instanciated decorator - * @throws IllegalArgumentException if the expression is not valid, says: - * <p/> - * - a missing right brace was detected. - * <p/> - * - a ${ was found in a jxpath token. - * @throws NullPointerException if internalClass parameter is null. - */ - public static <O> JXPathDecorator<O> newJXPathDecorator( - Class<O> internalClass, - String expression) - throws IllegalArgumentException, NullPointerException { - - Context<O> context = createJXPathContext(expression); - return new JXPathDecorator<O>(internalClass, expression, context); - } - - public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator( - Class<O> internalClass, - String expression, - String separator) - throws IllegalArgumentException, NullPointerException { - - MultiJXPathDecorator<O> decorator = newMultiJXPathDecorator( - internalClass, - expression, - separator, - separator); - return decorator; - } - - public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator( - Class<O> internalClass, - String expression, - String separator, - String separatorReplacement) - throws IllegalArgumentException, NullPointerException { - - Context<O>[] contexts = createMultiJXPathContext( - expression, - separator, - separatorReplacement); - - return new MultiJXPathDecorator<O>( - internalClass, - expression, - separator, - separatorReplacement, - contexts); - } - - /** - * Sort a list of data based on the first token property of a given context - * in a given decorator. - * - * @param <O> type of data to sort - * @param decorator the decorator to use to sort - * @param datas the list of data to sort - * @param pos the index of context to used in decorator to obtain - * sorted property. - */ - public static <O> void sort(JXPathDecorator<O> decorator, - List<O> datas, - int pos) { - sort(decorator, datas, pos, false); - } - - /** - * Sort a list of data based on the first token property of a given context - * in a given decorator. - * - * @param <O> type of data to sort - * @param decorator the decorator to use to sort - * @param datas the list of data to sort - * @param pos the index of context to used in decorator to obtain - * sorted property. - * @param reverse flag to sort in reverse order if sets to {@code true} - * @since 2.2 - */ - public static <O> void sort(JXPathDecorator<O> decorator, - List<O> datas, - int pos, - boolean reverse) { - Comparator<O> c = null; - boolean cachedComparator = false; - try { - c = decorator.getComparator(pos); - cachedComparator = c instanceof JXPathComparator<?>; - - if (cachedComparator) { - ((JXPathComparator<O>) c).init(decorator, datas); - } - Collections.sort(datas, c); - if (reverse) { - - // reverse order - Collections.reverse(datas); - } - } finally { - if (cachedComparator) { - ((JXPathComparator<?>) c).clear(); - } - } - } - - public static <O> Context<O> createJXPathContext(String expression) { - List<String> lTokens = new ArrayList<String>(); - StringBuilder buffer = new StringBuilder(); - int size = expression.length(); - int end = -1; - int start; - while ((start = expression.indexOf("${", end + 1)) > -1) { - if (start > end + 1) { - - // prefix of next jxpath token - buffer.append(expression.substring(end + 1, start)); - } - - // seek end of jxpath - end = expression.indexOf("}", start + 1); - if (end == -1) { - throw new IllegalArgumentException( - "could not find the rigth brace starting at car " + - start + " : " + expression.substring(start + 2)); - } - String jxpath = expression.substring(start + 2, end); - - // not allowed ${ inside a jxpath token - if (jxpath.contains("${")) { - throw new IllegalArgumentException( - "could not find a ${ inside a jxpath expression at " + - "car " + (start + 2) + " : " + jxpath); - } - - // save the jxpath token - lTokens.add(jxpath); - - // replace jxpath token in expresion with a string format variable - buffer.append('%').append(lTokens.size()); - } - if (size > end + 1) { - - // suffix after end jxpath (or all expression if no jxpath) - buffer.append(expression.substring(end + 1)); - } - String[] tokens = lTokens.toArray(new String[lTokens.size()]); - return new Context<O>(buffer.toString(), tokens); - } - - public static <O> Context<O>[] createMultiJXPathContext( - String expression, - String separator, - String separatorReplacement) { - int sep = expression.indexOf(separator); - if (sep == -1) { - Context<O>[] result = newInstance(1); - result[0] = createJXPathContext(expression); - return result; - } - - List<String> tokens = new ArrayList<String>(); - StringTokenizer stk = new StringTokenizer(expression, separator); - while (stk.hasMoreTokens()) { - tokens.add(stk.nextToken()); - } - - int nbTokens = tokens.size(); - Context<O>[] contexts = newInstance(nbTokens); - if (log.isDebugEnabled()) { - log.debug("Will prepare " + nbTokens + " contexts from [" + expression + "]"); - } - for (int i = 0; i < nbTokens; i++) { - StringBuilder buffer = new StringBuilder(expression.length()); - for (int j = 0; j < nbTokens; j++) { - int index = (i + j) % nbTokens; - String str = tokens.get(index); - - //replace all '%(index+1)$' pattern with '%(j+1)$' - Pattern p = Pattern.compile("\\%(" + (index + 1) + ")\\$"); - Matcher matcher = p.matcher(str); - String safeStr = matcher.replaceAll("\\%" + (j + 1) + "\\$"); - - if (log.isDebugEnabled()) { - log.debug("[" + (index + 1) + "-->" + (j + 1) + "] " + str + - " transformed to " + safeStr); - } - buffer.append(separatorReplacement).append(safeStr); - } - String expr = buffer.substring(separatorReplacement.length()); - if (log.isDebugEnabled()) { - log.debug("context [" + i + "] : " + expr); - } - contexts[i] = createJXPathContext( - expr); - } - return contexts; - } - - @SuppressWarnings("unchecked") - protected static <O> Context<O>[] newInstance(int size) { - // fixme how to instanciate a typed array with no checking warning ? - return new Context[size]; - } -} Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/JXPathDecorator.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/JXPathDecorator.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/JXPathDecorator.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -46,7 +46,7 @@ * <p/> * For example : * <pre> - * Decorator<Object> d = DecoratorUtils.newJXPathDecorator( + * Decorator<Object> d = DecoratorUtil.newJXPathDecorator( * JXPathDecorator.class,"expr = ${expressions}$s"); * assert "expr = %1$s" == d.getExpression(); * assert 1 == d.getNbToken(); @@ -57,7 +57,7 @@ * @param <O> type of data to decorate * @author tchemit <chemit@codelutin.com> * @see Decorator - * @since 2.2.1 + * @since 2.3 */ public class JXPathDecorator<O> extends Decorator<O> { Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MapPropertyHandler.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MapPropertyHandler.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MapPropertyHandler.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -52,7 +52,7 @@ * * @author tchemit <chemit@codelutin.com> * @see DynamicPropertyHandler - * @since 2.2.1 + * @since 2.3 */ public class MapPropertyHandler implements DynamicPropertyHandler { Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MultiJXPathDecorator.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MultiJXPathDecorator.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/MultiJXPathDecorator.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -35,7 +35,7 @@ * @param <O> type of data to decorate * @author tchemit <chemit@codelutin.com> * @see Decorator - * @since 2.2.1 + * @since 2.3 */ public class MultiJXPathDecorator<O> extends JXPathDecorator<O> { @@ -83,9 +83,9 @@ expression, separator, separatorReplacement, - DecoratorUtils.<O>createMultiJXPathContext(expression, - separator, - separatorReplacement) + DecoratorUtil.<O>createMultiJXPathContext(expression, + separator, + separatorReplacement) ); } Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/PropertyDecorator.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/PropertyDecorator.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/PropertyDecorator.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -39,13 +39,13 @@ * <p/> * For example : * <pre> - * Decorator<Object> d = DecoratorUtils.newPropertyDecorator(PropertyDecorator.class,"property"); + * Decorator<Object> d = DecoratorUtil.newPropertyDecorator(PropertyDecorator.class,"property"); * </pre> * + * @param <O> type of data to decorate * @author tchemit <chemit@codelutin.com> - * @param <O> type of data to decorate * @see Decorator - * @since 2.2.1 + * @since 2.3 */ public class PropertyDecorator<O> extends Decorator<O> { @@ -86,14 +86,14 @@ protected Method getM() { if (m == null) { - for (PropertyDescriptor propertyDescriptor : PropertyUtils.getPropertyDescriptors(internalClass)) { + for (PropertyDescriptor propertyDescriptor : PropertyUtils.getPropertyDescriptors(getType())) { if (propertyDescriptor.getName().equals(property)) { m = propertyDescriptor.getReadMethod(); break; } } if (m == null) { - throw new IllegalArgumentException("could not find the property " + property + " in " + internalClass); + throw new IllegalArgumentException("could not find the property " + property + " in " + getType()); } } return m; Added: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/package-info.java =================================================================== --- trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/package-info.java (rev 0) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/package-info.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -0,0 +1,72 @@ +/* + * #%L + * Nuiton Utils :: Nuiton Utils + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2004 - 2011 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +/** + * + * This package contains a api to do some decoration over any object. + * + * <h1>Decorator api</h1> + * The {@link org.nuiton.util.decorator.Decorator} has an internal state which + * is the type of object to decorate and a method to do the decoration : + * {@link org.nuiton.util.decorator.Decorator#toString(Object)}. + * <p/> + * There is some default implementations of a decorator using a simple property, + * or more complex one using jxpath mecanisms. + * + * <h1>DecoratorProvider api</h1> + * The {@link org.nuiton.util.decorator.DecoratorProvider} api is there to + * provide some decorators for you, + * + * There is a second one {@link org.nuiton.util.decorator.DecoratorMulti18nProvider} + * which take account of a given locale (so can be used in web context for + * example). + * + * User has to fill method + * {@link org.nuiton.util.decorator.DecoratorProvider}#loadDecorators()} + * or + * {@link org.nuiton.util.decorator.DecoratorMulti18nProvider#loadDecorators(Locale)} + * to specify which decorators are available. + * + * Then it can use the provider using the methods {@code getDecorator(XXX)} + * + * <strong>Note:</strong> Decorator can be contextualized so for a same type of + * object we can provide different way of decorating then. + * + * <h1>DecoratorUtil class</h1> + * + * This class offers some usefull method to create new decorator via the + * {@code newXXX} methods and also some method to sort list of objects using a + * decorator. + * + * <strong>Note: </strong> This api comes from the jaxx-runtime project. + * + * @author tchemit <chemit@codelutin.com> + * @since 2.3 + * @see org.nuiton.util.decorator.Decorator + * @see org.nuiton.util.decorator.DecoratorProvider + * @see org.nuiton.util.decorator.DecoratorMulti18nProvider + */ +package org.nuiton.util.decorator; + +import java.util.Locale; \ No newline at end of file Property changes on: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/package-info.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/Data.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/Data.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/Data.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -29,7 +29,7 @@ /** * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public class Data { Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorMulti18nProviderTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorMulti18nProviderTest.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorMulti18nProviderTest.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -35,7 +35,7 @@ * Tests the {@link DecoratorMulti18nProvider} * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public class DecoratorMulti18nProviderTest { @@ -80,31 +80,31 @@ Decorator<File> fileDecorator = provider.getDecorator(l_fr, f); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("myFile", fileDecorator.toString(f)); Decorator<?> classDecorator; classDecorator = provider.getDecorator(l_fr, Class.class); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("File FR", classDecorator.toString(k)); classDecorator = provider.getDecorator(l_en, Class.class); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("File GB", classDecorator.toString(k)); Decorator<Data> dataDecorator; dataDecorator = provider.getDecorator(l_fr, d); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("name FR", dataDecorator.toString(d)); dataDecorator = provider.getDecorator(l_en, d); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("name GB", dataDecorator.toString(d)); } @@ -117,19 +117,19 @@ Decorator<File> fileDecorator = provider.getDecorator(l_fr, f, BY_NAME); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("null", fileDecorator.toString(f)); Decorator<Class> classDecorator; - classDecorator = provider.getDecorator(l_fr, Class.class, BY_NAME); + classDecorator = provider.getDecoratorByType(l_fr, Class.class, BY_NAME); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("java.io.File FR", classDecorator.toString(k)); - classDecorator = provider.getDecorator(l_en, Class.class, BY_NAME); + classDecorator = provider.getDecoratorByType(l_en, Class.class, BY_NAME); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("java.io.File GB", classDecorator.toString(k)); @@ -143,12 +143,12 @@ dataDecorator = provider.getDecorator(l_fr, d, BY_POS); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("0 FR", dataDecorator.toString(d)); dataDecorator = provider.getDecorator(l_en, d, BY_POS); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("0 GB", dataDecorator.toString(d)); } @@ -159,33 +159,33 @@ Data d = new Data(0, "name"); Class<?> k = File.class; - Decorator<File> fileDecorator = provider.getDecorator(l_fr, File.class); + Decorator<File> fileDecorator = provider.getDecoratorByType(l_fr, File.class); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("myFile", fileDecorator.toString(f)); Decorator<Class> classDecorator; - classDecorator = provider.getDecorator(l_fr, Class.class); + classDecorator = provider.getDecoratorByType(l_fr, Class.class); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("File FR", classDecorator.toString(k)); - classDecorator = provider.getDecorator(l_en, Class.class); + classDecorator = provider.getDecoratorByType(l_en, Class.class); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("File GB", classDecorator.toString(k)); Decorator<Data> dataDecorator; - dataDecorator = provider.getDecorator(l_fr, Data.class); + dataDecorator = provider.getDecoratorByType(l_fr, Data.class); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("name FR", dataDecorator.toString(d)); - dataDecorator = provider.getDecorator(l_en, Data.class); + dataDecorator = provider.getDecoratorByType(l_en, Data.class); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("name GB", dataDecorator.toString(d)); } @@ -195,33 +195,33 @@ Data d = new Data(0, "name"); Class<?> k = File.class; - Decorator<File> fileDecorator = provider.getDecorator(l_fr, File.class, BY_NAME); + Decorator<File> fileDecorator = provider.getDecoratorByType(l_fr, File.class, BY_NAME); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("null", fileDecorator.toString(f)); Decorator<Class> classDecorator; - classDecorator = provider.getDecorator(l_fr, Class.class, BY_NAME); + classDecorator = provider.getDecoratorByType(l_fr, Class.class, BY_NAME); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("java.io.File FR", classDecorator.toString(k)); - classDecorator = provider.getDecorator(l_en, Class.class, BY_NAME); + classDecorator = provider.getDecoratorByType(l_en, Class.class, BY_NAME); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("java.io.File GB", classDecorator.toString(k)); Decorator<Data> dataDecorator; - dataDecorator = provider.getDecorator(l_fr, Data.class, BY_POS); + dataDecorator = provider.getDecoratorByType(l_fr, Data.class, BY_POS); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("0 FR", dataDecorator.toString(d)); - dataDecorator = provider.getDecorator(l_en, Data.class, BY_POS); + dataDecorator = provider.getDecoratorByType(l_en, Data.class, BY_POS); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("0 GB", dataDecorator.toString(d)); } Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorProviderTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorProviderTest.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/DecoratorProviderTest.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -32,7 +32,7 @@ /** * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public class DecoratorProviderTest { @@ -70,17 +70,17 @@ Decorator<File> fileDecorator = provider.getDecorator(f); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("myFile", fileDecorator.toString(f)); Decorator<?> classDecorator = provider.getDecorator(Class.class); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("File", classDecorator.toString(k)); Decorator<Data> dataDecorator = provider.getDecorator(d); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("name", dataDecorator.toString(d)); } @@ -93,18 +93,18 @@ Decorator<File> fileDecorator = provider.getDecorator(f, BY_NAME); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("null", fileDecorator.toString(f)); - Decorator<Class> classDecorator = provider.getDecorator(Class.class, BY_NAME); + Decorator<Class> classDecorator = provider.getDecoratorByType(Class.class, BY_NAME); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("java.io.File", classDecorator.toString(k)); Decorator<Data> dataDecorator = provider.getDecorator(d, BY_NAME); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("0", dataDecorator.toString(d)); } @@ -115,19 +115,19 @@ Data d = new Data(0, "name"); Class<?> k = File.class; - Decorator<File> fileDecorator = provider.getDecorator(File.class); + Decorator<File> fileDecorator = provider.getDecoratorByType(File.class); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("myFile", fileDecorator.toString(f)); - Decorator<Class> classDecorator = provider.getDecorator(Class.class); + Decorator<Class> classDecorator = provider.getDecoratorByType(Class.class); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("File", classDecorator.toString(k)); - Decorator<Data> dataDecorator = provider.getDecorator(Data.class); + Decorator<Data> dataDecorator = provider.getDecoratorByType(Data.class); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("name", dataDecorator.toString(d)); } @@ -137,20 +137,20 @@ Data d = new Data(0, "name"); Class<?> k = File.class; - Decorator<File> fileDecorator = provider.getDecorator(File.class, BY_NAME); + Decorator<File> fileDecorator = provider.getDecoratorByType(File.class, BY_NAME); Assert.assertNotNull(fileDecorator); - Assert.assertEquals(File.class, fileDecorator.getInternalClass()); + Assert.assertEquals(File.class, fileDecorator.getType()); Assert.assertEquals("null", fileDecorator.toString(f)); - Decorator<Class> classDecorator = provider.getDecorator(Class.class, BY_NAME); + Decorator<Class> classDecorator = provider.getDecoratorByType(Class.class, BY_NAME); Assert.assertNotNull(classDecorator); - Assert.assertEquals(Class.class, classDecorator.getInternalClass()); + Assert.assertEquals(Class.class, classDecorator.getType()); Assert.assertEquals("java.io.File", classDecorator.toString(k)); - Decorator<Data> dataDecorator = provider.getDecorator(Data.class, BY_NAME); + Decorator<Data> dataDecorator = provider.getDecoratorByType(Data.class, BY_NAME); Assert.assertNotNull(dataDecorator); - Assert.assertEquals(Data.class, dataDecorator.getInternalClass()); + Assert.assertEquals(Data.class, dataDecorator.getType()); Assert.assertEquals("0", dataDecorator.toString(d)); } Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathContextTester.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathContextTester.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathContextTester.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -32,7 +32,7 @@ * A simple class to test JXPath context. * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public abstract class JXPathContextTester { Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathDecoratorTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathDecoratorTest.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/JXPathDecoratorTest.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -36,11 +36,10 @@ /** * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public class JXPathDecoratorTest { - protected JXPathDecorator<?> decorator; protected String expected; @@ -54,22 +53,22 @@ @Test(expected = NullPointerException.class) public void testNullInternalClass() throws Exception { - decorator = DecoratorUtils.newJXPathDecorator(null, "hello"); + decorator = DecoratorUtil.newJXPathDecorator(null, "hello"); } @Test(expected = IllegalArgumentException.class) public void testMissingRightBrace() throws Exception { - decorator = DecoratorUtils.newJXPathDecorator(Object.class, "${haha"); + decorator = DecoratorUtil.newJXPathDecorator(Object.class, "${haha"); } @Test(expected = IllegalArgumentException.class) public void testMissingRightBrace2() throws Exception { - decorator = DecoratorUtils.newJXPathDecorator(Object.class, "${haha${hum}"); + decorator = DecoratorUtil.newJXPathDecorator(Object.class, "${haha${hum}"); } @Test public void testNullBean() throws Exception { - decorator = DecoratorUtils.newJXPathDecorator(Object.class, "hello"); + decorator = DecoratorUtil.newJXPathDecorator(Object.class, "hello"); expected = "hello"; assertEquals(expected, decorator.getExpression()); assertEquals(0, decorator.nbToken); @@ -81,7 +80,7 @@ @Test public void testNoJXPath() throws Exception { - decorator = DecoratorUtils.newJXPathDecorator(Object.class, "hello"); + decorator = DecoratorUtil.newJXPathDecorator(Object.class, "hello"); expected = "hello"; assertEquals(expected, decorator.getExpression()); assertEquals(0, decorator.nbToken); @@ -94,19 +93,25 @@ @Test public void testDecorator() throws Exception { - decorator = DecoratorUtils.newJXPathDecorator(JXPathDecorator.class, "${expression}$s - ${nbToken}$d"); + decorator = DecoratorUtil.newJXPathDecorator( + JXPathDecorator.class, "${expression}$s - ${nbToken}$d"); assertEquals("%1$s - %2$d", decorator.getExpression()); assertDecoratorInternal(); - decorator = DecoratorUtils.newJXPathDecorator(JXPathDecorator.class, "${expression}${nbToken}"); + decorator = DecoratorUtil.newJXPathDecorator( + JXPathDecorator.class, "${expression}${nbToken}"); assertEquals("%1%2", decorator.getExpression()); assertDecoratorInternal(); - decorator = DecoratorUtils.newJXPathDecorator(JXPathDecorator.class, "before ${expression}$s - ${nbToken}$d after"); + decorator = DecoratorUtil.newJXPathDecorator( + JXPathDecorator.class, + "before ${expression}$s - ${nbToken}$d after"); assertEquals("before %1$s - %2$d after", decorator.getExpression()); assertDecoratorInternal(); - decorator = DecoratorUtils.newJXPathDecorator(JXPathDecorator.class, "before${expression}$s-${nbToken}$dafter"); + decorator = DecoratorUtil.newJXPathDecorator( + JXPathDecorator.class, + "before${expression}$s-${nbToken}$dafter"); assertEquals("before%1$s-%2$dafter", decorator.getExpression()); assertDecoratorInternal(); } @@ -114,10 +119,10 @@ @Test public void testDecoratorEspcapeCharacters() throws Exception { - decorator = DecoratorUtils.newJXPathDecorator(JXPathDecorator.class, "(${expression}$s) - ${nbToken}$d"); + decorator = DecoratorUtil.newJXPathDecorator( + JXPathDecorator.class, "(${expression}$s) - ${nbToken}$d"); assertEquals("(%1$s) - %2$d", decorator.getExpression()); String s = decorator.toString(decorator); - System.out.println("s=" + s); assertDecoratorInternal(); } @@ -127,10 +132,11 @@ List<Data> datas = Data.generate(10); - JXPathDecorator<Data> d = DecoratorUtils.newJXPathDecorator(Data.class, "${pos}$d ${name}$s"); + JXPathDecorator<Data> d = DecoratorUtil.newJXPathDecorator( + Data.class, "${pos}$d ${name}$s"); List<Data> sortData = new ArrayList<Data>(datas); - DecoratorUtils.sort(d, sortData, 0); + DecoratorUtil.sort(d, sortData, 0); for (int i = 0; i < datas.size(); i++) { Data data = datas.get(i); Data sData = sortData.get(i); @@ -144,7 +150,7 @@ }); JXPathDecorator.Context<Data> context = d.context; context.setComparator(null); - DecoratorUtils.sort(d, sortData, 1); + DecoratorUtil.sort(d, sortData, 1); for (int i = 0; i < datas.size(); i++) { Data data = datas.get(i); Data sData = sortData.get(i); @@ -155,7 +161,9 @@ public void assertDecoratorInternal(String... tokens) { assertTokens(tokens); - expected = String.format(decorator.getExpression(), decorator.getExpression(), decorator.getNbToken()); + expected = String.format(decorator.getExpression(), + decorator.getExpression(), + decorator.getNbToken()); result = decorator.toString(decorator); assertEquals(expected, result); } Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MapPropertyHandlerTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MapPropertyHandlerTest.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MapPropertyHandlerTest.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -39,7 +39,7 @@ * Tests the class {@link MapPropertyHandler}. * * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public class MapPropertyHandlerTest extends JXPathContextTester { Modified: trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MultiJXPathDecoratorTest.java =================================================================== --- trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MultiJXPathDecoratorTest.java 2011-08-04 09:51:37 UTC (rev 2161) +++ trunk/nuiton-utils/src/test/java/org/nuiton/util/decorator/MultiJXPathDecoratorTest.java 2011-08-04 12:48:03 UTC (rev 2162) @@ -36,7 +36,7 @@ /** * @author tchemit <chemit@codelutin.com> - * @since 2.2.1 + * @since 2.3 */ public class MultiJXPathDecoratorTest { @@ -53,22 +53,22 @@ @Test(expected = NullPointerException.class) public void testNullInternalClass() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(null, "hello", "#"); + decorator = DecoratorUtil.newMultiJXPathDecorator(null, "hello", "#"); } @Test(expected = IllegalArgumentException.class) public void testMissingRightBrace() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(Object.class, "${haha", "#"); + decorator = DecoratorUtil.newMultiJXPathDecorator(Object.class, "${haha", "#"); } @Test(expected = IllegalArgumentException.class) public void testMissingRightBrace2() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(Object.class, "${haha${hum}", "#"); + decorator = DecoratorUtil.newMultiJXPathDecorator(Object.class, "${haha${hum}", "#"); } @Test public void testNullBean() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(Object.class, "hello", ""); + decorator = DecoratorUtil.newMultiJXPathDecorator(Object.class, "hello", ""); expected = "hello"; assertEquals(expected, decorator.getExpression()); assertEquals(0, decorator.nbToken); @@ -81,7 +81,7 @@ @Test public void testMultiDecorator() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s#${nbToken}$d", "#", " - "); + decorator = DecoratorUtil.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s#${nbToken}$d", "#", " - "); assertEquals("%1$s - %2$d", decorator.getExpression()); assertDecoratorInternal(); assertEquals(2, decorator.contexts.length); @@ -92,7 +92,7 @@ result = decorator.toString(decorator); assertEquals(expected, result); - decorator = DecoratorUtils.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s ## ${nbToken}$d", " ## ", " - "); + decorator = DecoratorUtil.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s ## ${nbToken}$d", " ## ", " - "); assertEquals("%1$s - %2$d", decorator.getExpression()); assertDecoratorInternal(); assertEquals(2, decorator.contexts.length); @@ -107,7 +107,7 @@ @Test public void testMultiDecorator2() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s#${nbToken}$d#${separator}$s", "#", " - "); + decorator = DecoratorUtil.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s#${nbToken}$d#${separator}$s", "#", " - "); assertEquals("%1$s - %2$d - %3$s", decorator.getExpression()); assertTokens("expression", "nbToken", "separator"); @@ -137,7 +137,7 @@ @Test public void testDecoratorEspcapeCharacters() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(JXPathDecorator.class, "(${expression}$s)#${nbToken}$d", "#", " - "); + decorator = DecoratorUtil.newMultiJXPathDecorator(JXPathDecorator.class, "(${expression}$s)#${nbToken}$d", "#", " - "); assertEquals("(%1$s) - %2$d", decorator.getExpression()); assertTokens("expression", "nbToken"); assertEquals(2, decorator.contexts.length); @@ -146,7 +146,7 @@ System.out.println("s=" + result); assertEquals(expected, result); - decorator = DecoratorUtils.newMultiJXPathDecorator(JXPathDecorator.class, "${nbToken}$d#(${expression}$s)", "#", " - "); + decorator = DecoratorUtil.newMultiJXPathDecorator(JXPathDecorator.class, "${nbToken}$d#(${expression}$s)", "#", " - "); assertEquals("%1$d - (%2$s)", decorator.getExpression()); assertTokens("nbToken", "expression"); assertEquals(2, decorator.contexts.length); @@ -172,7 +172,7 @@ @Test public void testMultiDecoratorWithMultiRef() throws Exception { - decorator = DecoratorUtils.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s#${nbToken}$d#${separator}$s %3$s", "#", " - "); + decorator = DecoratorUtil.newMultiJXPathDecorator(JXPathDecorator.class, "${expression}$s#${nbToken}$d#${separator}$s %3$s", "#", " - "); assertEquals("%1$s - %2$d - %3$s %3$s", decorator.getExpression()); assertTokens("expression", "nbToken", "separator"); @@ -203,10 +203,10 @@ List<Data> datas = Data.generate(10); - MultiJXPathDecorator<Data> d = DecoratorUtils.newMultiJXPathDecorator(Data.class, "${pos}$d-${name}$s", "-"); + MultiJXPathDecorator<Data> d = DecoratorUtil.newMultiJXPathDecorator(Data.class, "${pos}$d-${name}$s", "-"); List<Data> sortData = new ArrayList<Data>(datas); - DecoratorUtils.sort(d, sortData, 0); + DecoratorUtil.sort(d, sortData, 0); for (int i = 0; i < datas.size(); i++) { Data data = datas.get(i); Data sData = sortData.get(i); @@ -220,7 +220,7 @@ } }); d.setContextIndex(1); - DecoratorUtils.sort(d, sortData, 1); + DecoratorUtil.sort(d, sortData, 1); for (int i = 0; i < datas.size(); i++) { Data data = datas.get(i); Data sData = sortData.get(i);