org.nuiton.util.decorator
Class JXPathDecorator<O>

java.lang.Object
  extended by org.nuiton.util.decorator.Decorator<O>
      extended by org.nuiton.util.decorator.JXPathDecorator<O>
Type Parameters:
O - type of data to decorate
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MultiJXPathDecorator

public class JXPathDecorator<O>
extends Decorator<O>

JXPath decorator based on String.format(String, Object...) method.

To use it, give to him a expression where all jxpath to apply on bean are boxed in ${}.

After the jxpath token you must specifiy the formatter to apply of the jxpath token.

For example :

 Decorator<Object> d = DecoratorUtil.newJXPathDecorator(
 JXPathDecorator.class,"expr = ${expressions}$s");
 assert "expr = %1$s" == d.getExpression();
 assert 1 == d.getNbToken();
 assert java.util.Arrays.asList("expression") == d.getTokens();
 assert "expr = %1$s" == d.toString(d);
 

Since:
2.3
Author:
tchemit
See Also:
Decorator, Serialized Form

Nested Class Summary
static class JXPathDecorator.Context<O>
           
static class JXPathDecorator.JXPathComparator<O>
           
 
Field Summary
protected  JXPathDecorator.Context<O> context
          the computed context of the decorator
protected  String initialExpression
          the initial expression used to compute the decorator context.
protected  int nbToken
          nb jxpath tokens to compute
 
Fields inherited from class org.nuiton.util.decorator.Decorator
type
 
Constructor Summary
protected JXPathDecorator(Class<O> internalClass, String expression, JXPathDecorator.Context<O> context)
           
 
Method Summary
protected static void ensureTokenIndex(JXPathDecorator<?> decorator, int pos)
           
protected  Comparator<O> getComparator(int pos)
           
 String getExpression()
           
 String getInitialExpression()
           
 int getNbToken()
           
 String getProperty(int pos)
           
 String[] getTokens()
           
protected  Comparable<Comparable<?>> getTokenValue(org.apache.commons.jxpath.JXPathContext jxcontext, String token)
           
 void setContext(JXPathDecorator.Context<O> context)
           
 String toString()
           
 String toString(Object bean)
           
 
Methods inherited from class org.nuiton.util.decorator.Decorator
getInternalClass, getType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

context

protected JXPathDecorator.Context<O> context
the computed context of the decorator


nbToken

protected int nbToken
nb jxpath tokens to compute


initialExpression

protected String initialExpression
the initial expression used to compute the decorator context.

Constructor Detail

JXPathDecorator

protected JXPathDecorator(Class<O> internalClass,
                          String expression,
                          JXPathDecorator.Context<O> context)
                   throws IllegalArgumentException,
                          NullPointerException
Throws:
IllegalArgumentException
NullPointerException
Method Detail

toString

public String toString(Object bean)
Specified by:
toString in class Decorator<O>
Parameters:
bean - the bean to decorate
Returns:
the string value of the given bean

getProperty

public String getProperty(int pos)

getExpression

public String getExpression()

getTokens

public String[] getTokens()

getNbToken

public int getNbToken()

getInitialExpression

public String getInitialExpression()

toString

public String toString()
Overrides:
toString in class Object

setContext

public void setContext(JXPathDecorator.Context<O> context)

getComparator

protected Comparator<O> getComparator(int pos)

getTokenValue

protected Comparable<Comparable<?>> getTokenValue(org.apache.commons.jxpath.JXPathContext jxcontext,
                                                  String token)

ensureTokenIndex

protected static void ensureTokenIndex(JXPathDecorator<?> decorator,
                                       int pos)


Copyright © 2004-2012 CodeLutin. All Rights Reserved.