public abstract class AbstractPojoPathNavigator extends AbstractLoggableComponent implements PojoPathNavigator
PojoPathNavigator
.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractPojoPathNavigator.CachingPojoPath
This class represents a
PojoPath . |
protected static class |
AbstractPojoPathNavigator.PojoPathCache
This inner class represents the cache for
AbstractPojoPathNavigator.CachingPojoPath s based on an initial
Pojo . |
protected static class |
AbstractPojoPathNavigator.PojoPathState
This inner class represents the state for a
PojoPath evaluation. |
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
AbstractPojoPathNavigator()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
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)
|
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 . |
<TYPE> TYPE |
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)
|
protected Object |
getFromList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
int index)
|
protected Object |
getFromMap(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Map parentPojo)
|
protected abstract Object |
getFromPojo(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state)
|
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 PojoPathFunction s that are global for
this PojoPathNavigator instance. |
private AbstractPojoPathNavigator.CachingPojoPath |
getPath(Object pojo,
String pojoPath,
PojoPathMode mode,
PojoPathContext context)
This method contains the internal implementation of
get(Object, String, PojoPathMode, PojoPathContext) . |
protected PojoFactory |
getPojoFactory()
|
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
pojoPath 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
pojoPath 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)
|
Map<String,Object> |
pojo2Map(Object pojo,
PojoPathContext context)
|
protected Object |
set(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value)
|
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
PojoPathFunction s. |
protected Object |
setInList(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value,
int index)
|
protected abstract Object |
setInPojo(AbstractPojoPathNavigator.CachingPojoPath currentPath,
PojoPathContext context,
AbstractPojoPathNavigator.PojoPathState state,
Object parentPojo,
Object value)
|
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. |
createLogger, getLogger
doInitialized, getInitializationState, initialize
private static final String PATH_SUFFIX_COLLECTION_LIST
PojoPath
-suffix used to cache a CollectionList
.private ReflectionUtil reflectionUtil
private CollectionReflectionUtil collectionReflectionUtil
private PojoPathFunctionManager functionManager
private ComposedValueConverter valueConverter
private PojoFactory pojoFactory
protected PojoPathFunctionManager getFunctionManager()
PojoPathFunctionManager
for PojoPathFunction
s that are global for
this PojoPathNavigator
instance. PojoPathFunction
s 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
PojoPathFunction
s.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
to use.PojoPathContext.getPojoFactory()
@Inject public void setPojoFactory(PojoFactory pojoFactory)
PojoFactory to use
.pojoFactory
- is the PojoFactory
to use.protected void doInitialize()
AbstractComponent
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)
PojoPathNavigator
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 PojoPathNavigator
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.pojoPath
starting at the given pojo
. It
may be null
according to the given mode
.private AbstractPojoPathNavigator.CachingPojoPath getPath(Object pojo, String pojoPath, PojoPathMode mode, PojoPathContext context)
get(Object, String, PojoPathMode, PojoPathContext)
.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.AbstractPojoPathNavigator.CachingPojoPath
for the given pojoPath
.public <TYPE> TYPE get(Object pojo, String pojoPath, PojoPathMode mode, PojoPathContext context, Class<TYPE> targetClass)
PojoPathNavigator
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 PojoPathNavigator
TYPE
- 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
.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)
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 ObjectNotFoundException
PojoPathFunction
for the given functionName
.functionName
- is the name
of the requested
PojoPathFunction
.context
- is the context
for this operation.PojoPathFunction
.ObjectNotFoundException
- if no PojoPathFunction
is defined for the given functionName
.public GenericType<?> getType(Type pojoType, String pojoPath, boolean failOnUnsafePath, PojoPathContext context) throws PojoPathException, IllegalPojoPathException, PojoPathUnsafeException
PojoPathNavigator
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 PojoPathNavigator
pojoType
- is the type of the initial Pojo
.pojoPath
- is the PojoPath
to navigate.failOnUnsafePath
- determines how to deal with unsafe PojoPath
s. 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)
PojoPathNavigator
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 PojoPathNavigator
pojoType
- is the type of the initial Pojo
.pojoPath
- is the PojoPath
to navigate.failOnUnsafePath
- determines how to deal with unsafe PojoPath
s. 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)
PojoPathNavigator
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 PojoPathNavigator
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.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)
PojoPathNavigator
Map
reflecting the given
Pojo
. Map
will be simple
and will NOT
support size
or iteration
.pojo2Map
in interface PojoPathNavigator
pojo
- is the Pojo
to convert.Map
reflecting the given Pojo
.PojoDescriptorBuilder.pojo2Map(Object)
public Map<String,Object> pojo2Map(Object pojo, PojoPathContext context)
PojoPathNavigator
Map
reflecting the given
Pojo
. Map
will be simple
and will NOT
support size
or iteration
.pojo2Map
in interface PojoPathNavigator
pojo
- is the Pojo
to convert.context
- is the PojoPathContext
for this operation.Map
reflecting the given Pojo
.PojoDescriptorBuilder.pojo2Map(Object)
Copyright © 2001–2016 mmm-Team. All rights reserved.