Class BeanBuilder

java.lang.Object
repast.simphony.integration.BeanBuilder
All Implemented Interfaces:
OutputBuilder<ObjectHolder,Object>, Queryable

public class BeanBuilder extends Object implements OutputBuilder<ObjectHolder,Object>
Writes data to a Bean. This doesn't actually "build" a bean class, but will load a given class with data.
Author:
Jerry Vos
  • Constructor Details

    • BeanBuilder

      public BeanBuilder()
      Instantiates this object without a class to create a bean from. Before an instance created with this method can be used, setRootBeanClass(Class) must be called. This is the same as BeanBuilder(null)}.
      See Also:
    • BeanBuilder

      public BeanBuilder(Object target)
      Instantiates this object without a class to create a bean from. Before an instance created with this method can be used, setRootBeanClass(Class) must be called. This is the same as BeanBuilder(null)}.
      See Also:
    • BeanBuilder

      public BeanBuilder(Class<?> rootBeanClass)
      Instantiates this with the specified class to use as the root to set values on. Classes
      Parameters:
      rootBeanClass - the class that will be the root of the value "tree"
      See Also:
  • Method Details

    • setRootBeanClass

      public void setRootBeanClass(Class<?> rootBeanClass)
      Sets the class to use as the root for setting values. This will be the class instantiated and that will have top-level values set on it.
      Parameters:
      rootBeanClass -
    • getRootBeanClass

      public Class getRootBeanClass()
      Retrieves the class that will act as the base for setting values.
      Returns:
      the specified root bean class
    • createAndGoInto

      public ObjectHolder createAndGoInto(String name)
      Finds an "add" method with the specified name associated with it (ie addName) and instantiates an object of its argument type. It then will add the instantiated object to the current object (or the parent set in the name path) and set the current object to be the newly instantiated object.
      Specified by:
      createAndGoInto in interface OutputBuilder<ObjectHolder,Object>
      Parameters:
      name - a string that represents the name of the property to create an object for; if the name is an xpath expression then this will attempt to grab an object using the xpath expression and use the string from the last slash on as the name of the add method. For example if the name is /fileDef/bob/prop, it will find /fileDef/Bob and look for it's "addProp" method.
      Returns:
      a detachable object
      See Also:
    • goUp

      public void goUp()
      Sets the current object up a level in the hierarchy. If we're at the root object the behavior is unspecified.
      Specified by:
      goUp in interface OutputBuilder<ObjectHolder,Object>
    • goRoot

      public void goRoot()
      Sets the current object to be the root object.
      Specified by:
      goRoot in interface OutputBuilder<ObjectHolder,Object>
    • writeValue

      public ObjectHolder writeValue(String name, Object value)
      Writes a value to the specified object
      Specified by:
      writeValue in interface OutputBuilder<ObjectHolder,Object>
      Parameters:
      name - the name to write the value under
      value - the value to write
      Returns:
      a detachable object
    • getWrittenObject

      public Object getWrittenObject()
      Retrieves the object (an instance of the root bean class) that was written to by this instance.
      Specified by:
      getWrittenObject in interface OutputBuilder<ObjectHolder,Object>
      Returns:
      the root object that had values written to it
    • detach

      public void detach()
      Detaches the current object from it's parent. This will either set the current object to null in the parent (if it was set with a set method) or remove it from the parent (if it was added).
      Specified by:
      detach in interface OutputBuilder<ObjectHolder,Object>
    • detach

      public void detach(Iterable<ObjectHolder> objsToDetach)
      Detaches each of the given objects from their parents. This will occur in the way as specified in detach(), but for each object.
      Specified by:
      detach in interface OutputBuilder<ObjectHolder,Object>
      Parameters:
      objsToDetach - the objects to detach
      See Also:
    • initialize

      public void initialize()
      Instantiates an instance of the root bean class and starts using it.
      Specified by:
      initialize in interface OutputBuilder<ObjectHolder,Object>
    • selectNode

      public Object selectNode(String path)
      Description copied from interface: Queryable
      Selects a node from using the current location (or root if no such thing exists) using the specified path. If multiple nodes are returned with the query this will be the first one.
      Specified by:
      selectNode in interface Queryable
      Parameters:
      path - the XPath query
      Returns:
      the selected node (can be null if the query failed)
    • selectNode

      public Object selectNode(Object curContext, String path)
      Description copied from interface: Queryable
      Selects a node using the specified context as the current location. If multiple nodes are returned with the query this will be the first one.
      Specified by:
      selectNode in interface Queryable
      Parameters:
      curContext - the context of the query
      path - the query
      Returns:
      the value of the query
      See Also:
    • selectNodes

      public List<?> selectNodes(String path)
      Description copied from interface: Queryable
      Selects multiple nodes using the query.
      Specified by:
      selectNodes in interface Queryable
      Parameters:
      path - the query
      Returns:
      the result
    • selectNodes

      public List<?> selectNodes(Object curContext, String path)
      Description copied from interface: Queryable
      Selects multiple nodes using the query based at the specified context.
      Specified by:
      selectNodes in interface Queryable
      path - the query
      Returns:
      the result
    • getRoot

      public Object getRoot()
      Description copied from interface: Queryable
      Retrieves the root object.
      Specified by:
      getRoot in interface Queryable
      Returns:
      the root
    • getValue

      public Object getValue(Object o)
      Description copied from interface: Queryable
      Extracts a value from a Node and returns it. What this means is implementation dependent.
      Specified by:
      getValue in interface Queryable
      Parameters:
      o - the node to extract a value from
      Returns: