Class Traverser
- java.lang.Object
-
- jadex.commons.transformation.traverser.Traverser
-
public class Traverser extends java.lang.Object
The traverser allows to traverse an object graph deeply. Traversal processors can be used to perform specific actions on traversed object, e.g. object modifications. Does currently not allow transforming objects to other objects of another type (replacements), because objects have to be saved in the graph itself (no extra table for exchanged objects). The traverser can be used as a cloner when processors always return copies of the original objects. todo: introduce classloaders to allows for creating objects with other classloaders (e.g. convert a parameter from a sender to a receiver resource id).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Traverser.MODE
Available modes: PREPROCESS - Preprocess objects using the conversion processors POSTPROCESS - Postprocess objects using the conversion processors PLAIN - Ignore conversion processors
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Object
IGNORE_RESULT
protected static Traverser
instance
The default cloner.protected java.util.Map<java.lang.Class<?>,ITraverseProcessor>
processorcache
protected static java.util.List<ITraverseProcessor>
processors
The default traversal processors with no special actions.
-
Constructor Summary
Constructors Constructor Description Traverser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.Object
convertBasicType(IStringConverter converter, java.lang.Object value, java.lang.Class<?> targetclazz, java.lang.ClassLoader cl, java.lang.Object context)
Convert a basic type.java.lang.Object
doTraverse(java.lang.Object object, java.lang.reflect.Type type, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.void
finalizeProcessing(java.lang.Object inputobject, java.lang.Object outputobject, ITraverseProcessor convproc, ITraverseProcessor proc, java.lang.Object context)
Handle objects after all processing steps have been done before object is returned.java.lang.Class<?>
findClazz(java.lang.Object object, java.lang.ClassLoader cl)
Find the class of an object.static java.util.List<ITraverseProcessor>
getDefaultProcessors()
Get the default traversal processors.static Traverser
getInstance()
Get the default cloner instance.java.lang.Object
preemptProcessing(java.lang.Object inputobject, java.lang.reflect.Type inputtype, java.lang.Object context)
Allows preemption of processing, if the return value is not null, the returned object is used and processing is skipped.java.lang.Object
traverse(java.lang.Object object, java.lang.reflect.Type clazz, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.static java.lang.Object
traverseObject(java.lang.Object object, java.lang.Class<?> clazz, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.static java.lang.Object
traverseObject(java.lang.Object object, java.lang.Class<?> clazz, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, Traverser.MODE mode, java.lang.Object context)
Traverse an object.static java.lang.Object
traverseObject(java.lang.Object object, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.static java.lang.Object
traverseObject(java.lang.Object object, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, Traverser.MODE mode, java.lang.Object context)
Traverse an object.
-
-
-
Field Detail
-
IGNORE_RESULT
public static final java.lang.Object IGNORE_RESULT
-
instance
protected static volatile Traverser instance
The default cloner.
-
processors
protected static final java.util.List<ITraverseProcessor> processors
The default traversal processors with no special actions.
-
processorcache
protected java.util.Map<java.lang.Class<?>,ITraverseProcessor> processorcache
-
-
Method Detail
-
getDefaultProcessors
public static java.util.List<ITraverseProcessor> getDefaultProcessors()
Get the default traversal processors.- Returns:
- The traversal processors.
-
getInstance
public static Traverser getInstance()
Get the default cloner instance.
-
traverseObject
public static java.lang.Object traverseObject(java.lang.Object object, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, Traverser.MODE mode, java.lang.Object context)
Traverse an object.- Parameters:
object
- The object to traverse.processors
- The lists of processors.- Returns:
- The traversed (or modified) object.
-
traverseObject
public static java.lang.Object traverseObject(java.lang.Object object, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.- Parameters:
object
- The object to traverse.processors
- The lists of processors.targetcl
- If not null, the traverser should make sure that the result object is compatible with the class loader, e.g. by cloning the object using the class loaded from the target class loader.- Returns:
- The traversed (or modified) object.
-
traverseObject
public static java.lang.Object traverseObject(java.lang.Object object, java.lang.Class<?> clazz, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, Traverser.MODE mode, java.lang.Object context)
Traverse an object.- Parameters:
object
- The object to traverse.processors
- The lists of processors.- Returns:
- The traversed (or modified) object.
-
traverseObject
public static java.lang.Object traverseObject(java.lang.Object object, java.lang.Class<?> clazz, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.- Parameters:
object
- The object to traverse.processors
- The lists of processors.targetcl
- If not null, the traverser should make sure that the result object is compatible with the class loader, e.g. by cloning the object using the class loaded from the target class loader.- Returns:
- The traversed (or modified) object.
-
traverse
public java.lang.Object traverse(java.lang.Object object, java.lang.reflect.Type clazz, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.- Parameters:
object
- The object.targetcl
- If not null, the traverser should make sure that the result object is compatible with the class loader, e.g. by cloning the object using the class loaded from the target class loader.- Returns:
- The processed object.
-
doTraverse
public java.lang.Object doTraverse(java.lang.Object object, java.lang.reflect.Type type, java.util.List<ITraverseProcessor> conversionprocessors, java.util.List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, java.lang.ClassLoader targetcl, java.lang.Object context)
Traverse an object.- Parameters:
object
- The object.targetcl
- If not null, the traverser should make sure that the result object is compatible with the class loader, e.g. by cloning the object using the class loaded from the target class loader.- Returns:
- The processed object.
-
findClazz
public java.lang.Class<?> findClazz(java.lang.Object object, java.lang.ClassLoader cl)
Find the class of an object.- Parameters:
object
- The object.cl
- The classloader.- Returns:
- The objects class.
-
preemptProcessing
public java.lang.Object preemptProcessing(java.lang.Object inputobject, java.lang.reflect.Type inputtype, java.lang.Object context)
Allows preemption of processing, if the return value is not null, the returned object is used and processing is skipped.- Parameters:
inputobject
- The input objectinputtype
- The input class.context
- The context.- Returns:
- Null to process as normal, any other object skips normal processing.
-
finalizeProcessing
public void finalizeProcessing(java.lang.Object inputobject, java.lang.Object outputobject, ITraverseProcessor convproc, ITraverseProcessor proc, java.lang.Object context)
Handle objects after all processing steps have been done before object is returned. Not called for objects returned by preHandle().- Parameters:
inputobject
- The input objectoutputobject
- The object after processing.context
- The context.
-
convertBasicType
public static java.lang.Object convertBasicType(IStringConverter converter, java.lang.Object value, java.lang.Class<?> targetclazz, java.lang.ClassLoader cl, java.lang.Object context)
Convert a basic type.- Parameters:
value
- The value.targetclazz
- The target class.- Returns:
- The converted value.
-
-