|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ls.util.threading.ObjectBuilder
An object builder constructs java objects out of a given set of properties. To do this an instance of a concrete
object builder has to be created. Then the particular properties can be set either by calling
setXXX(...)
methods directly (which are not defined in this class but should be in subclasses of this
one) or by calling setProperties(Properties)
. The argument of that method is a Properties
object
containing the properties that should be set. After setting the properties a call to newInstance()
will
create the actual java object. You can call newInstance()
serveral times to create java objects using the
same properties.
Object builder instances can be reused by calling reset()
which deletes all previously set property values.
Constructor Summary | |
ObjectBuilder()
Constructs a new object builder instance and calls reset() to put it in a defined state. |
Method Summary | |
void |
check()
Performes a check if all set properites are correct. |
protected void |
clearPropertyError(String property)
Resets a previously set property error. |
protected abstract void |
doCheck()
This method has to be overwritten by subclasses to perform specific operations when the method check()
is called. |
protected abstract Object |
doNewInstance()
This method has to be overwritten by subclasses to perform the actual instantiation of the java object. |
protected abstract void |
doReset()
This method has to be overwritten by subclasses to perform specific operations when the method reset()
is called, e.g. resetting of subclass specific properties. |
protected boolean |
hasPropertyError()
Checks if there are errors associated with any properties. |
protected boolean |
hasPropertyError(String property)
Checks if an error was set on the given property. |
static ObjectBuilder |
newBuilderInstance(String className)
Utility method which allowed to quickly instantiate an object builder by class name. |
Object |
newInstance()
Builds a new java object according to the properties set on this object builder. |
void |
reset()
Resets all properties that are already set on this object builder. |
void |
setProperties(Properties props)
Sets all properties defined in the argument 'props' at once. |
void |
setProperties(Properties props,
String basePath)
Behaves similar to setProperties(Properties) , except that only those entries in 'props' will be
processed, whose property name starts with the given 'basePath' argument. |
void |
setProperty(String key,
Object value)
Sets a single property with the given name and value. |
protected void |
setPropertyError(String property,
String message)
Associates the given property name with the given error message. |
protected void |
setPropertyError(String property,
Throwable error)
Behaves similar to setPropertyError(String, String) except that a throwable object can be associated
with the property name instead of an error message (as string). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ObjectBuilder()
reset()
to put it in a defined state.Method Detail |
public final void setProperty(String key, Object value)
public void set[property name with first letter upper case]( [to value compatible parameter type] )
If such a method is found, it is called with the given property value as argument. Otherwise it is ignored.
key
- The name of the property.value
- The value of the property.public final void setProperties(Properties props)
setProperty(String, Object)
is called.props
- The properties that should be set on this object builder at once.public final void setProperties(Properties props, String basePath)
setProperties(Properties)
, except that only those entries in 'props' will be
processed, whose property name starts with the given 'basePath' argument.props
- The properties that should be set on this object builder at once.basePath
- substring of propertiespublic final void check() throws BuildException
BuildException
- If some properties are invalid.public final Object newInstance() throws BuildException
check()
first to make sure that all properties are valid. If not, the build process is interrupted and a
build exception is raised.BuildException
- If an error occured during the build process.public final void reset()
public static final ObjectBuilder newBuilderInstance(String className) throws BuildException
className
- The name of the object builder class, that should be instantiated.BuildException
- If the class could not be instantiated.protected abstract void doCheck() throws BuildException
check()
is called. If this method returns a build exception, the same exception will also be returned by
check()
.BuildException
- If some properties set are not valid.protected abstract Object doNewInstance() throws Throwable
newInstance()
. Every exception thrown by this method is catched by
newInstance()
, encapsulated in a build exception and thrown again (as a build exception).Throwable
- If something goes wrong during instantiation.protected abstract void doReset()
reset()
is called, e.g. resetting of subclass specific properties.protected final void setPropertyError(String property, String message)
property
- The name of the property, whose value cannot be set.message
- The error message.protected final void setPropertyError(String property, Throwable error)
setPropertyError(String, String)
except that a throwable object can be associated
with the property name instead of an error message (as string).property
- The name of the property, whose value cannot be set.error
- The throwable object.protected final void clearPropertyError(String property)
property
- The name of the property, whose error state should be reset.protected final boolean hasPropertyError(String property)
property
- The name of the property.True
, if an error is set, otherwise false
.protected final boolean hasPropertyError()
True
, if there are errors, otherwise false
.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |