org.nuiton.util.decorator
Class MapPropertyHandler

java.lang.Object
  extended by org.nuiton.util.decorator.MapPropertyHandler
All Implemented Interfaces:
org.apache.commons.jxpath.DynamicPropertyHandler

public class MapPropertyHandler
extends Object
implements org.apache.commons.jxpath.DynamicPropertyHandler

A extended handler to deal with map in JXPath contexts.

The basic one in JXPath api only deals with map keys as string.

We offers a hook in method getKey(Object) to obtain a string representation of a real object in map (key or value).

More over, you can also access directly to a key or a value, using this syntax :

context.getValue(".[@name='key:programme2']")
context.getValue(".[@name='value:programme2']")

If the values are iterable, then will scan inot it when looking for a direct value.

Since:
2.3
Author:
tchemit
See Also:
DynamicPropertyHandler

Constructor Summary
MapPropertyHandler()
           
 
Method Summary
protected  String getKey(Object o)
          Obtain a string representation of an object.
 Object getProperty(Object object, String propertyName)
           
 Object getPropertyKey(Map<?,?> map, String key)
          Obtain the key from the map keys which matches the given key.
 String[] getPropertyNames(Object object)
           
 Object getPropertyValue(Map<?,?> map, String value)
          Obtain the value from the map values which matches the given value.
 void setProperty(Object object, String propertyName, Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapPropertyHandler

public MapPropertyHandler()
Method Detail

getPropertyNames

public String[] getPropertyNames(Object object)
Specified by:
getPropertyNames in interface org.apache.commons.jxpath.DynamicPropertyHandler

getProperty

public Object getProperty(Object object,
                          String propertyName)
Specified by:
getProperty in interface org.apache.commons.jxpath.DynamicPropertyHandler

setProperty

public void setProperty(Object object,
                        String propertyName,
                        Object value)
Specified by:
setProperty in interface org.apache.commons.jxpath.DynamicPropertyHandler

getPropertyKey

public Object getPropertyKey(Map<?,?> map,
                             String key)
Obtain the key from the map keys which matches the given key.

To compare object ot string, please refers to the method getKey(Object).

Parameters:
map - the map to scan
key - the string representation of the required key as object
Returns:
the found key, or null if not found.

getPropertyValue

public Object getPropertyValue(Map<?,?> map,
                               String value)
Obtain the value from the map values which matches the given value.

To compare object to string, please refer to the method getKey(Object).

Parameters:
map - the map to scan
value - the string representation of the value
Returns:
the found value, or null if not found.}

getKey

protected String getKey(Object o)
Obtain a string representation of an object.

Parameters:
o - the object to decorate
Returns:
the string representation of the object


Copyright © 2004-2012 CodeLutin. All Rights Reserved.