com.acsinet_solutions.util.build
Class BlockBuilder

java.lang.Object
  extended by com.acsinet_solutions.util.build.BlockBuilder
All Implemented Interfaces:
Builder

public class BlockBuilder
extends java.lang.Object
implements Builder

An implementation of a builder based in BuildingBlock beans. This represents a very practical way to build objects from a source like an XML file, as a very easy alternative to other libraries that build object hierarchies from XML files.

This class works well with XMLObjectFactory when processing XML files. See BlockBuilerTest source for examples.

WARNING! This class is not intended to be thread safe nor reusable

Author:
Santiago Arriaga
See Also:
XMLObjectFactory, BlockBuilderTest

Constructor Summary
BlockBuilder()
          Empty constructor
BlockBuilder(java.lang.Class defaultRootClass)
           
BlockBuilder(java.lang.Object rootObject)
           
 
Method Summary
 void enterObject(java.lang.String name, java.lang.String className)
          Add a new object to the builder
 void exitObject()
          Exit the current object instance.
 java.lang.Object getObject()
          Get the built object.
protected  void setup(java.lang.Object object)
          Setup the object before adding it to the parent object.
 void setValue(java.lang.String name, java.lang.Object value)
          Set a value to the current target object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockBuilder

public BlockBuilder(java.lang.Object rootObject)
Parameters:
rootObject - The root object that will be the root of the block building.

BlockBuilder

public BlockBuilder(java.lang.Class defaultRootClass)
Parameters:
defaultRootClass - A maybe-null Class instance value

BlockBuilder

public BlockBuilder()
Empty constructor

Method Detail

enterObject

public final void enterObject(java.lang.String name,
                              java.lang.String className)
                       throws BuildException
Description copied from interface: Builder
Add a new object to the builder

Specified by:
enterObject in interface Builder
Parameters:
name - The not-null not-empty name of the type instance
className - The maybe-null class type of the instance
Throws:
BuildException - Thrown if any building error occurs

setValue

public final void setValue(java.lang.String name,
                           java.lang.Object value)
                    throws BuildException
Description copied from interface: Builder
Set a value to the current target object

Specified by:
setValue in interface Builder
Parameters:
name - The not-null not-empty name of the attribute to be set
value - The maybe-null value of the given attribute
Throws:
BuildException - Thrown if any building error occurs

exitObject

public final void exitObject()
                      throws BuildException
Description copied from interface: Builder
Exit the current object instance. Every exitObject() call is issued for a call of enterObject();

Specified by:
exitObject in interface Builder
Throws:
BuildException - Thrown if any building error occurs

getObject

public final java.lang.Object getObject()
                                 throws BuildException
Description copied from interface: Builder
Get the built object.

Specified by:
getObject in interface Builder
Returns:
A not-null not-empty Object instance
Throws:
BuildException - Thrown if any building error occurs

setup

protected void setup(java.lang.Object object)
              throws BuildException
Setup the object before adding it to the parent object. Meant for subclasses. Default implementation does nothing.

Throws:
BuildException