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
BeanBuilderinterface that is able to process bean definitions defined in a Apache Commons Jelly script.This class prepares a
JellyContextobject 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 protectedJellyBeanBuilder()Creates a new instance ofJellyBeanBuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanBuilderResultbuild(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider)Executes a script with bean definitions.BeanBuilderResultbuild(Locator script, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp)Executes a script with bean definitions and the specified helper objects.protected DIBuilderDatacreateBuilderData(org.apache.commons.jelly.JellyContext context, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp)Creates theDIBuilderDataobject used during the builder operation.protected org.apache.commons.jelly.JellyContextcreateJellyContext()Creates the Jelly context for executing the builder script.protected DependencyProvidercreateReleaseDependencyProvider(BeanBuilderResult result)Creates aDependencyProviderobject that can be used during arelease()operation.protected BeanBuilderResultexecuteScript(Locator script, org.apache.commons.jelly.JellyContext context, MutableBeanStore rootStore, ClassLoaderProvider loaderProvider, InvocationHelper invHlp)Executes the specified script on the given Jelly context.protected ClassLoaderProviderfetchClassLoaderProvider(ClassLoaderProvider clp)Returns aClassLoaderProvider.StringgetDiBuilderNameSpaceURI()Returns the name space URI, under which the DI tag library must be registered.protected InputSourceprepareInputSource(Locator script)Prepares anInputSourceobject for the specifiedLocator.protected voidregisterTagLibraries(org.apache.commons.jelly.JellyContext context)Registers the required builder tag libraries at the given context.voidrelease(BeanBuilderResult builderResult)Releases the specifiedBeanBuilderResultobject.voidsetDiBuilderNameSpaceURI(String diBuilderNameSpaceURI)Sets the name space URI for the DI tag library.protected org.apache.commons.jelly.JellyContextsetUpJellyContext()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:
buildin interfaceBeanBuilder- Parameters:
script- points to the script to be executed (must not be null)rootStore- the rootBeanStoreobject; 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
BeanStoreinstances 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 theInvocationHelpercan be useful if the script defines special beans which require custom data type converters. These converters can be configured in theConversionHelperinstance 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:
buildin interfaceBeanBuilder- Parameters:
script- points to the script to be executed (must not be null)rootStore- the rootBeanStoreobject; 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
BeanStoreinstances created or populated during the builder operation - Throws:
BuilderException- if an error occurs
-
release
public void release(BeanBuilderResult builderResult)
Releases the specifiedBeanBuilderResultobject. This will especially invoke theshutdown()method on all bean providers stored in one of theBeanContextobjects contained in the result object.- Specified by:
releasein interfaceBeanBuilder- Parameters:
builderResult- theBeanBuilderResultobject 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 theDIBuilderDataobject 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
DIBuilderDataobject
-
prepareInputSource
protected InputSource prepareInputSource(Locator script) throws IOException
Prepares anInputSourceobject for the specifiedLocator. This method is called byexecuteScript(). The resultingInputSourceis then passed to Jelly for processing the represented script. Note that the way Jelly deals with URLs is not compatible withLocatorimplementations 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 theInputSourcefrom the stream theLocatorprovides. 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- theLocatorpointing the the Jelly script- Returns:
- an
InputSourcefor 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 validClassLoaderProviderreference. If the passed inClassLoaderProviderobject is defined, it is directly returned. Otherwise a defaultClassLoaderProvideris created, which does not has any registered class loaders.- Parameters:
clp- the inputClassLoaderProvider- Returns:
- the
ClassLoaderProviderto be used
-
createReleaseDependencyProvider
protected DependencyProvider createReleaseDependencyProvider(BeanBuilderResult result)
Creates aDependencyProviderobject 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- theBeanBuilderResultobject that is to be released- Returns:
- the
DependencyProviderfor release operations - Throws:
IllegalArgumentException- if helper objects required for the dependency provider are undefined
-
-