|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.beesoft.gaia.util.ObjectBuilder<T>
T
- class of object created by this builderpublic abstract class ObjectBuilder<T>
An abstract superclass of all builders.
A builder serves as a factory for the creation and initialization of the
created object. The building process is managed by
ObjectBuilderFactory
. This implementation does not dictate
relationships between builder, created object and XML element - it is your
responsibility.
Each builder is managed by ObjectBuilderFactory
instance that created
it. ObjectBuilderFactory
loads a XML description and for each
element creates a new appropriate builder. This is done in these steps:
ObjectBuilderFactory
and builder's
parent are stored to this buildercreateObject()
or
createObject(String)
, if the class
property was found
When ObjectBuilderFactory
processed all XML elements and for
each executed steps described above, it walks each builder again and invokes
method initObjectProperties()
on it. Builder for each property
invokes method initObjectProperty(String, String)
. This method in
current implementation searches for initialization method for given property
and invokes it.
When all builders were requested to initiaze their properties, the
ObjectBuilderFactory
notifies each builder about its hierarchy
position. On each builder with children is invoked method
addChild(ObjectBuilder)
. This is done from bottom to top in the
builder hierarchy, so parent is notified about its children when each its
child was notified about its children.
After that is builder and its object fully initialized and object can be used in application.
Constructor Summary | |
---|---|
ObjectBuilder()
|
Method Summary | |
---|---|
protected void |
addChild(ObjectBuilder<?> builder)
Invoked from ObjectBuilderFactory when adding child to this
builder. |
protected abstract T |
createObject()
Creates object for this builder. |
protected T |
createObject(java.lang.String className)
Creates object for this builder. |
ObjectBuilderFactory |
getFactory()
Returns factory which created this builder. |
java.util.List<ObjectBuilder<?>> |
getChildren()
Returns list of builder children. |
java.lang.String |
getId()
Returns id of this builder. |
T |
getObject()
Returns object created by this builder. |
ObjectBuilder<?> |
getParent()
Returns parent of this builder. |
java.util.Map<java.lang.String,java.lang.String> |
getProperties()
Returns properties for this this builder as map {name : value}. |
java.lang.String |
getProperty(java.lang.String name)
Returns a value of property with given name. |
protected void |
initClass(java.lang.String value)
|
protected void |
initId(java.lang.String value)
Initializes property ID for this value. |
void |
initObjectProperties()
Initializes object from builder properties. |
protected void |
initObjectProperty(java.lang.String name,
java.lang.String value)
Initializes this builder's object property with given name and value. |
protected boolean |
parseBoolean(java.lang.String value)
Helper method to convert given String value to boolean . |
protected java.lang.Class<?> |
parseClass(java.lang.String value)
Helper method to get class with given name. |
protected java.lang.Object |
parseConstant(java.lang.String name,
java.lang.Class<?> owner)
Helper method to get value of a constant (static field) with given name from given class. |
protected java.lang.Object |
parseConstructor(java.lang.String value,
java.lang.String defaultPackage)
Helper method to get object for given value. |
protected double |
parseDouble(java.lang.String value)
Helper method to convert given String value to double . |
protected java.lang.Object |
parseInstance(java.lang.String value)
Helper method to get object for given name. |
protected java.lang.Object |
parseInstance(java.lang.String value,
java.lang.Class<?> instanceOf)
Helper method to get object for given name. |
protected int |
parseInt(java.lang.String value)
Helper method to convert given String value to int . |
protected int |
parseInt(java.util.StringTokenizer tokenizer)
Helper method to convert given String value to int . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ObjectBuilder()
Method Detail |
---|
public ObjectBuilderFactory getFactory()
public T getObject()
protected abstract T createObject()
protected T createObject(java.lang.String className)
className
- - name of the class to instantiate object
public java.util.Map<java.lang.String,java.lang.String> getProperties()
public java.lang.String getProperty(java.lang.String name)
name
- - name of the property
public void initObjectProperties()
initObjectProperty(String, String)
is invokedinitObjectProperty(String, String)
protected void initObjectProperty(java.lang.String name, java.lang.String value)
initObjectProperties()
method. This
implementation searches for initialization method for the property and
then invokes it. If the property name is "abc", it searches for
the method "initAbc (String)". Override this method if you want to
change this behavior.
name
- - name of the initialized propertyvalue
- - value of the property
java.lang.RuntimeException
- if there is no initialization method for requested property
foundprotected void initId(java.lang.String value)
value
- - id to setpublic java.lang.String getId()
id
of this builder.
protected void initClass(java.lang.String value)
public ObjectBuilder<?> getParent()
protected void addChild(ObjectBuilder<?> builder)
ObjectBuilderFactory
when adding child to this
builder. In this implementation does nothing.
builder
- - child to addpublic java.util.List<ObjectBuilder<?>> getChildren()
protected boolean parseBoolean(java.lang.String value)
boolean
.
value
- - String value to be converted; if it is null, returns false
protected int parseInt(java.lang.String value)
int
.
value
- - String value to be converted
java.lang.RuntimeException
- if given value cannot be converted to intprotected int parseInt(java.util.StringTokenizer tokenizer)
int
.
tokenizer
- - supplier of the converted String
java.lang.RuntimeException
- if next token cannot be converted to intprotected double parseDouble(java.lang.String value)
double
.
value
- - String value to be converted
java.lang.RuntimeException
- if given value cannot be converted to doubleprotected java.lang.Object parseConstant(java.lang.String name, java.lang.Class<?> owner)
name
- - name of the constantowner
- - class in which is the constant with given name
java.lang.RuntimeException
- if cannot find constant with given nameprotected java.lang.Class<?> parseClass(java.lang.String value)
value
- - name of the class
java.lang.RuntimeException
- if cannot find class with given nameprotected java.lang.Object parseInstance(java.lang.String value)
value
- - name for object lookup
protected java.lang.Object parseInstance(java.lang.String value, java.lang.Class<?> instanceOf)
parseInstance(String)
to get requested object and then checks if
returned object is instance of given class.
value
- - name for object lookupinstanceOf
- - class that is accessible from returned object
java.lang.RuntimeException
- if found object is not an instance of given classprotected java.lang.Object parseConstructor(java.lang.String value, java.lang.String defaultPackage)
defaultPackage
to get qualified class name. Arguments must
be enclosed by parentheses. Possible values are:
value
- - string to create objectdefaultPackage
- - name of a package if value
does not contain
qualified class name
java.lang.RuntimeException
- if cannot create new object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |