groovytools.builder
Class MetaObjectGraphBuilder

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by groovy.lang.Binding
          extended by groovy.util.FactoryBuilderSupport
              extended by groovy.util.ObjectGraphBuilder
                  extended by groovytools.builder.MetaObjectGraphBuilder
All Implemented Interfaces:
GroovyObject

public class MetaObjectGraphBuilder
extends ObjectGraphBuilder

This class is the workhorse behind MetaBuilder. It is responsible for building object hierarchies according to the schemas given to it. It is not intended to be used independently of MetaBuilder.

Version:
$Id: MetaObjectGraphBuilder.java 63 2009-07-31 07:10:10Z didge $
Author:
didge

Nested Class Summary
 class MetaObjectGraphBuilder.FactoryClassNameResolver
          Overrides the default implementation in MetaObjectGraphBuilder.FactoryClassNameResolver in order to support resolution of the class name using the factory schema attribute.
 
Nested classes/interfaces inherited from class groovy.util.ObjectGraphBuilder
ObjectGraphBuilder.ChildPropertySetter, ObjectGraphBuilder.ClassNameResolver, ObjectGraphBuilder.DefaultChildPropertySetter, ObjectGraphBuilder.DefaultClassNameResolver, ObjectGraphBuilder.DefaultIdentifierResolver, ObjectGraphBuilder.DefaultNewInstanceResolver, ObjectGraphBuilder.DefaultReferenceResolver, ObjectGraphBuilder.DefaultRelationNameResolver, ObjectGraphBuilder.IdentifierResolver, ObjectGraphBuilder.NewInstanceResolver, ObjectGraphBuilder.ReferenceResolver, ObjectGraphBuilder.RelationNameResolver
 
Field Summary
 
Fields inherited from class groovy.util.ObjectGraphBuilder
NODE_CLASS, NODE_NAME, OBJECT_ID
 
Fields inherited from class groovy.util.FactoryBuilderSupport
CURRENT_FACTORY, CURRENT_NAME, CURRENT_NODE, OWNER, PARENT_CONTEXT, PARENT_FACTORY, PARENT_NAME, PARENT_NODE
 
Constructor Summary
MetaObjectGraphBuilder(MetaBuilder metaBuilder, SchemaNode defaultSchema, Factory defaultFactory)
          Constructs a MetaObjectGraphBuilder.
MetaObjectGraphBuilder(MetaBuilder metaBuilder, SchemaNode defaultSchema, Factory defaultFactory, Closure objectVisitor)
          Constructs a MetaObjectGraphBuilder.
 
Method Summary
protected  void checkCollections(SchemaNode currentSchema, Object node)
           
protected  void checkNode(SchemaNode schema, Object node)
          Execute check against node, if one exists.
protected  void checkPropertyValue(SchemaNode schema, Object val)
          Check value against a propertySchema's check attribute, if it exists.
protected  ObjectGraphBuilder.ClassNameResolver createClassNameResolver()
          Override to modify the MetaObjectGraphBuilder.FactoryClassNameResolver behavior.
protected  ObjectGraphBuilder.IdentifierResolver createIdentifierResolver()
          Override to modify the ObjectGraphBuilder.IdentifierResolver behavior.
protected  Object createNode(Object name, Map attributes, Object value)
          Overrides in order to construct nodes based on the current schema definition.
protected  SchemaNode findCollectionSchema(SchemaNode parentSchema, String containerName, String name)
           
protected  SchemaNode findSchema(SchemaNode parentSchema, String containerName, String name)
          Finds and returns a child schema with the given name, in the specified container or null if not found.
protected  Object findSchemaAttribute(SchemaNode parentSchema, String name)
           
 Map getCurrentProperties()
           
 SchemaNode getCurrentSchema()
           
protected  SchemaNode getMergedCollections(SchemaNode schema)
          Return a shallow set of merged collections by searching for all collections of schema and its parents, in a depth first manner.
protected  SchemaNode getMergedProperties(SchemaNode schema)
          Return a shallow set of merged properties by searching for all properties of schema and its parents, in a depth first manner.
 MetaBuilder getMetaBuilder()
           
protected  Comparable getMinMaxValComp(SchemaNode schema, String name, Object val)
          Returns a Comparable object that can be used with the min and max constraints.
 Closure getObjectVisitor()
           
protected  void handleUnsetProperties(SchemaNode currentSchema, Object node)
           
protected  void nodeCompleted(Object parent, Object node)
          Overrides the default implementation to: sync the schema with the current node handle unset properties check collections execute any check on the node iteself
 Map popProperties()
           
 SchemaNode popSchema()
           
 void pushProperties(Map properties)
           
 void pushProperties(SchemaNode propertiesSchema)
           
 void pushSchema(SchemaNode schema)
           
protected  Factory resolveFactory(Object name, Map attributes, Object value)
          Overrides the default implementation to support lookup of a factory defined in a schema attribute.
protected  SchemaNode resolveSchemaRef(Object schemaRef)
          Returns the schema referenced by name.
protected  void setNodeAttributes(Object node, Map attributesMap)
          Sets properties on the node based on the current schema.
 void setObjectVisitor(Closure objectVisitor)
           
protected  void setParent(Object parent, Object child)
          Overrides the default implementation in order set the parent using the current schema definition.
protected  void setProperty(Object node, Object value, SchemaNode propertySchema)
          Sets a node's property value, allowing for property renaming.
 void setVariable(Object node, SchemaNode schema, String name, Object value)
          Sets the given node's property value by name referencing the given schema.
 void setVariable(String name, Object value)
          Sets thet node's property value by name referencing the current schema.
 
Methods inherited from class groovy.util.ObjectGraphBuilder
getChildPropertySetter, getClassLoader, getClassNameResolver, getNewInstanceResolver, getRelationNameResolver, postInstantiate, preInstantiate, setChildPropertySetter, setClassLoader, setClassNameResolver, setIdentifierResolver, setNewInstanceResolver, setReferenceResolver, setRelationNameResolver
 
Methods inherited from class groovy.util.FactoryBuilderSupport
addAttributeDelegate, addDisposalClosure, addPostInstantiateDelegate, addPostNodeCompletionDelegate, addPreInstantiateDelegate, build, build, build, checkValueIsNull, checkValueIsType, checkValueIsTypeNotString, dispose, getContext, getContexts, getCurrent, getCurrentFactory, getCurrentName, getFactories, getName, getParentContext, getParentFactory, getParentName, getParentNode, getProxyBuilder, handleNodeAttributes, invokeMethod, invokeMethod, newContext, popContext, postNodeCompletion, registerBeanFactory, registerFactory, removeAttributeDelegate, removePostInstantiateDelegate, removePostNodeCompletionDelegate, removePreInstantiateDelegate, reset, setClosureDelegate, setProxyBuilder, withBuilder, withBuilder, withBuilder
 
Methods inherited from class groovy.lang.Binding
getProperty, getVariable, getVariables, setProperty
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MetaObjectGraphBuilder

public MetaObjectGraphBuilder(MetaBuilder metaBuilder,
                              SchemaNode defaultSchema,
                              Factory defaultFactory)
Constructs a MetaObjectGraphBuilder.

Parameters:
metaBuilder - the MetaBuilder providing the build context
defaultSchema -
defaultFactory -

MetaObjectGraphBuilder

public MetaObjectGraphBuilder(MetaBuilder metaBuilder,
                              SchemaNode defaultSchema,
                              Factory defaultFactory,
                              Closure objectVisitor)
Constructs a MetaObjectGraphBuilder.

Parameters:
metaBuilder - the MetaBuilder providing the build context
defaultSchema -
defaultFactory -
objectVisitor -
Method Detail

getMetaBuilder

public MetaBuilder getMetaBuilder()

pushProperties

public void pushProperties(SchemaNode propertiesSchema)

pushProperties

public void pushProperties(Map properties)

popProperties

public Map popProperties()

getCurrentProperties

public Map getCurrentProperties()

pushSchema

public void pushSchema(SchemaNode schema)

popSchema

public SchemaNode popSchema()

getCurrentSchema

public SchemaNode getCurrentSchema()

getObjectVisitor

public Closure getObjectVisitor()

setObjectVisitor

public void setObjectVisitor(Closure objectVisitor)

resolveSchemaRef

protected SchemaNode resolveSchemaRef(Object schemaRef)
Returns the schema referenced by name.

Parameters:
schemaRef - the schema reference
Returns:
see above

findSchema

protected SchemaNode findSchema(SchemaNode parentSchema,
                                String containerName,
                                String name)
Finds and returns a child schema with the given name, in the specified container or null if not found. This method will also search any super-schemas specified with the 'schema' attribute.

Parameters:
parentSchema - the parent schema
containerName - the name of a container of child schemas, e.g. collections, properties
name - the name of the child schema
Returns:
see above

findCollectionSchema

protected SchemaNode findCollectionSchema(SchemaNode parentSchema,
                                          String containerName,
                                          String name)

findSchemaAttribute

protected Object findSchemaAttribute(SchemaNode parentSchema,
                                     String name)

createNode

protected Object createNode(Object name,
                            Map attributes,
                            Object value)
Overrides in order to construct nodes based on the current schema definition.

Overrides:
createNode in class FactoryBuilderSupport
Parameters:
name - the name of the node
attributes - optional attributes of the current node
value - optional value of the current node
Returns:
a node

setVariable

public void setVariable(String name,
                        Object value)
Sets thet node's property value by name referencing the current schema. Invoked when using '=' to set a property value.

Overrides:
setVariable in class Binding
Parameters:
name - the property name
value - the property value
See Also:
setVariable(Object, SchemaNode, String, Object)

setVariable

public void setVariable(Object node,
                        SchemaNode schema,
                        String name,
                        Object value)
Sets the given node's property value by name referencing the given schema.

Parameters:
node - the property owner
schema - the property owner's schema
name - the property name
value - the property value

nodeCompleted

protected void nodeCompleted(Object parent,
                             Object node)
Overrides the default implementation to:

Overrides:
nodeCompleted in class FactoryBuilderSupport
Parameters:
parent - the parent node
node - the node that is being completed

checkCollections

protected void checkCollections(SchemaNode currentSchema,
                                Object node)

handleUnsetProperties

protected void handleUnsetProperties(SchemaNode currentSchema,
                                     Object node)

createIdentifierResolver

protected ObjectGraphBuilder.IdentifierResolver createIdentifierResolver()
Override to modify the ObjectGraphBuilder.IdentifierResolver behavior.

Returns:
see above

createClassNameResolver

protected ObjectGraphBuilder.ClassNameResolver createClassNameResolver()
Override to modify the MetaObjectGraphBuilder.FactoryClassNameResolver behavior.

Returns:
see above

resolveFactory

protected Factory resolveFactory(Object name,
                                 Map attributes,
                                 Object value)
Overrides the default implementation to support lookup of a factory defined in a schema attribute. The Factory is resolved as follows:
  1. If the schema itself is an instance of Factory, then it is returned.
  2. If the schema defines an attribute value called factory which is an instance of Factory, then the attribute value is returned.
  3. If the schema defines an attribute value called factory which is an instance of Closure, then the Closure will be returned, wrapped by ClosureFactoryAdapter
  4. If the schema defines an attribute value called factory which is an instance of String or Class, then the corresponding class will be instantiated and returned.

Overrides:
resolveFactory in class ObjectGraphBuilder
Parameters:
name -
attributes -
value -
Returns:
see above

getMergedProperties

protected SchemaNode getMergedProperties(SchemaNode schema)
Return a shallow set of merged properties by searching for all properties of schema and its parents, in a depth first manner. This facilitates fast lookup of property attributes and tracking which properties have been set and which have not.

Parameters:
schema - the owner of the properties
Returns:
see above

getMergedCollections

protected SchemaNode getMergedCollections(SchemaNode schema)
Return a shallow set of merged collections by searching for all collections of schema and its parents, in a depth first manner. This facilitates fast lookup of collection attributes and checking.

Parameters:
schema - the owner of the collections
Returns:
see above

setNodeAttributes

protected void setNodeAttributes(Object node,
                                 Map attributesMap)
Sets properties on the node based on the current schema.

Overrides:
setNodeAttributes in class FactoryBuilderSupport
Parameters:
node -
attributesMap -
See Also:
setProperty(java.lang.Object, java.lang.Object, groovytools.builder.SchemaNode)

checkPropertyValue

protected void checkPropertyValue(SchemaNode schema,
                                  Object val)
Check value against a propertySchema's check attribute, if it exists.

Parameters:
schema - see above
val - the value

checkNode

protected void checkNode(SchemaNode schema,
                         Object node)
Execute check against node, if one exists.

Parameters:
schema - see above
node - the node

getMinMaxValComp

protected Comparable getMinMaxValComp(SchemaNode schema,
                                      String name,
                                      Object val)
Returns a Comparable object that can be used with the min and max constraints.

Parameters:
schema - the property owner (used to report errors)
name - the property name (used to report errors)
val - the property value
Returns:
see above

setProperty

protected void setProperty(Object node,
                           Object value,
                           SchemaNode propertySchema)
Sets a node's property value, allowing for property renaming. The property name is taken from the property schema's property attribute, if any, else the property node name is used by default.

Parameters:
node - the current node
value - the value of the property
propertySchema - the property's property attribute or name

setParent

protected void setParent(Object parent,
                         Object child)
Overrides the default implementation in order set the parent using the current schema definition.

Overrides:
setParent in class FactoryBuilderSupport
Parameters:
parent -
child -


Copyright © 2008 FoundryLogic, LLC. All Rights Reserved.