Class AbstractBeanTag

  • All Implemented Interfaces:
    org.apache.commons.jelly.Tag
    Direct Known Subclasses:
    BeanTag, CollectionTag, ContextBeanTag, MapTag

    public abstract class AbstractBeanTag
    extends org.apache.commons.jelly.TagSupport

    An abstract base class for tag handler implementations that create bean providers.

    This class provides some common functionality related to the creation and management of BeanProvider objects. The features implemented here include the following:

    • A store attribute is implemented for selecting the bean store, in which to store the provider created by this tag. Alternatively the tag can be nested inside a BeanStoreTag.
    • Functionality is provided for passing a bean provider to a bean store. Both standard and anonymous bean providers can be stored.
    • A framework of methods is defined that are called during the execution of the tag. While most of these methods are fully functional, derived classes can override some for adding specific functionality.
    • An abstract createBeanProvider() method is declared. Here concrete subclasses have to implement the creation of their bean provider.

    Version:
    $Id: AbstractBeanTag.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Field Summary

      • Fields inherited from class org.apache.commons.jelly.TagSupport

        body, context, hasTrimmed, parent, shouldTrim
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractBeanTag()  
    • Constructor Detail

      • AbstractBeanTag

        public AbstractBeanTag()
    • 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.
        Returns:
        the name of the bean definition
      • getStore

        public String getStore()
        Returns the name of the BeanStore, in which to place the managed bean definition.
        Returns:
        the name of the bean store
      • setStore

        public void setStore​(String store)
        Set method of the store attribute.
        Parameters:
        store - the attribute's value
      • getBeanStoreTag

        public BeanStoreTag getBeanStoreTag()
        Returns a reference to the enclosing BeanStoreTag. This can be null if there is no such tag.
        Returns:
        a reference to the enclosing bean store tag
      • getTargetDependency

        public DependencyTag getTargetDependency()
        Returns the target dependency. If this is a valid anonymous bean declaration, there is a target dependency tag, on which to set the reference to the declared bean.
        Returns:
        the target dependency tag
      • isAnonymous

        public boolean isAnonymous()
        Returns a flag whether this tag declares an anonymous bean. This is a bean without a name that is only visible in the context it is declared.
        Returns:
        a flag if this is an anonymous bean
      • doTag

        public void doTag​(org.apache.commons.jelly.XMLOutput output)
                   throws org.apache.commons.jelly.JellyTagException
        The main method of this tag. Delegates to the specific processing methods.
        Parameters:
        output - the output object
        Throws:
        org.apache.commons.jelly.JellyTagException - if an error occurs or the tag is incorrectly used
      • setBeanStoreTag

        protected void setBeanStoreTag​(BeanStoreTag beanStoreTag)
        Sets the reference to the enclosing BeanStoreTag. This can be null if this tag is not placed in the body of a bean store tag.
        Parameters:
        beanStoreTag - the enclosing BeanStoreTag
      • processBeforeBody

        protected void processBeforeBody()
                                  throws org.apache.commons.jelly.JellyTagException
        Performs pre-processing before the body of this tag is evaluated. This method is called by the doTag() method. It checks whether this tag is nested inside a DependencyTag, which will become the target dependency, i.e. if this is an anonymous bean declaration, the target dependency will be initialized to point to this bean.
        Throws:
        org.apache.commons.jelly.JellyTagException - if no name is defined for this tag, but no target dependency can be obtained or the target dependency is already initialized
      • process

        protected void process()
                        throws org.apache.commons.jelly.JellyTagException
        Processes this tag after its body has been evaluated. Creates the bean provider and adds it to the correct bean store.
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is incorrectly used
      • store

        protected void store​(BeanProvider provider)
                      throws org.apache.commons.jelly.JellyTagException
        Stores the newly created BeanProvider in the correct bean store. This method is called by process() when a provider could be successfully created.
        Parameters:
        provider - the newly created bean provider
        Throws:
        org.apache.commons.jelly.JellyTagException - if an error occurs
      • createBeanProvider

        protected abstract 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.
        Returns:
        the bean provider defined by this tag
        Throws:
        org.apache.commons.jelly.JellyTagException - in case of an error