Author: tchemit Date: 2012-08-20 12:44:03 +0200 (Mon, 20 Aug 2012) New Revision: 2403 Url: http://nuiton.org/repositories/revision/nuiton-utils/2403 Log: fixes #2277: Improve decorator api (make public registerXXX methods) Modified: trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorMulti18nProvider.java trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorProvider.java 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 2012-08-19 11:07:20 UTC (rev 2402) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorMulti18nProvider.java 2012-08-20 10:44:03 UTC (rev 2403) @@ -129,115 +129,58 @@ return d == null ? null : d.getDecorator(); } - public void clear() { - if (decoratorContexts != null) { - decoratorContexts.clear(); - } - } - - protected Map<Locale, Collection<DecoratorContext<?>>> getDecoratorContexts() { - if (decoratorContexts == null) { - decoratorContexts = new HashMap<Locale, Collection<DecoratorContext<?>>>(); - } - return decoratorContexts; - } - - protected Collection<DecoratorContext<?>> getDecoratorContexts(Locale locale, - boolean doLoad) { - - Collection<DecoratorContext<?>> decoratorContexts = - getDecoratorContexts().get(locale); - - if (decoratorContexts == null) { - decoratorContexts = new ArrayList<DecoratorContext<?>>(); - getDecoratorContexts().put(locale, decoratorContexts); - if (doLoad) { - loadDecorators(locale); - } - } - return decoratorContexts; - } - - @SuppressWarnings({"unchecked"}) - protected <T> DecoratorContext<T> getDecoratorContext(Locale locale, - Class<T> type, - String context, - boolean doLoad) { - DecoratorContext<T> result = null; - - Collection<DecoratorContext<?>> decoratorContexts = - getDecoratorContexts(locale, doLoad); - - if (decoratorContexts != null) { - for (DecoratorContext<?> d : decoratorContexts) { - if (type == null) { - if (d.accept(context)) { - result = (DecoratorContext<T>) d; - break; - } - continue; - } - if (d.accept(type, context)) { - result = (DecoratorContext<T>) d; - break; - } - } - } - return result; - } - - protected void registerPropertyDecorator(Locale locale, - Class<?> klass, - String expression) { + public void registerPropertyDecorator(Locale locale, + Class<?> klass, + String expression) { registerPropertyDecorator(locale, klass, null, expression); } - protected void registerJXPathDecorator(Locale locale, - Class<?> klass, String expression) { + public void registerJXPathDecorator(Locale locale, + Class<?> klass, String expression) { registerJXPathDecorator(locale, klass, null, expression); } - protected void registerMultiJXPathDecorator(Locale locale, - Class<?> klass, - String expression, - String separator, - String separatorReplacement) { + public void registerMultiJXPathDecorator(Locale locale, + Class<?> klass, + String expression, + String separator, + String separatorReplacement) { registerMultiJXPathDecorator(locale, klass, null, expression, separator, separatorReplacement); } - protected void registerPropertyDecorator(Locale locale, - Class<?> klass, - String name, - String expression) { + public void registerPropertyDecorator(Locale locale, + Class<?> klass, + String name, + String expression) { Decorator<?> decorator = DecoratorUtil.newPropertyDecorator(klass, expression); registerDecorator(locale, name, decorator); } - protected void registerJXPathDecorator(Locale locale, - Class<?> klass, - String name, - String expression) { + public void registerJXPathDecorator(Locale locale, + Class<?> klass, + String name, + String expression) { Decorator<?> decorator = DecoratorUtil.newJXPathDecorator(klass, expression); registerDecorator(locale, name, decorator); } - protected void registerMultiJXPathDecorator(Locale locale, - Class<?> klass, - String name, - String expression, - String separator, - String separatorReplacement) { + public void registerMultiJXPathDecorator(Locale locale, + Class<?> klass, + String name, + String expression, + String separator, + String separatorReplacement) { Decorator<?> decorator = DecoratorUtil.newMultiJXPathDecorator( klass, expression, separator, separatorReplacement ); registerDecorator(locale, name, decorator); } - protected void registerDecorator(Locale locale, - Decorator<?> decorator) { + public void registerDecorator(Locale locale, + Decorator<?> decorator) { registerDecorator(locale, null, decorator); } @@ -249,9 +192,9 @@ * @param context the name decorator * @param decorator the decorator to register */ - protected <T> void registerDecorator(Locale locale, - String context, - Decorator<T> decorator) { + public <T> void registerDecorator(Locale locale, + String context, + Decorator<T> decorator) { // obtain the decorator context DecoratorContext<?> result = @@ -275,6 +218,63 @@ getDecoratorContexts(locale, false).add(decoratorContext); } + public void clear() { + if (decoratorContexts != null) { + decoratorContexts.clear(); + } + } + + protected Map<Locale, Collection<DecoratorContext<?>>> getDecoratorContexts() { + if (decoratorContexts == null) { + decoratorContexts = new HashMap<Locale, Collection<DecoratorContext<?>>>(); + } + return decoratorContexts; + } + + protected Collection<DecoratorContext<?>> getDecoratorContexts(Locale locale, + boolean doLoad) { + + Collection<DecoratorContext<?>> decoratorContexts = + getDecoratorContexts().get(locale); + + if (decoratorContexts == null) { + decoratorContexts = new ArrayList<DecoratorContext<?>>(); + getDecoratorContexts().put(locale, decoratorContexts); + if (doLoad) { + loadDecorators(locale); + } + } + return decoratorContexts; + } + + @SuppressWarnings({"unchecked"}) + protected <T> DecoratorContext<T> getDecoratorContext(Locale locale, + Class<T> type, + String context, + boolean doLoad) { + DecoratorContext<T> result = null; + + Collection<DecoratorContext<?>> decoratorContexts = + getDecoratorContexts(locale, doLoad); + + if (decoratorContexts != null) { + for (DecoratorContext<?> d : decoratorContexts) { + if (type == null) { + if (d.accept(context)) { + result = (DecoratorContext<T>) d; + break; + } + continue; + } + if (d.accept(type, context)) { + result = (DecoratorContext<T>) d; + break; + } + } + } + return result; + } + public static class DecoratorContext<T> { /** the context name of the 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 2012-08-19 11:07:20 UTC (rev 2402) +++ trunk/nuiton-utils/src/main/java/org/nuiton/util/decorator/DecoratorProvider.java 2012-08-20 10:44:03 UTC (rev 2403) @@ -113,22 +113,16 @@ loadDecorators(); } - public void clear() { - if (decorators != null) { - decorators.clear(); - } - } - - protected void registerPropertyDecorator(Class<?> klass, + public void registerPropertyDecorator(Class<?> klass, String expression) { registerPropertyDecorator(klass, null, expression); } - protected void registerJXPathDecorator(Class<?> klass, String expression) { + public void registerJXPathDecorator(Class<?> klass, String expression) { registerJXPathDecorator(klass, null, expression); } - protected void registerMultiJXPathDecorator(Class<?> klass, + public void registerMultiJXPathDecorator(Class<?> klass, String expression, String separator, String separatorReplacement) { @@ -136,7 +130,7 @@ separatorReplacement); } - protected void registerPropertyDecorator(Class<?> klass, + public void registerPropertyDecorator(Class<?> klass, String name, String expression) { Decorator<?> decorator = @@ -144,7 +138,7 @@ registerDecorator(name, decorator); } - protected void registerJXPathDecorator(Class<?> klass, + public void registerJXPathDecorator(Class<?> klass, String name, String expression) { Decorator<?> decorator = @@ -152,7 +146,7 @@ registerDecorator(name, decorator); } - protected void registerMultiJXPathDecorator(Class<?> klass, + public void registerMultiJXPathDecorator(Class<?> klass, String name, String expression, String separator, @@ -163,7 +157,7 @@ registerDecorator(name, decorator); } - protected void registerDecorator(Decorator<?> decorator) { + public void registerDecorator(Decorator<?> decorator) { registerDecorator(null, decorator); } @@ -174,7 +168,7 @@ * @param context the name decorator * @param decorator the decorator to register */ - protected <T> void registerDecorator(String context, + public <T> void registerDecorator(String context, Decorator<T> decorator) { // obtain the decorator context @@ -195,6 +189,12 @@ getDecorators().add(decoratorContext); } + public void clear() { + if (decorators != null) { + decorators.clear(); + } + } + protected List<DecoratorContext<?>> getDecorators() { if (decorators == null) { decorators = new ArrayList<DecoratorContext<?>>();
participants (1)
-
tchemit@users.nuiton.org