Class 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 the ConstantValueTag. 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 specific BeanContext. 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 ConstantValueTag to expose a constant member field of a class as bean. The const tag is used to obtain the value of a constant field and store it in the Jelly context; from there it is picked up by the contextBean tag and added to the current BeanContext:

     <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 Detail

      • ContextBeanTag

        public ContextBeanTag()
    • Method Detail

      • getName

        public String getName()
        Returns the name of the managed bean definition. This name is used when the BeanProvider created by this tag is stored in a BeanStore. 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:
        getName in class AbstractBeanTag
        Returns:
        the name of the bean definition
      • setName

        public void setName​(String name)
        Set method of the name attribute.
        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 the var attribute.
        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 by process(). A concrete subclass has to implement it and return a BeanProvider, which will be stored in the selected bean store. This implementation looks up the configured variable in the Jelly context and creates a ConstantBeanProvider with it.
        Specified by:
        createBeanProvider in class AbstractBeanTag
        Returns:
        the bean provider defined by this tag
        Throws:
        org.apache.commons.jelly.JellyTagException - in case of an error