Package repast.simphony.integration
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 Summary
Constructors Constructor Description BeanBuilder()
Instantiates this object without a class to create a bean from.BeanBuilder(Class<?> rootBeanClass)
Instantiates this with the specified class to use as the root to set values on.BeanBuilder(Object target)
Instantiates this object without a class to create a bean from.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
detach()
Detaches the current object from it's parent.void
detach(Iterable<ObjectHolder> objsToDetach)
Detaches each of the given objects from their parents.Object
getRoot()
Retrieves the root object.Class
getRootBeanClass()
Retrieves the class that will act as the base for setting values.Object
getValue(Object o)
Extracts a value from a Node and returns it.Object
getWrittenObject()
Retrieves the object (an instance of the root bean class) that was written to by this instance.void
goRoot()
Sets the current object to be the root object.void
goUp()
Sets the current object up a level in the hierarchy.void
initialize()
Instantiates an instance of the root bean class and starts using it.Object
selectNode(Object curContext, String path)
Selects a node using the specified context as the current location.Object
selectNode(String path)
Selects a node from using the current location (or root if no such thing exists) using the specified path.List<?>
selectNodes(Object curContext, String path)
Selects multiple nodes using the query based at the specified context.List<?>
selectNodes(String path)
Selects multiple nodes using the query.void
setRootBeanClass(Class<?> rootBeanClass)
Sets the class to use as the root for setting values.ObjectHolder
writeValue(String name, Object value)
Writes a value to the specified object
-
-
-
Constructor Detail
-
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 asBeanBuilder(null)}
.- See Also:
BeanBuilder(Class)
-
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 asBeanBuilder(null)}
.- See Also:
BeanBuilder(Class)
-
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:
setRootBeanClass(Class)
-
-
Method Detail
-
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 interfaceOutputBuilder<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:
OutputBuilder.detach(Iterable)
-
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 interfaceOutputBuilder<ObjectHolder,Object>
-
goRoot
public void goRoot()
Sets the current object to be the root object.- Specified by:
goRoot
in interfaceOutputBuilder<ObjectHolder,Object>
-
writeValue
public ObjectHolder writeValue(String name, Object value)
Writes a value to the specified object- Specified by:
writeValue
in interfaceOutputBuilder<ObjectHolder,Object>
- Parameters:
name
- the name to write the value undervalue
- 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 interfaceOutputBuilder<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 interfaceOutputBuilder<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 indetach()
, but for each object.- Specified by:
detach
in interfaceOutputBuilder<ObjectHolder,Object>
- Parameters:
objsToDetach
- the objects to detach- See Also:
detach()
-
initialize
public void initialize()
Instantiates an instance of the root bean class and starts using it.- Specified by:
initialize
in interfaceOutputBuilder<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 interfaceQueryable
- 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 interfaceQueryable
- Parameters:
curContext
- the context of the querypath
- the query- Returns:
- the value of the query
- See Also:
Queryable.selectNode(String)
-
selectNodes
public List<?> selectNodes(String path)
Description copied from interface:Queryable
Selects multiple nodes using the query.- Specified by:
selectNodes
in interfaceQueryable
- 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 interfaceQueryable
path
- the query- Returns:
- the result
-
getRoot
public Object getRoot()
Description copied from interface:Queryable
Retrieves the root object.
-
-