public class JellyBeanBuilder extends Object implements BeanBuilder
An implementation of the BeanBuilder
interface that is able to
process bean definitions defined in a Apache Commons Jelly script.
This class prepares a JellyContext
object and registers the
dependency injection tag library (DITagLibrary
).
Then it invokes Jelly for evaluating the specified script.
Modifier | Constructor and Description |
---|---|
protected |
JellyBeanBuilder()
Creates a new instance of
JellyBeanBuilder . |
Modifier and Type | Method and Description |
---|---|
BeanBuilderResult |
build(Locator script,
MutableBeanStore rootStore,
ClassLoaderProvider loaderProvider)
Executes a script with bean definitions.
|
BeanBuilderResult |
build(Locator script,
MutableBeanStore rootStore,
ClassLoaderProvider loaderProvider,
InvocationHelper invHlp)
Executes a script with bean definitions and the specified helper objects.
|
protected DIBuilderData |
createBuilderData(org.apache.commons.jelly.JellyContext context,
MutableBeanStore rootStore,
ClassLoaderProvider loaderProvider,
InvocationHelper invHlp)
Creates the
DIBuilderData object used during the builder
operation. |
protected org.apache.commons.jelly.JellyContext |
createJellyContext()
Creates the Jelly context for executing the builder script.
|
protected DependencyProvider |
createReleaseDependencyProvider(BeanBuilderResult result)
Creates a
DependencyProvider object that can be used during a
release() operation. |
protected BeanBuilderResult |
executeScript(Locator script,
org.apache.commons.jelly.JellyContext context,
MutableBeanStore rootStore,
ClassLoaderProvider loaderProvider,
InvocationHelper invHlp)
Executes the specified script on the given Jelly context.
|
protected ClassLoaderProvider |
fetchClassLoaderProvider(ClassLoaderProvider clp)
Returns a
ClassLoaderProvider . |
String |
getDiBuilderNameSpaceURI()
Returns the name space URI, under which the DI tag library must be
registered.
|
protected InputSource |
prepareInputSource(Locator script)
Prepares an
InputSource object for the specified
Locator . |
protected void |
registerTagLibraries(org.apache.commons.jelly.JellyContext context)
Registers the required builder tag libraries at the given context.
|
void |
release(BeanBuilderResult builderResult)
Releases the specified
BeanBuilderResult object. |
void |
setDiBuilderNameSpaceURI(String diBuilderNameSpaceURI)
Sets the name space URI for the DI tag library.
|
protected org.apache.commons.jelly.JellyContext |
setUpJellyContext()
Creates and initializes the Jelly context to be used for executing the
builder script.
|
protected JellyBeanBuilder()
JellyBeanBuilder
. Instances
should only be created using the factory.public String getDiBuilderNameSpaceURI()
public void setDiBuilderNameSpaceURI(String diBuilderNameSpaceURI)
diBuilderNameSpaceURI
- the new name space URIpublic BeanBuilderResult build(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider) throws BuilderException
build()
method passing in a null InvocationHelper
.build
in interface BeanBuilder
script
- points to the script to be executed (must not be
null)rootStore
- the root BeanStore
object; if defined, the
processed bean definitions will be added to this store unless
otherwise specified; if null, a new bean store will be
createdloaderProvider
- an object with information about registered class
loaders; can be null, then a default class loader provider
will be usedBeanStore
instances created or populated during the builder operationBuilderException
- if an error occurspublic BeanBuilderResult build(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp) throws BuilderException
InvocationHelper
can be useful if
the script defines special beans which require custom data type
converters. These converters can be configured in the
ConversionHelper
instance
contained in the InvocationHelper
. It is possible to pass
null references for the helper objects. In this case default
objects are created. Delegates to #executeScript()
which does the real
work.build
in interface BeanBuilder
script
- points to the script to be executed (must not be
null)rootStore
- the root BeanStore
object; if defined, the
processed bean definitions will be added to this store unless
otherwise specified; if null, a new bean store will be
createdloaderProvider
- an object with information about registered class
loaders; can be null, then a default class loader provider
will be usedinvHlp
- a helper object for reflection operations; can be
null, then a default helper object will be usedBeanStore
instances created or populated during the builder operationBuilderException
- if an error occurspublic void release(BeanBuilderResult builderResult)
BeanBuilderResult
object. This will
especially invoke the shutdown()
method on all bean providers
stored in one of the BeanContext
objects contained in the result
object.release
in interface BeanBuilder
builderResult
- the BeanBuilderResult
object to be releasedIllegalArgumentException
- if the passed in result object is
null or invalidprotected BeanBuilderResult executeScript(Locator script, org.apache.commons.jelly.JellyContext context, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp) throws BuilderException
script
- the script to be executed (must not be null)context
- the Jelly contextrootStore
- the root bean store (can be null)loaderProvider
- a data object with the registered class loaders
(can be null)invHlp
- a helper object for reflection operations (can be
null)BuilderException
- if an error occurs while executing the scriptIllegalArgumentException
- if the script is nullprotected DIBuilderData createBuilderData(org.apache.commons.jelly.JellyContext context, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp)
DIBuilderData
object used during the builder
operation. This object holds central data required by multiple components
involved in the builder operation.context
- the Jelly contextrootStore
- the root bean storeloaderProvider
- the class loader providerinvHlp
- the invocation helperDIBuilderData
objectprotected InputSource prepareInputSource(Locator script) throws IOException
InputSource
object for the specified
Locator
. This method is called by
executeScript()
. The resulting InputSource
is
then passed to Jelly for processing the represented script. Note that the
way Jelly deals with URLs is not compatible with Locator
implementations derived from ByteArrayLocator
(in-memory
locators). This is due to the fact that the URL is first transformed into
a string and later back into a URL. This implementation tries to work
around this problem by creating the InputSource
from the
stream the Locator
provides. If the URL can be transformed
to a string and back to a URL, it is also set as the system ID of the
input source (this makes it possible to resolve relative files).script
- the Locator
pointing the the Jelly scriptInputSource
for this scriptIOException
- if an IO error occursprotected org.apache.commons.jelly.JellyContext setUpJellyContext()
protected org.apache.commons.jelly.JellyContext createJellyContext()
setUpJellyContext()
. Its task is only the
creation of the context, not its initialization.protected void registerTagLibraries(org.apache.commons.jelly.JellyContext context)
setUpJellyContext()
before the builder
script will be executed.context
- the contextprotected ClassLoaderProvider fetchClassLoaderProvider(ClassLoaderProvider clp)
ClassLoaderProvider
. Some of the builder methods need a
ClassLoaderProvider
, but the corresponding parameter is optional.
This method is called to obtain a valid ClassLoaderProvider
reference. If the passed in ClassLoaderProvider
object is
defined, it is directly returned. Otherwise a default ClassLoaderProvider
is created, which does not has any registered class
loaders.clp
- the input ClassLoaderProvider
ClassLoaderProvider
to be usedprotected DependencyProvider createReleaseDependencyProvider(BeanBuilderResult result)
DependencyProvider
object that can be used during a
release()
operation. This method creates a restricted dependency
provider that can be used for executing simple shutdown scripts, but does
not support access to external beans.result
- the BeanBuilderResult
object that is to be releasedDependencyProvider
for release operationsIllegalArgumentException
- if helper objects required for the
dependency provider are undefinedCopyright © 2016 The JGUIraffe Team. All rights reserved.