Class Traverser

java.lang.Object
jadex.common.transformation.traverser.Traverser

public class Traverser extends 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).
  • Field Details

    • IGNORE_RESULT

      public static final Object IGNORE_RESULT
    • instance

      protected static volatile Traverser instance
      The default cloner.
    • processors

      protected static final List<ITraverseProcessor> processors
      The default traversal processors with no special actions.
    • processorcache

      protected Map<Class<?>,ITraverseProcessor> processorcache
  • Constructor Details

    • Traverser

      public Traverser()
  • Method Details

    • getDefaultProcessors

      public static 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 Object traverseObject(Object object, List<ITraverseProcessor> conversionprocessors, List<ITraverseProcessor> processors, Traverser.MODE mode, 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 Object traverseObject(Object object, List<ITraverseProcessor> conversionprocessors, List<ITraverseProcessor> processors, Traverser.MODE mode, ClassLoader targetcl, 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 Object traverseObject(Object object, Class<?> clazz, List<ITraverseProcessor> conversionprocessors, List<ITraverseProcessor> processors, Traverser.MODE mode, 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 Object traverseObject(Object object, Class<?> clazz, List<ITraverseProcessor> conversionprocessors, List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, ClassLoader targetcl, 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 Object traverse(Object object, Type clazz, List<ITraverseProcessor> conversionprocessors, List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, ClassLoader targetcl, 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 Object doTraverse(Object object, Type type, List<ITraverseProcessor> conversionprocessors, List<ITraverseProcessor> processors, IStringConverter converter, Traverser.MODE mode, ClassLoader targetcl, 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 Class<?> findClazz(Object object, ClassLoader cl)
      Find the class of an object.
      Parameters:
      object - The object.
      cl - The classloader.
      Returns:
      The objects class.
    • preemptProcessing

      public Object preemptProcessing(Object inputobject, Type inputtype, 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 object
      inputtype - The input class.
      context - The context.
      Returns:
      Null to process as normal, any other object skips normal processing.
    • finalizeProcessing

      public void finalizeProcessing(Object inputobject, Object outputobject, ITraverseProcessor convproc, ITraverseProcessor proc, 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 object
      outputobject - The object after processing.
      context - The context.
    • convertBasicType

      public static Object convertBasicType(IStringConverter converter, Object value, Class<?> targetclazz, ClassLoader cl, Object context)
      Convert a basic type.
      Parameters:
      value - The value.
      targetclazz - The target class.
      Returns:
      The converted value.