|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.mmm.util.component.base.AbstractComponent
net.sf.mmm.util.component.base.AbstractLoggableComponent
net.sf.mmm.util.pojo.path.base.AbstractPojoPathNavigator
public abstract class AbstractPojoPathNavigator
This is the abstract base implementation of the PojoPathNavigator.
| Nested Class Summary | |
|---|---|
protected static class |
AbstractPojoPathNavigator.CachingPojoPath
This class represents a PojoPath. |
protected static class |
AbstractPojoPathNavigator.PojoPathCache
This inner class represents the cache for AbstractPojoPathNavigator.CachingPojoPaths based on
an initial Pojo. |
protected static class |
AbstractPojoPathNavigator.PojoPathState
This inner class represents the state for a PojoPath evaluation. |
| Field Summary | |
|---|---|
private CollectionReflectionUtil |
collectionReflectionUtil
|
private PojoPathFunctionManager |
functionManager
|
private static String |
PATH_SUFFIX_COLLECTION_LIST
The reserved PojoPath-suffix used to
cache a CollectionList. |
private PojoFactory |
pojoFactory
|
private ReflectionUtil |
reflectionUtil
|
private ComposedValueConverter |
valueConverter
|
| Constructor Summary | |
|---|---|
AbstractPojoPathNavigator()
The constructor. |
|
| Method Summary | ||
|---|---|---|
protected Object |
convert(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
Object pojo,
Class<?> targetClass,
GenericType<?> targetType)
This method converts the given pojo to the given
targetClass (or even targetType) as necessary. |
|
protected Object |
convertList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object arrayOrCollection)
This method converts the given arrayOrCollection to a
List as necessary. |
|
protected Object |
create(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Class<?> pojoClass)
This method creates a Pojo of the given
pojoType. |
|
protected AbstractPojoPathNavigator.PojoPathState |
createState(Object initialPojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context)
This method gets the AbstractPojoPathNavigator.PojoPathState for the given
context. |
|
protected AbstractPojoPathNavigator.PojoPathState |
createStateByType(GenericType initialPojoType,
String pojoPath,
PojoPathMode mode,
PojoPathContext context)
This method gets the AbstractPojoPathNavigator.PojoPathState for the given
context. |
|
protected void |
doInitialize()
This method performs the actual initialization. |
|
protected Object |
get(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state)
This method gets the value for the single segment of the given
currentPath from the pojo of
its parent. |
|
Object |
get(Object pojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context)
This method evaluates the given pojoPath for the given
pojo using the given mode and
context. |
|
|
get(Object pojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context,
Class<TYPE> targetClass)
This method evaluates the given pojoPath for the given
pojo using the given mode and
context. |
|
CollectionReflectionUtil |
getCollectionReflectionUtil()
This method gets the CollectionReflectionUtil instance to use. |
|
protected Object |
getFromFunction(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
PojoPathFunction function)
This method gets the single segment of the given
currentPath from the Pojo
given by parentPojo. |
|
protected Object |
getFromList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
int index)
This method gets the
single segment of the given
currentPath from the array or List given by
parentPojo. |
|
protected Object |
getFromMap(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Map parentPojo)
This method gets the single
segment of the given
currentPath from the Map given by
parentPojo. |
|
protected abstract Object |
getFromPojo(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state)
This method reflectively gets the single segment of the given
currentPath from the Pojo
given by parentPojo. |
|
protected PojoPathFunction |
getFunction(String functionName,
PojoPathContext context)
This method gets the PojoPathFunction for the given
functionName. |
|
protected PojoPathFunctionManager |
getFunctionManager()
This method gets the optional PojoPathFunctionManager for
PojoPathFunctions that are global for this
PojoPathNavigator instance. |
|
protected PojoFactory |
getPojoFactory()
This method gets the PojoFactory instance used to
create new
Pojos. |
|
protected AbstractPojoPathNavigator.CachingPojoPath |
getRecursive(String pojoPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state)
This method recursively navigates the given pojoPath. |
|
ReflectionUtil |
getReflectionUtil()
This method gets the ReflectionUtil instance to use. |
|
GenericType<?> |
getType(GenericType<?> pojoType,
String pojoPath,
boolean failOnUnsafePath,
PojoPathContext context)
This method determines the result-type for the given starting at the given
pojoType using the given context. |
|
GenericType<?> |
getType(Type pojoType,
String pojoPath,
boolean failOnUnsafePath,
PojoPathContext context)
This method determines the result-type for the given starting at the given
pojoType using the given context. |
|
protected ComposedValueConverter |
getValueConverter()
This method gets the ComposedValueConverter used by default to
convert values that are NOT compatible. |
|
Map<String,Object> |
pojo2Map(Object pojo)
This method creates a lazy, immutable Map reflecting the given
Pojo. |
|
Map<String,Object> |
pojo2Map(Object pojo,
PojoPathContext context)
This method creates a lazy, immutable Map reflecting the given
Pojo. |
|
protected Object |
set(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value)
This method sets the single segment of
the given currentPath from the
Pojo given by parentPojo. |
|
Object |
set(Object pojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context,
Object value)
This method sets the given value for the given
pojoPath in the given pojo using the given
mode and context. |
|
void |
setCollectionReflectionUtil(CollectionReflectionUtil collectionUtil)
|
|
void |
setFunctionManager(PojoPathFunctionManager functionManager)
This method sets the function-manager used
for global PojoPathFunctions. |
|
protected Object |
setInList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value,
int index)
This method sets
the single segment of the given
currentPath from the array or List given by
parentPojo. |
|
protected abstract Object |
setInPojo(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value)
This method sets the single segment of
the given currentPath from the
Pojo given by parentPojo. |
|
void |
setPojoFactory(PojoFactory pojoFactory)
This method sets the PojoFactory to use. |
|
void |
setReflectionUtil(ReflectionUtil reflectionUtil)
|
|
void |
setValueConverter(ComposedValueConverter valueConverter)
This method sets the value-converter used by
default. |
|
| Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent |
|---|
getLogger, setLogger |
| Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent |
|---|
doInitialized, getInitializationState, initialize |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final String PATH_SUFFIX_COLLECTION_LIST
PojoPath-suffix used to
cache a CollectionList.
private ReflectionUtil reflectionUtil
getReflectionUtil()private CollectionReflectionUtil collectionReflectionUtil
getCollectionReflectionUtil()private PojoPathFunctionManager functionManager
getFunctionManager()private ComposedValueConverter valueConverter
getValueConverter()private PojoFactory pojoFactory
getPojoFactory()| Constructor Detail |
|---|
public AbstractPojoPathNavigator()
| Method Detail |
|---|
protected PojoPathFunctionManager getFunctionManager()
PojoPathFunctionManager for
PojoPathFunctions that are global for this
PojoPathNavigator instance.PojoPathFunctions provided by this
PojoPathFunctionManager need to be stateless / thread-safe.
PojoPathFunctionManager or null if NOT
available.@Inject public void setFunctionManager(PojoPathFunctionManager functionManager)
function-manager used
for global PojoPathFunctions.
functionManager - is the PojoPathFunctionManager.protected ComposedValueConverter getValueConverter()
ComposedValueConverter used by default to
convert values that are NOT compatible.
PojoPathContext.getAdditionalConverter()@Inject public void setValueConverter(ComposedValueConverter valueConverter)
value-converter used by
default.
valueConverter - is the ComposedValueConverter to set.public CollectionReflectionUtil getCollectionReflectionUtil()
CollectionReflectionUtil instance to use.
CollectionReflectionUtil to use.@Inject public void setCollectionReflectionUtil(CollectionReflectionUtil collectionUtil)
collectionUtil - is the collectionUtil to setpublic ReflectionUtil getReflectionUtil()
ReflectionUtil instance to use.
ReflectionUtil to use.@Inject public void setReflectionUtil(ReflectionUtil reflectionUtil)
reflectionUtil - is the reflectionUtil to setprotected PojoFactory getPojoFactory()
PojoFactory instance used to
create new
Pojos.
PojoFactory to use.PojoPathContext.getPojoFactory()@Inject public void setPojoFactory(PojoFactory pojoFactory)
PojoFactory to use.
pojoFactory - is the PojoFactory to use.protected void doInitialize()
initialization. It is
called when AbstractComponent.initialize() is invoked for the first time.super.AbstractComponent.doInitialize().
doInitialize in class AbstractLoggableComponent
protected AbstractPojoPathNavigator.PojoPathState createState(Object initialPojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context)
AbstractPojoPathNavigator.PojoPathState for the given
context.
initialPojo - is the initial Pojo
this PojoPathNavigator was invoked with.pojoPath - is the PojoPath to
navigate.mode - is the mode that determines how to deal
null values.context - is the context for this operation.
AbstractPojoPathNavigator.PojoPathState or null if caching is
disabled.
protected AbstractPojoPathNavigator.PojoPathState createStateByType(GenericType initialPojoType,
String pojoPath,
PojoPathMode mode,
PojoPathContext context)
AbstractPojoPathNavigator.PojoPathState for the given
context.
initialPojoType - is the initial pojo-type this
PojoPathNavigator was invoked with.pojoPath - is the PojoPath to
navigate.mode - is the mode that determines how to deal
with unsafe PojoPath
s.context - is the context for this operation.
AbstractPojoPathNavigator.PojoPathState or null if caching is
disabled.
public Object get(Object pojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context)
pojoPath for the given
pojo using the given mode and
context. It returns the result of the evaluation.caching for repetitive calls
on the same initial pojo, you might get wrong results if
intermediate objects have changed
outside
this navigator in the meantime.
get in interface PojoPathNavigatorpojo - is the initial Pojo to operate
on.pojoPath - is the PojoPath to navigate.mode - is the mode that determines how to deal
with null values.context - is the PojoPathContext for this operation.
pojoPath
starting at the given pojo. It may be
null according to the given mode.
public <TYPE> TYPE get(Object pojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context,
Class<TYPE> targetClass)
pojoPath for the given
pojo using the given mode and
context. It returns the result of the evaluation.caching for repetitive calls
on the same initial pojo, you might get wrong results if
intermediate objects have changed
outside
this navigator in the meantime.
get in interface PojoPathNavigatorTYPE - is the generic type of the result.pojo - is the initial Pojo to operate
on.pojoPath - is the PojoPath to navigate.mode - is the mode that determines how to deal
with null values.context - is the PojoPathContext for this operation.targetClass - is the required result-type.
pojoPath
starting at the given pojo. It may be
null according to the given mode.
protected AbstractPojoPathNavigator.CachingPojoPath getRecursive(String pojoPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state)
pojoPath.
pojoPath - is the current
PojoPath to navigate.context - is the context for this operation.state - is the
state of this operation.
pojoPath
starting at the given pojo. It may be
null according to the given mode.
protected Object get(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state)
segment of the given
currentPath from the pojo of
its parent.state indicates an
invocation from
getType,
only the pojo-type should
be determined. Otherwise if the result is null and
mode is
PojoPathMode.CREATE_IF_NULL it creates and attaches (sets) the
missing object.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to evaluate.context - is the context for this operation.state - is the
cache to use or null to disable caching.
pojoPath
starting at the given pojo. It may be
null according to the given mode.
protected Object getFromFunction(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
PojoPathFunction function)
gets the single segment of the given
currentPath from the Pojo
given by parentPojo. If the result is null and
mode is
PojoPathMode.CREATE_IF_NULL it
creates
the missing object.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to evaluate.context - is the context for this operation.state - is the
state of this operation.function - is the PojoPathFunction for evaluation.
null
according to the mode.
protected Object getFromMap(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Map parentPojo)
gets the single
segment of the given
currentPath from the Map given by
parentPojo. If the result is null and
mode is
PojoPathMode.CREATE_IF_NULL it creates and
attaches the missing object.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to evaluate.context - is the context for this operation.state - is the
state of this operation.parentPojo - is the parent object to work on.
null
according to the mode.
protected Object getFromList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
int index)
gets the
single segment of the given
currentPath from the array or List given by
parentPojo. If the result is null and
mode is
PojoPathMode.CREATE_IF_NULL it creates and
sets the missing
object. For arrays a new array has to be created and set in the parent of
the parentPojo.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to evaluate.context - is the context for this operation.state - is the
state of this operation.index - is the List-index.
null
according to the mode.
protected Object create(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Class<?> pojoClass)
throws PojoPathCreationException
Pojo of the given
pojoType.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to evaluate.context - is the context for this operation.state - is the
state of this operation.pojoClass - is the Class reflecting the
Pojo to create.
Pojo.
PojoPathCreationException - if the creation failed.
protected abstract Object getFromPojo(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state)
segment of the given
currentPath from the Pojo
given by parentPojo. If the result is null and
mode is PojoPathMode.CREATE_IF_NULL it creates and
attaches (sets) the missing object.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to evaluate.context - is the context for this operation.state - is the
state of this operation.
null
according to the mode.
protected PojoPathFunction getFunction(String functionName,
PojoPathContext context)
throws PojoPathFunctionUndefinedException
PojoPathFunction for the given
functionName.
functionName - is the
name of the
requested PojoPathFunction.context - is the context for this operation.
PojoPathFunction.
PojoPathFunctionUndefinedException - if no PojoPathFunction
is defined for the given functionName.
public GenericType<?> getType(Type pojoType,
String pojoPath,
boolean failOnUnsafePath,
PojoPathContext context)
throws PojoPathException,
IllegalPojoPathException,
PojoPathUnsafeException
pojoPath starting at the given
pojoType using the given context.get is invoked
on this navigator with an instance of pojoType the result will
be an instance of the type returned by this method.pojoPath may be unsafe
, what means that it has a segment that
points to a property that does NOT exist for the Class determined
for the according Pojo. In other words a
PojoPath is unsafe if it can NOT be written as native Java method
cascade without using casts in order to be compiled. It may be illegal
depending on the initial Pojo.
getType in interface PojoPathNavigatorpojoType - is the type of the initial
Pojo.pojoPath - is the PojoPath to navigate.failOnUnsafePath - determines how to deal with unsafe
PojoPaths. If true and the given
pojoPath is unsafe for the given pojoType
an PojoPathUnsafeException is thrown and if
false this method returns null in such
case.context - is the PojoPathContext for this operation.
pojoPath starting at the given pojoType.
It may be Object.class e.g. in case an untyped
Collection is hit. It will be null
if the given pojoPath is unsafe and the given
mode is PojoPathMode.RETURN_IF_NULL.
IllegalPojoPathException - if the given pojoPath is
illegal.
PojoPathUnsafeException - if the given pojoPath is
unsafe for the given pojoType and this is disallowed
by mode.
PojoPathException - if the operation failed for arbitrary reasons.
public GenericType<?> getType(GenericType<?> pojoType,
String pojoPath,
boolean failOnUnsafePath,
PojoPathContext context)
pojoPath starting at the given
pojoType using the given context.get is invoked
on this navigator with an instance of pojoType the result will
be an instance of the type returned by this method.pojoPath may be unsafe
, what means that it has a segment that
points to a property that does NOT exist for the Class determined
for the according Pojo. In other words a
PojoPath is unsafe if it can NOT be written as native Java method
cascade without using casts in order to be compiled. It may be illegal
depending on the initial Pojo.
getType in interface PojoPathNavigatorpojoType - is the type of the initial
Pojo.pojoPath - is the PojoPath to navigate.failOnUnsafePath - determines how to deal with unsafe
PojoPaths. If true and the given
pojoPath is unsafe for the given pojoType
an PojoPathUnsafeException is thrown and if
false this method returns null in such
case.context - is the PojoPathContext for this operation.
pojoPath starting at the given pojoType.
It may be Object.class e.g. in case an untyped
Collection is hit. It will be null
if the given pojoPath is unsafe and the given
mode is PojoPathMode.RETURN_IF_NULL.
public Object set(Object pojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context,
Object value)
value for the given
pojoPath in the given pojo using the given
mode and context. It acts like a
get on the
parent-path and then setting the
value for the remaining segment
on the result.segment points to a
PojoPathFunction the result of its
set
-method is returned.segment points to an index,parent-path is a List, Map or array,
this will be the old
value of the
given pojoPath that has been replaced by value.pojo is This will typically be the value that replaced
value. It may be null.
set in interface PojoPathNavigatorpojo - is the initial Pojo to operate
on.pojoPath - is the PojoPath to navigate.mode - is the mode that determines how to deal
with null values.context - is the PojoPathContext for this operation.value - is the value to set. It may be null.
set operation.
protected Object set(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value)
segment of
the given currentPath from the
Pojo given by parentPojo. If
the result is null and mode is
PojoPathMode.CREATE_IF_NULL it creates and attaches (sets) the
missing object.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to set.context - is the context for this operation.state - is the
cache to use or null to disable caching.parentPojo - is the parent Pojo to
work on.value - is the value to set in parentPojo.
null.
protected abstract Object setInPojo(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value)
segment of
the given currentPath from the
Pojo given by parentPojo. If
the result is null and mode is
PojoPathMode.CREATE_IF_NULL it creates and attaches (sets) the
missing object.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to set.context - is the context for this operation.state - is the
state to use.parentPojo - is the parent Pojo to
work on.value - is the value to set in parentPojo.
null.
protected Object convert(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
Object pojo,
Class<?> targetClass,
GenericType<?> targetType)
throws PojoPathConversionException
pojo to the given
targetClass (or even targetType) as necessary.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath that lead to
pojo.context - is the context for this operation.pojo - is the Pojo to convert as
necessary.targetClass - is the expected Class.targetType - is the expected Type.
pojo converted to the targetType as
necessary.
PojoPathConversionException - if the given pojo is NOT
compatible and could NOT be converted.
protected Object convertList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object arrayOrCollection)
arrayOrCollection to a
List as necessary.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath that lead to
arrayOrCollection.context - is the context for this operation.state - is the
state to use.arrayOrCollection - is the object to be accessed at a given index.
List that adapts arrayOrCollection if it is
a Collection but NOT a List. Otherwise the given
arrayOrCollection itself.
protected Object setInList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value,
int index)
sets
the single segment of the given
currentPath from the array or List given by
parentPojo. If the result is null and
mode is PojoPathMode.CREATE_IF_NULL it creates and
attaches (sets) the missing object.
currentPath - is the current AbstractPojoPathNavigator.CachingPojoPath to set.context - is the context for this operation.state - is the
state to use.parentPojo - is the parent Pojo to
work on.value - is the value to set in parentPojo.index - is the position of the value to set in the array
or List given by parentPojo.
null.public Map<String,Object> pojo2Map(Object pojo)
Map reflecting the given
Pojo.Map will be
simple and will
NOT support size or iteration.
pojo2Map in interface PojoPathNavigatorpojo - is the Pojo to convert.
Map reflecting the given
Pojo.PojoDescriptorBuilder.pojo2Map(Object)
public Map<String,Object> pojo2Map(Object pojo,
PojoPathContext context)
Map reflecting the given
Pojo.Map will be
simple and will
NOT support size or iteration.
pojo2Map in interface PojoPathNavigatorpojo - is the Pojo to convert.context - is the PojoPathContext for this operation.
Map reflecting the given
Pojo.PojoDescriptorBuilder.pojo2Map(Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||