Package: groovy.util

## [Java] Class ObjectGraphBuilder

- groovy.util.ObjectGraphBuilder

-     public class ObjectGraphBuilder
      extends FactoryBuilderSupport

  A builder for creating object graphs.
  Each node defines the class to be created and the property on its parent (if any) at the same time.

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `interface` | `ObjectGraphBuilder.ChildPropertySetter` | Strategy for setting a child node on its parent.
    `interface` | `ObjectGraphBuilder.ClassNameResolver` | Strategy for resolving a classname.
    `static class` | `ObjectGraphBuilder.DefaultChildPropertySetter` | Default impl that calls parent.propertyName = child If parent.propertyName is a Collection it will try to add child to the collection.
    `static class` | `ObjectGraphBuilder.DefaultClassNameResolver` | Default impl that capitalizes the classname.
    `static class` | `ObjectGraphBuilder.DefaultIdentifierResolver` | Default impl, always returns 'id'
    `static class` | `ObjectGraphBuilder.DefaultNewInstanceResolver` | Default impl that calls Class.newInstance()
    `static class` | `ObjectGraphBuilder.DefaultReferenceResolver` | Default impl, always returns 'refId'
    `static class` | `ObjectGraphBuilder.DefaultRelationNameResolver` | Default impl that returns parentName and childName accordingly.
    `interface` | `ObjectGraphBuilder.IdentifierResolver` | Strategy for picking the correct synthetic identifier.
    `interface` | `ObjectGraphBuilder.NewInstanceResolver` | Strategy for creating new instances of a class.
    `interface` | `ObjectGraphBuilder.ReferenceResolver` | Strategy for picking the correct synthetic reference identifier.
    `class` | `ObjectGraphBuilder.ReflectionClassNameResolver` | Build objects using reflection to resolve class names.
    `interface` | `ObjectGraphBuilder.RelationNameResolver` | Strategy for resolving a relationship property name.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static String` | `CLASSNAME_RESOLVER_KEY` | Option key selecting a class-name resolver strategy.
    `static String` | `CLASSNAME_RESOLVER_REFLECTION` | Resolver option that uses reflection against the graph model.
    `static String` | `CLASSNAME_RESOLVER_REFLECTION_ROOT` | Resolver option holding the root package for reflection lookup.
    `static String` | `LAZY_REF` | Context key indicating that a reference should be resolved lazily.
    `static String` | `NODE_CLASS` | Context key for the resolved node class.
    `static String` | `NODE_NAME` | Context key for the resolved node name.
    `static String` | `OBJECT_ID` | Context key for a synthetic object identifier.

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class FactoryBuilderSupport` | `CHILD_BUILDER, CURRENT_BUILDER, CURRENT_FACTORY, CURRENT_NAME, CURRENT_NODE, OWNER, PARENT_BUILDER, PARENT_CONTEXT, PARENT_FACTORY, PARENT_NAME, PARENT_NODE, SCRIPT_CLASS_NAME, attributeDelegates, autoRegistrationComplete, autoRegistrationRunning, explicitMethods, explicitProperties, methodMissingDelegate, postInstantiateDelegates, postNodeCompletionDelegates, preInstantiateDelegates, propertyMissingDelegate, registrationGroup, registrationGroupName`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `ObjectGraphBuilder()` Creates an object graph builder with default resolver strategies.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public String` | `getBeanFactoryName()` Returns the current name of the 'bean' node.
    `` | `public ObjectGraphBuilder.ChildPropertySetter` | `getChildPropertySetter()` Returns the current ChildPropertySetter.
    `` | `public ClassLoader` | `getClassLoader()` Returns the classLoader used to load a node's class.
    `` | `public ObjectGraphBuilder.ClassNameResolver` | `getClassNameResolver()` Returns the current ClassNameResolver.
    `` | `public ObjectGraphBuilder.NewInstanceResolver` | `getNewInstanceResolver()` Returns the current NewInstanceResolver.
    `` | `public ObjectGraphBuilder.RelationNameResolver` | `getRelationNameResolver()` Returns the current RelationNameResolver.
    `` | `public boolean` | `isLazyReferencesAllowed()` Returns true if references can be resolved lazily
    `` | `protected void` | `postInstantiate(Object name, Map attributes, Object node)` * A hook after the factory creates the node and before attributes are set. * It will call any registered postInstantiateDelegates, if you override * this method be sure to call this impl somewhere in your code. * * Parameters: `name` - the name of the node * `attributes` - the attributes for the node * `node` - the object created by the node factory
    `` | `protected void` | `preInstantiate(Object name, Map attributes, Object value)` * A hook before the factory creates the node. * It will call any registered preInstantiateDelegates, if you override this * method be sure to call this impl somewhere in your code. * * Parameters: `name` - the name of the node * `attributes` - the attributes of the node * `value` - the value argument(s) of the node
    `` | `protected Factory` | `resolveFactory(Object name, Map attributes, Object value)` * This is a hook for subclasses to plug in a custom strategy for mapping * names to factories. * * Parameters: `name` - the name of the factory * `attributes` - the attributes from the node * `value` - value arguments from te node * Returns: the Factory associated with name.
    `` | `public void` | `setBeanFactoryName(String beanFactoryName)` Sets the name for the 'bean' node.
    `` | `public void` | `setChildPropertySetter(Object childPropertySetter)` Sets the current ChildPropertySetter.
    `` | `public void` | `setClassLoader(ClassLoader classLoader)` Sets the classLoader used to load a node's class.
    `` | `public void` | `setClassNameResolver(Object classNameResolver)` Sets the current ClassNameResolver.
    `` | `public void` | `setIdentifierResolver(Object identifierResolver)` Sets the current IdentifierResolver.
    `` | `public void` | `setLazyReferencesAllowed(boolean lazyReferencesAllowed)` Sets whether references can be resolved lazily or not.
    `` | `public void` | `setNewInstanceResolver(Object newInstanceResolver)` Sets the current NewInstanceResolver.
    `` | `public void` | `setReferenceResolver(Object referenceResolver)` Sets the current ReferenceResolver.
    `` | `public void` | `setRelationNameResolver(ObjectGraphBuilder.RelationNameResolver relationNameResolver)` Sets the current RelationNameResolver.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class FactoryBuilderSupport` | `addAttributeDelegate, addDisposalClosure, addPostInstantiateDelegate, addPostNodeCompletionDelegate, addPreInstantiateDelegate, autoRegisterNodes, build, build, build, checkExplicitMethod, checkValueIsNull, checkValueIsType, checkValueIsTypeNotString, createNode, dispatchNodeCall, dispathNodeCall, dispose, getAttributeDelegates, getChildBuilder, getContext, getContextAttribute, getContexts, getContinuationData, getCurrent, getCurrentBuilder, getCurrentFactory, getCurrentName, getDisposalClosures, getExplicitMethods, getExplicitProperties, getFactories, getLocalExplicitMethods, getLocalExplicitProperties, getLocalFactories, getMethodMissingDelegate, getName, getNameMappingClosure, getParentContext, getParentFactory, getParentName, getParentNode, getPostInstantiateDelegates, getPostNodeCompletionDelegates, getPreInstantiateDelegates, getProperty, getPropertyMissingDelegate, getProxyBuilder, getRegistrationGroupItems, getRegistrationGroups, getVariable, getVariables, handleNodeAttributes, invokeMethod, invokeMethod, newContext, nodeCompleted, popContext, postInstantiate, postNodeCompletion, preInstantiate, registerBeanFactory, registerBeanFactory, registerExplicitMethod, registerExplicitMethod, registerExplicitProperty, registerExplicitProperty, registerFactory, registerFactory, removeAttributeDelegate, removePostInstantiateDelegate, removePostNodeCompletionDelegate, removePreInstantiateDelegate, reset, resolveExplicitMethod, resolveExplicitProperty, resolveFactory, restoreFromContinuationData, setClosureDelegate, setMethodMissingDelegate, setNameMappingClosure, setNodeAttributes, setParent, setProperty, setPropertyMissingDelegate, setProxyBuilder, setVariable, withBuilder, withBuilder, withBuilder`
    `class Binding` | `getProperty, getVariable, getVariables, hasVariable, removeVariable, setProperty, setVariable`
    `class GroovyObjectSupport` | `getMetaClass, setMetaClass`

- - ### Field Detail

    - #### public static final String CLASSNAME_RESOLVER_KEY

      Option key selecting a class-name resolver strategy.

    - #### public static final String CLASSNAME_RESOLVER_REFLECTION

      Resolver option that uses reflection against the graph model.

    - #### public static final String CLASSNAME_RESOLVER_REFLECTION_ROOT

      Resolver option holding the root package for reflection lookup.

    - #### public static final String LAZY_REF

      Context key indicating that a reference should be resolved lazily.

    - #### public static final String NODE_CLASS

      Context key for the resolved node class.

    - #### public static final String NODE_NAME

      Context key for the resolved node name.

    - #### public static final String OBJECT_ID

      Context key for a synthetic object identifier.

  - ### Constructor Detail

    - #### public ObjectGraphBuilder()

      Creates an object graph builder with default resolver strategies.

  - ### Method Detail

    - #### public String getBeanFactoryName()

      Returns the current name of the 'bean' node.

    - #### public ObjectGraphBuilder.ChildPropertySetter getChildPropertySetter()

      Returns the current ChildPropertySetter.

    - #### public ClassLoader getClassLoader()

      Returns the classLoader used to load a node's class.

    - #### public ObjectGraphBuilder.ClassNameResolver getClassNameResolver()

      Returns the current ClassNameResolver.

    - #### public ObjectGraphBuilder.NewInstanceResolver getNewInstanceResolver()

      Returns the current NewInstanceResolver.

    - #### public ObjectGraphBuilder.RelationNameResolver getRelationNameResolver()

      Returns the current RelationNameResolver.

    - #### public boolean isLazyReferencesAllowed()

      Returns true if references can be resolved lazily

    - #### protected void postInstantiate(Object name, Map attributes, Object node)

      * A hook after the factory creates the node and before attributes are set.
      * It will call any registered postInstantiateDelegates, if you override * this method be sure to call this impl somewhere in your code. * *

      Parameters:
        `name` - the name of the node *
        `attributes` - the attributes for the node *
        `node` - the object created by the node factory

    - #### protected void preInstantiate(Object name, Map attributes, Object value)

      * A hook before the factory creates the node.
      * It will call any registered preInstantiateDelegates, if you override this * method be sure to call this impl somewhere in your code. * *

      Parameters:
        `name` - the name of the node *
        `attributes` - the attributes of the node *
        `value` - the value argument(s) of the node

    - #### protected Factory resolveFactory(Object name, Map attributes, Object value)

      * This is a hook for subclasses to plug in a custom strategy for mapping * names to factories. * *

      Parameters:
        `name` - the name of the factory *
        `attributes` - the attributes from the node *
        `value` - value arguments from te node *
      Returns:
        the Factory associated with name.

    - #### public void setBeanFactoryName(String beanFactoryName)

      Sets the name for the 'bean' node.

    - #### public void setChildPropertySetter(Object childPropertySetter)

      Sets the current ChildPropertySetter.
      It will assign DefaultChildPropertySetter if null.
      It accepts a ChildPropertySetter instance or a Closure.

    - #### public void setClassLoader(ClassLoader classLoader)

      Sets the classLoader used to load a node's class.

    - #### public void setClassNameResolver(Object classNameResolver)

      Sets the current ClassNameResolver.
      It will assign DefaultClassNameResolver if null.
      It accepts a ClassNameResolver instance, a String, a Closure or a Map.

    - #### public void setIdentifierResolver(Object identifierResolver)

      Sets the current IdentifierResolver.
      It will assign DefaultIdentifierResolver if null.
      It accepts a IdentifierResolver instance, a String or a Closure.

    - #### public void setLazyReferencesAllowed(boolean lazyReferencesAllowed)

      Sets whether references can be resolved lazily or not.

    - #### public void setNewInstanceResolver(Object newInstanceResolver)

      Sets the current NewInstanceResolver.
      It will assign DefaultNewInstanceResolver if null.
      It accepts a NewInstanceResolver instance or a Closure.

    - #### public void setReferenceResolver(Object referenceResolver)

      Sets the current ReferenceResolver.
      It will assign DefaultReferenceResolver if null.
      It accepts a ReferenceResolver instance, a String or a Closure.

    - #### public void setRelationNameResolver(ObjectGraphBuilder.RelationNameResolver relationNameResolver)

      Sets the current RelationNameResolver.
      It will assign DefaultRelationNameResolver if null.