branch develop updated (2e59483 -> 972f3b6)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository nuiton-decorator. See http://git.nuiton.org/nuiton-decorator.git from 2e59483 fixes #3543: Migrates to git (fix git url) new 172793f fixes #3586: Be able to create a new decorator from another one new 972f3b6 update nuitonpom version The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 972f3b6e5d9abbd97a1f6354a2dcc47c3208b8ce Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Nov 30 10:13:26 2014 +0100 update nuitonpom version commit 172793f2cb0bf4e35f434e9b09c317ac1bc2765e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Nov 30 10:12:39 2014 +0100 fixes #3586: Be able to create a new decorator from another one Summary of changes: pom.xml | 2 +- .../java/org/nuiton/decorator/DecoratorUtil.java | 73 +++++++++++++++++++--- 2 files changed, 64 insertions(+), 11 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-decorator. See http://git.nuiton.org/nuiton-decorator.git commit 172793f2cb0bf4e35f434e9b09c317ac1bc2765e Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Nov 30 10:12:39 2014 +0100 fixes #3586: Be able to create a new decorator from another one --- .../java/org/nuiton/decorator/DecoratorUtil.java | 73 +++++++++++++++++++--- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/nuiton/decorator/DecoratorUtil.java b/src/main/java/org/nuiton/decorator/DecoratorUtil.java index 5a3b19c..f0a06a2 100644 --- a/src/main/java/org/nuiton/decorator/DecoratorUtil.java +++ b/src/main/java/org/nuiton/decorator/DecoratorUtil.java @@ -21,6 +21,7 @@ */ package org.nuiton.decorator; +import org.apache.commons.beanutils.MethodUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.JXPathDecorator.Context; @@ -29,6 +30,7 @@ import org.nuiton.decorator.JXPathDecorator.JXPathComparator; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.List; import java.util.StringTokenizer; import java.util.regex.Matcher; @@ -131,14 +133,14 @@ public class DecoratorUtil { * When setting conext index to 1, then we will us this expression: * <pre>B - C - A</pre> * - * @param type type of bean - * @param expression initial expression - * @param separator expression context separator + * @param type type of bean + * @param expression initial expression + * @param separator expression context separator * @param separatorReplacement context separator replacement in decorator - * @param <O> type of bean + * @param <O> type of bean * @return the new decorator * @throws IllegalArgumentException ... - * @throws NullPointerException ... + * @throws NullPointerException ... * @since 3.0 */ public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator( @@ -170,14 +172,14 @@ public class DecoratorUtil { * When setting conext index to 1, then we will us this expression: * <pre>B - A - C</pre> * - * @param type type of bean - * @param expression initial expression - * @param separator expression context separator + * @param type type of bean + * @param expression initial expression + * @param separator expression context separator * @param separatorReplacement context separator replacement in decorator - * @param <O> type of bean + * @param <O> type of bean * @return the new decorator * @throws IllegalArgumentException ... - * @throws NullPointerException ... + * @throws NullPointerException ... * @since 3.0 */ public static <O> MultiJXPathDecorator<O> newMultiJXPathDecoratorKeepingOrder( @@ -200,6 +202,57 @@ public class DecoratorUtil { contexts); } + private static final Object[] EMPTY_CLASS_ARRAY = new Object[0]; + + /** + * Creates a new multijxpath decorator from a given jxpath decorator. + * + * If decorator is clonable, just clone it, otherwise creates a new using his definition. + * + * @param decorator the decorator to clone + * @param <O> generic type of decorator to clone + * @return cloned decorator + * @since 3.0 + */ + public static <O> MultiJXPathDecorator<O> cloneDecorator(JXPathDecorator<O> decorator) { + if (decorator == null) { + throw new NullPointerException( + "can not have a null decorator as parameter"); + } + String separator; + String separatorReplacement; + + if (decorator instanceof Cloneable) { + Cloneable cloneable = (Cloneable) decorator; + + try { + Object clone = MethodUtils.invokeExactMethod(cloneable, + "clone", + EMPTY_CLASS_ARRAY); + return (MultiJXPathDecorator<O>) clone; + } catch (Exception e) { + throw new IllegalStateException("Could not clone decorator " + decorator, e); + } + + } + if (decorator instanceof MultiJXPathDecorator<?>) { + + separator = ((MultiJXPathDecorator<?>) decorator).getSeparator(); + separatorReplacement = ((MultiJXPathDecorator<?>) decorator).getSeparatorReplacement(); + + } else { + + separator = "??" + new Date().getTime(); // trick to avoid collisions + separatorReplacement = " - "; + } + + return newMultiJXPathDecorator(decorator.getType(), + decorator.getInitialExpression(), + separator, + separatorReplacement); + + } + /** * Sort a list of data based on the first token property of a given context * in a given decorator. -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository nuiton-decorator. See http://git.nuiton.org/nuiton-decorator.git commit 972f3b6e5d9abbd97a1f6354a2dcc47c3208b8ce Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Nov 30 10:13:26 2014 +0100 update nuitonpom version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 67a2f84..51e6693 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ <parent> <groupId>org.nuiton</groupId> <artifactId>nuitonpom</artifactId> - <version>1.5</version> + <version>1.6</version> </parent> <artifactId>nuiton-decorator</artifactId> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm