public class JellyBuilder extends JellyBeanBuilder implements Builder
An implementation of the Builder
interface that uses Commons Jelly for processing build
scripts and creating GUI components.
This builder implementation will interpret Jelly build scripts that contain tags for creating bean definitions, form components, actions, and windows. To fulfill its purpose the builder object must be initialized with a couple of manager and factory interfaces, which will perform the real create operations for elements that comprise the generated GUI. Usually a client won't have to deal with these initialization stuff; instead this is handled by the dependency injection framework.
Implementation note: This class is not thread-safe. The intended usage is that a new instance is created for each new builder operator.
Modifier and Type | Field and Description |
---|---|
static String |
NSURI_ACTION_BUILDER
Constant for the default name space URI for the action builder tag
library.
|
static String |
NSURI_COMPONENT_BUILDER
Constant for the default name space URI for the component builder tag
library.
|
static String |
NSURI_WINDOW_BUILDER
Constant for the default namespace URI for the window builder tag
library.
|
Constructor and Description |
---|
JellyBuilder()
Creates a new instance of
JellyBuilder . |
Modifier and Type | Method and Description |
---|---|
void |
addDefaultBaseClassConverter(org.apache.commons.beanutils.Converter converter,
Class<?> targetClass)
Adds a new default base class converter to this builder.
|
void |
addDefaultBaseClassConverters(Map<Class<?>,? extends org.apache.commons.beanutils.Converter> converters)
Adds all converters in the specified map as default base class converters
to this object.
|
void |
addDefaultBaseClassConverters(Map<String,? extends org.apache.commons.beanutils.Converter> converters,
ClassLoaderProvider clp)
Adds all converters in the specified map as default base class converters
to this object using the specified
ClassLoaderProvider to resolve
class names. |
void |
addDefaultConverter(org.apache.commons.beanutils.Converter converter,
Class<?> targetClass)
Adds a new default converter to this builder.
|
void |
addDefaultConverters(Map<Class<?>,? extends org.apache.commons.beanutils.Converter> converters)
Adds all converters in the specified map as default converters to this
object.
|
void |
build(Locator script,
BuilderData data)
A generic build method for executing a builder script.
|
void |
buildContainer(Locator script,
BuilderData data,
Object container)
A convenience method for building the content of a container object.
|
Window |
buildWindow(Locator script,
BuilderData data)
A convenience method for building windows.
|
protected void |
checkState()
Checks the state of this builder.
|
void |
clearDefaultBaseClassConverters()
Removes all base class converters that have been added to this object
before.
|
void |
clearDefaultConverters()
Removes all default converters that have been added to this object so
far.
|
protected ActionBuilder |
createActionBuilderData(BuilderData data)
Creates the action builder data object for the current builder process.
|
protected ComponentBuilderData |
createComponentBuilderData(BuilderData data,
Object rootContainer)
Creates the component builder data object for the current builder
process.
|
protected WindowBuilderData |
createWindowBuilderData(BuilderData data)
Creates the window builder data object for the current builder process.
|
protected void |
fetchResults(org.apache.commons.jelly.JellyContext context,
BuilderData data,
BeanBuilderResult result,
Locator script)
Fetches all result variables from the context and stores them in the
builder parameter object.
|
String |
getActionBuilderNamespace()
Returns the name space used for the action builder tag library.
|
ActionManager |
getActionManager()
Returns the action manager used by this builder.
|
String |
getComponentBuilderNamespace()
Returns the name space used for the component builder tag library.
|
ComponentManager |
getComponentManager()
Returns the component manager used by this builder.
|
Map<Class<?>,org.apache.commons.beanutils.Converter> |
getDefaultBaseClassConverters()
Returns a map with the default base class converters that have been
registered so far.
|
Map<Class<?>,org.apache.commons.beanutils.Converter> |
getDefaultConverters()
Returns a map with the default converters that have been registered so
far.
|
FieldHandlerFactory |
getFieldHandlerFactory()
Returns the field handler factory used by this builder.
|
String |
getName()
Returns the name of this builder.
|
String |
getWindowBuilderNamespace()
Returns the name space used for the window builder tag library.
|
WindowManager |
getWindowManager()
Returns the window manager used by this builder.
|
protected MutableBeanStore |
initBuilderBeanContext(BuilderData data,
org.apache.commons.jelly.JellyContext context,
InvocationHelper invHlp)
Creates the root bean store for the current builder operation and
initializes the
BeanContext to be used. |
protected InvocationHelper |
initInvocationHelper(BuilderData data)
Initializes the
InvocationHelper to be used during the builder
operation. |
protected void |
performBuild(Locator script,
BuilderData data,
Object rootContainer)
The main method for executing a builder script.
|
protected void |
registerBeanCreationListeners(BeanContext context,
BuilderData data)
Registers the
BeanCreationListener objects defined by the
BuilderData object at the specified BeanContext . |
void |
registerDefaultConverters(ConversionHelper conHlp)
Registers default converters at the specified
ConversionHelper
instance. |
protected void |
registerExtendedTagLibraries(org.apache.commons.jelly.JellyContext context,
BuilderData data)
Registers the builder tag libraries at the given context.
|
void |
release(BuilderData data)
Frees all resources associated with the specified
BuilderData
object. |
void |
setActionBuilderNamespace(String actionBuilderNamespace)
Sets the name space used for the action builder tag library.
|
void |
setActionManager(ActionManager actionManager)
Sets the action manager to be used by this builder.
|
void |
setComponentBuilderNamespace(String componentBuilderNamespace)
Sets the name space used for the component builder tag library.
|
void |
setComponentManager(ComponentManager componentManager)
Sets the component manager to be used by this builder.
|
void |
setFieldHandlerFactory(FieldHandlerFactory fieldHandlerFactory)
Sets the field handler factory to be used by this builder.
|
void |
setName(String name)
Sets the name of this builder.
|
protected org.apache.commons.jelly.JellyContext |
setUpExtendedJellyContext(BuilderData data,
Object rootContainer)
Creates and initializes the Jelly context to be used for executing the
builder script.
|
void |
setWindowBuilderNamespace(String windowBuilderNamespace)
Sets the name space used for the window builder tag library.
|
void |
setWindowManager(WindowManager windowManager)
Sets the window manager to be used by this builder.
|
build, build, createBuilderData, createJellyContext, createReleaseDependencyProvider, executeScript, fetchClassLoaderProvider, getDiBuilderNameSpaceURI, prepareInputSource, registerTagLibraries, release, setDiBuilderNameSpaceURI, setUpJellyContext
public static final String NSURI_COMPONENT_BUILDER
public static final String NSURI_ACTION_BUILDER
public static final String NSURI_WINDOW_BUILDER
public String getName()
public void setName(String name)
name
- the builder's namepublic String getActionBuilderNamespace()
public void setActionBuilderNamespace(String actionBuilderNamespace)
actionBuilderNamespace
- the new name space URIpublic String getComponentBuilderNamespace()
public void setComponentBuilderNamespace(String componentBuilderNamespace)
componentBuilderNamespace
- the new name spacepublic String getWindowBuilderNamespace()
public void setWindowBuilderNamespace(String windowBuilderNamespace)
windowBuilderNamespace
- the new name spacepublic ActionManager getActionManager()
public void setActionManager(ActionManager actionManager)
actionManager
- the action managerpublic ComponentManager getComponentManager()
public void setComponentManager(ComponentManager componentManager)
componentManager
- the component managerpublic FieldHandlerFactory getFieldHandlerFactory()
public void setFieldHandlerFactory(FieldHandlerFactory fieldHandlerFactory)
fieldHandlerFactory
- the field handler factorypublic WindowManager getWindowManager()
public void setWindowManager(WindowManager windowManager)
windowManager
- the window managerpublic Map<Class<?>,org.apache.commons.beanutils.Converter> getDefaultConverters()
addDefaultConverter(Converter, Class)
public void addDefaultConverter(org.apache.commons.beanutils.Converter converter, Class<?> targetClass)
ConversionHelper
object has to be created, these default
converters are automatically registered at the helper object. Normally
client code does not have to call this method manually. This is done when
this builder instance is created (per default the dependency injection
framework is used to create new builder instances; when this happens the
default converters are automatically initialized).converter
- the converter to be added (must not be null)targetClass
- the target class of the conversion (must not be
null)IllegalArgumentException
- if a required parameter is missingConversionHelper.registerConverter(Converter, Class)
public void addDefaultConverters(Map<Class<?>,? extends org.apache.commons.beanutils.Converter> converters)
addDefaultConverter(Converter, Class)
for
each entry in the map.converters
- the map with the converters to be added (must not be
nullIllegalArgumentException
- if the map is null or contains
null entriespublic void clearDefaultConverters()
public Map<Class<?>,org.apache.commons.beanutils.Converter> getDefaultBaseClassConverters()
addDefaultConverter(Converter, Class)
public void addDefaultBaseClassConverter(org.apache.commons.beanutils.Converter converter, Class<?> targetClass)
addDefaultConverter(Converter, Class)
, but
the Converter
passed to this method is registered as a base class
converter at the ConversionHelper
object created for a new
builder operation.converter
- the converter to be added (must not be null)targetClass
- the target class of the conversion (must not be
null)IllegalArgumentException
- if a required parameter is missingConversionHelper.registerBaseClassConverter(Converter, Class)
public void addDefaultBaseClassConverters(Map<Class<?>,? extends org.apache.commons.beanutils.Converter> converters)
addDefaultBaseClassConverter(Converter, Class)
for each entry in
the map.converters
- the map with the converters to be added (must not be
nullIllegalArgumentException
- if the map is null or contains
null entriespublic void addDefaultBaseClassConverters(Map<String,? extends org.apache.commons.beanutils.Converter> converters, ClassLoaderProvider clp)
ClassLoaderProvider
to resolve
class names. This method works like the method with the same name, but
converter class are specified by name and resolved dynamically.converters
- the map with the converters to be added (must not be
nullclp
- the ClassLoaderProvider
(must not be null)IllegalArgumentException
- if the map is null or contains
null entries or the ClassLoaderProvider
is
nullpublic void clearDefaultBaseClassConverters()
public void registerDefaultConverters(ConversionHelper conHlp)
ConversionHelper
instance. These are the converters added using the
addDefaultConverter(Converter, Class)
or
addDefaultBaseClassConverter(Converter, Class)
methods. If the
BuilderData
object passed to the build()
methods does not
contain an InvocationHelper
instance, a new instance is
automatically created, and the default converters are registered at the
associated ConversionHelper
instance. However, if a custom
InvocationHelper
is set, this registration is not done - the
helper object is used as is. Using this method the default converters can
be registered manually. Clients of the builder that need their own
InvocationHelper
can decide whether they call this method so that
enhanced type conversion facilities are supported or not.conHlp
- the ConversionHelper
to be initialized (must not be
null)IllegalArgumentException
- if the ConversionHelper
is
nullpublic void build(Locator script, BuilderData data) throws BuilderException
build
in interface Builder
script
- specifies the script to be executeddata
- the parameter objectBuilderException
- if an error occurspublic Window buildWindow(Locator script, BuilderData data) throws BuilderException
buildWindow
in interface Builder
script
- specifies the script to be executeddata
- the parameter objectBuilderException
- if an error occurspublic void buildContainer(Locator script, BuilderData data, Object container) throws BuilderException
buildContainer
in interface Builder
script
- specifies the script to be executeddata
- the parameter objectcontainer
- the root containerBuilderException
- if an error occurspublic void release(BuilderData data)
BuilderData
object. The BuilderData
object passed to this method must have
been initialized by this builder. Especially the BeanContext
and
the BeanBuilderResult
properties must have been set. Otherwise an
exception is thrown.release
in interface Builder
data
- the BuilderData
objectIllegalArgumentException
- if the data object is null or is
not fully initializedprotected void performBuild(Locator script, BuilderData data, Object rootContainer) throws BuilderException
build()
methods. It executes the specified script
with a newly initialized context and collects all results afterwards.script
- specifies the build scriptdata
- the builder parameter objectrootContainer
- the root container objectBuilderException
- if an error occursprotected org.apache.commons.jelly.JellyContext setUpExtendedJellyContext(BuilderData data, Object rootContainer)
data
- the builder parametersrootContainer
- the root container for the builder processprotected ComponentBuilderData createComponentBuilderData(BuilderData data, Object rootContainer)
ComponentBuilderData
bean from the parent bean context. If such a bean
cannot be found, a default bean is created.data
- the builder parametersrootContainer
- the root containerprotected InvocationHelper initInvocationHelper(BuilderData data)
InvocationHelper
to be used during the builder
operation. This method is called before the builder script gets executed.
If an InvocationHelper
instance is provided in the specified
BuilderData
object, it is directly returned. Otherwise, a new
instance is created with a specialized ConversionHelper
whose
parent is obtained from the parent bean store. That way all converters
registered for the parent bean store are also available in the current
builder script.data
- the builder parametersInvocationHelper
to useprotected MutableBeanStore initBuilderBeanContext(BuilderData data, org.apache.commons.jelly.JellyContext context, InvocationHelper invHlp)
BeanContext
to be used. In this bean store
the bean definitions defined by the builder script are stored (unless a
different store is explicitly selected). A new BeanContext
is created and initialized, so that it allows access to the following
bean definitions (in this order):
ComponentBuilderData
instancedata
- the builder parameterscontext
- the Jelly contextinvHlp
- the current InvocationHelper
protected ActionBuilder createActionBuilderData(BuilderData data)
ActionBuilder
bean
from the parent bean context. If such a bean cannot be found, a new
default instance is created.data
- the builder parametersprotected WindowBuilderData createWindowBuilderData(BuilderData data)
WindowBuilderData
bean
can be obtained from the parent bean context. If such a bean cannot be
found, a new default instance is created.data
- the builder parametersprotected void registerExtendedTagLibraries(org.apache.commons.jelly.JellyContext context, BuilderData data)
setUpExtendedJellyContext()
before the builder
script will be executed. "Extended" in this context means that all tag
libraries for the more complex builders are registered.context
- the contextdata
- the builder parametersprotected void checkState()
IllegalStateException
- if initialization of this instance is
incompleteprotected void fetchResults(org.apache.commons.jelly.JellyContext context, BuilderData data, BeanBuilderResult result, Locator script) throws BuilderException
context
- the context objectdata
- the parameter objectresult
- the result object from the bean builderscript
- the locator to the current build scriptBuilderException
- if an error occursprotected void registerBeanCreationListeners(BeanContext context, BuilderData data)
BeanCreationListener
objects defined by the
BuilderData
object at the specified BeanContext
. This
method is called by
initBuilderBeanContext(BuilderData, JellyContext, InvocationHelper)
with the newly created BeanContext
as parameter. If the
BuilderData
object contains bean creation listeners, these
listeners have to be added to the context. (Note: this method is called
in any case, even if the collection with creation listeners is
null or empty.)context
- the BeanContext
used by the builderdata
- the BuilderData
objectCopyright © 2016 The JGUIraffe Team. All rights reserved.