Class ContextBeanTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- net.sf.jguiraffe.gui.builder.di.tags.AbstractBeanTag
-
- net.sf.jguiraffe.gui.builder.di.tags.ContextBeanTag
-
- All Implemented Interfaces:
org.apache.commons.jelly.Tag
public class ContextBeanTag extends AbstractBeanTag
A specialized tag for the creation of beans from objects stored in the Jelly context.
Jelly provides some native ways for creating objects and storing them in the
JellyContext. Also this tag library offers some functionality in this area, for instance theConstantValueTag. With this tag it is possible to access such objects and expose them as regular beans of the dependency injecting framework.By inheriting from
AbstractBeanTag, this tag has access to the standard functionality related to bean definitions; so it allows the creation of anonymous beans and named beans as well that are stored in a specificBeanContext. The following table lists the attributes specific to this tag:Attribute Description Optional name Defines a name for the created bean definition. Using this name the bean can be queried from an bean context. yes var Refers to a variable in the Jelly context. This variable is looked up and made available as bean in the selected BeanContext. Note that this variable must exist; otherwise, the tag fails with an exception.no Below is an example how this tag can be used together with the
ConstantValueTagto expose a constant member field of a class as bean. Theconsttag is used to obtain the value of a constant field and store it in the Jelly context; from there it is picked up by thecontextBeantag and added to the currentBeanContext:<di:const targetClassName="com.acme.MyService" field="INSTANCE" var="acme_service"/> <di:contextBean name="acmeService" var="acme_service"/>
- Since:
- 1.4
- Version:
- $Id$
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description ContextBeanTag()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BeanProvidercreateBeanProvider()Creates the bean provider defined by this tag.StringgetName()Returns the name of the managed bean definition.StringgetVar()Returns the name of the variable in the Jelly context that is to be read by this tag.voidsetName(String name)Set method of thenameattribute.voidsetVar(String var)Set method of thevarattribute.-
Methods inherited from class net.sf.jguiraffe.gui.builder.di.tags.AbstractBeanTag
doTag, getBeanStoreTag, getStore, getTargetDependency, isAnonymous, process, processBeforeBody, setBeanStoreTag, setStore, store
-
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
-
-
-
-
Method Detail
-
getName
public String getName()
Returns the name of the managed bean definition. This name is used when theBeanProvidercreated by this tag is stored in aBeanStore. In this base implementation the name is only queried to distinguish whether this is a normal or an anonymous bean definition.getName()always returns null here; if derived classes support setting a name, they must override this method. This implementation returns the name as set by an attribute of this tag. Thus named beans can be created in the usual way.- Overrides:
getNamein classAbstractBeanTag- Returns:
- the name of the bean definition
-
setName
public void setName(String name)
Set method of thenameattribute.- Parameters:
name- the name for the bean to be created
-
getVar
public String getVar()
Returns the name of the variable in the Jelly context that is to be read by this tag.- Returns:
- the name of the Jelly variable to be read
-
setVar
public void setVar(String var)
Set method of thevarattribute.- Parameters:
var- the name of the source variable
-
createBeanProvider
protected BeanProvider createBeanProvider() throws org.apache.commons.jelly.JellyTagException
Creates the bean provider defined by this tag. This method is invoked byprocess(). A concrete subclass has to implement it and return aBeanProvider, which will be stored in the selected bean store. This implementation looks up the configured variable in the Jelly context and creates aConstantBeanProviderwith it.- Specified by:
createBeanProviderin classAbstractBeanTag- Returns:
- the bean provider defined by this tag
- Throws:
org.apache.commons.jelly.JellyTagException- in case of an error
-
-