Package repast.simphony.integration
Class BeanBuilder
java.lang.Object
repast.simphony.integration.BeanBuilder
- All Implemented Interfaces:
OutputBuilder<ObjectHolder,
,Object> Queryable
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
ConstructorDescriptionInstantiates 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
Modifier and TypeMethodDescriptioncreateAndGoInto
(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.getRoot()
Retrieves the root object.Retrieves the class that will act as the base for setting values.Extracts a value from a Node and returns it.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
Instantiates an instance of the root bean class and starts using it.selectNode
(Object curContext, String path) Selects a node using the specified context as the current location.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.writeValue
(String name, Object value) Writes a value to the specified object
-
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 asBeanBuilder(null)}
.- See Also:
-
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
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
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
Retrieves the class that will act as the base for setting values.- Returns:
- the specified root bean class
-
createAndGoInto
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:
-
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
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
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
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:
-
initialize
public void initialize()Instantiates an instance of the root bean class and starts using it.- Specified by:
initialize
in interfaceOutputBuilder<ObjectHolder,
Object>
-
selectNode
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
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:
-
selectNodes
Description copied from interface:Queryable
Selects multiple nodes using the query.- Specified by:
selectNodes
in interfaceQueryable
- Parameters:
path
- the query- Returns:
- the result
-
selectNodes
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
Description copied from interface:Queryable
Retrieves the root object. -
getValue
Description copied from interface:Queryable
Extracts a value from a Node and returns it. What this means is implementation dependent.
-