Class JellyBeanBuilder
- java.lang.Object
-
- net.sf.jguiraffe.gui.builder.impl.JellyBeanBuilder
-
- All Implemented Interfaces:
BeanBuilder
- Direct Known Subclasses:
JellyBuilder
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.- Version:
- $Id: JellyBeanBuilder.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
JellyBeanBuilder()
Creates a new instance ofJellyBeanBuilder
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 theDIBuilderData
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 aDependencyProvider
object that can be used during arelease()
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 aClassLoaderProvider
.String
getDiBuilderNameSpaceURI()
Returns the name space URI, under which the DI tag library must be registered.protected InputSource
prepareInputSource(Locator script)
Prepares anInputSource
object for the specifiedLocator
.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 specifiedBeanBuilderResult
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.
-
-
-
Method Detail
-
getDiBuilderNameSpaceURI
public String getDiBuilderNameSpaceURI()
Returns the name space URI, under which the DI tag library must be registered.- Returns:
- the name space URI for the DI tag library
-
setDiBuilderNameSpaceURI
public void setDiBuilderNameSpaceURI(String diBuilderNameSpaceURI)
Sets the name space URI for the DI tag library.- Parameters:
diBuilderNameSpaceURI
- the new name space URI
-
build
public BeanBuilderResult build(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider) throws BuilderException
Executes a script with bean definitions. This implementation just calls the otherbuild()
method passing in a nullInvocationHelper
.- Specified by:
build
in interfaceBeanBuilder
- Parameters:
script
- points to the script to be executed (must not be null)rootStore
- the rootBeanStore
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 used- Returns:
- an object providing access to the
BeanStore
instances created or populated during the builder operation - Throws:
BuilderException
- if an error occurs
-
build
public BeanBuilderResult build(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp) throws BuilderException
Executes a script with bean definitions and the specified helper objects. With this method all helper objects taking part in the builder operation can be specified. Passing theInvocationHelper
can be useful if the script defines special beans which require custom data type converters. These converters can be configured in theConversionHelper
instance contained in theInvocationHelper
. 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.- Specified by:
build
in interfaceBeanBuilder
- Parameters:
script
- points to the script to be executed (must not be null)rootStore
- the rootBeanStore
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 used- Returns:
- an object providing access to the
BeanStore
instances created or populated during the builder operation - Throws:
BuilderException
- if an error occurs
-
release
public void release(BeanBuilderResult builderResult)
Releases the specifiedBeanBuilderResult
object. This will especially invoke theshutdown()
method on all bean providers stored in one of theBeanContext
objects contained in the result object.- Specified by:
release
in interfaceBeanBuilder
- Parameters:
builderResult
- theBeanBuilderResult
object to be released- Throws:
IllegalArgumentException
- if the passed in result object is null or invalid
-
executeScript
protected BeanBuilderResult executeScript(Locator script, org.apache.commons.jelly.JellyContext context, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp) throws BuilderException
Executes the specified script on the given Jelly context. Occurring Jelly exceptions are caught and re-thrown as builder exceptions.- Parameters:
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)- Returns:
- an object with the results of the builder operation
- Throws:
BuilderException
- if an error occurs while executing the scriptIllegalArgumentException
- if the script is null
-
createBuilderData
protected DIBuilderData createBuilderData(org.apache.commons.jelly.JellyContext context, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp)
Creates theDIBuilderData
object used during the builder operation. This object holds central data required by multiple components involved in the builder operation.- Parameters:
context
- the Jelly contextrootStore
- the root bean storeloaderProvider
- the class loader providerinvHlp
- the invocation helper- Returns:
- the newly created
DIBuilderData
object
-
prepareInputSource
protected InputSource prepareInputSource(Locator script) throws IOException
Prepares anInputSource
object for the specifiedLocator
. This method is called byexecuteScript()
. The resultingInputSource
is then passed to Jelly for processing the represented script. Note that the way Jelly deals with URLs is not compatible withLocator
implementations derived fromByteArrayLocator
(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 theInputSource
from the stream theLocator
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).- Parameters:
script
- theLocator
pointing the the Jelly script- Returns:
- an
InputSource
for this script - Throws:
IOException
- if an IO error occurs
-
setUpJellyContext
protected org.apache.commons.jelly.JellyContext setUpJellyContext()
Creates and initializes the Jelly context to be used for executing the builder script. This method will also register the required tag libraries and perform other mandatory initialization steps.- Returns:
- the fully initialized context
-
createJellyContext
protected org.apache.commons.jelly.JellyContext createJellyContext()
Creates the Jelly context for executing the builder script. This method is called bysetUpJellyContext()
. Its task is only the creation of the context, not its initialization.- Returns:
- the newly created context
-
registerTagLibraries
protected void registerTagLibraries(org.apache.commons.jelly.JellyContext context)
Registers the required builder tag libraries at the given context. This method is called bysetUpJellyContext()
before the builder script will be executed.- Parameters:
context
- the context
-
fetchClassLoaderProvider
protected ClassLoaderProvider fetchClassLoaderProvider(ClassLoaderProvider clp)
Returns aClassLoaderProvider
. Some of the builder methods need aClassLoaderProvider
, but the corresponding parameter is optional. This method is called to obtain a validClassLoaderProvider
reference. If the passed inClassLoaderProvider
object is defined, it is directly returned. Otherwise a defaultClassLoaderProvider
is created, which does not has any registered class loaders.- Parameters:
clp
- the inputClassLoaderProvider
- Returns:
- the
ClassLoaderProvider
to be used
-
createReleaseDependencyProvider
protected DependencyProvider createReleaseDependencyProvider(BeanBuilderResult result)
Creates aDependencyProvider
object that can be used during arelease()
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.- Parameters:
result
- theBeanBuilderResult
object that is to be released- Returns:
- the
DependencyProvider
for release operations - Throws:
IllegalArgumentException
- if helper objects required for the dependency provider are undefined
-
-