Class EntryTag

  • All Implemented Interfaces:
    ValueSupport, org.apache.commons.jelly.Tag

    public class EntryTag
    extends DependencyTag

    A tag handler implementation for populating a map.

    Tags of this type can be placed in the body of a MapTag. They define both the key and the value of an entry. By inheriting from DependencyTag the usual ways of defining a value are available. It is even possible to place a BeanTag in the body of this tag to create a complex value object (that way for instance a collection can be created as value). For the key there are the typical set methods for specifying the key object and optionally a class. If the key is a complex object, the EntryKeyTag class must be used in the body of this tag.

    The most simple use case is a tag defining the key and value directly as in the following fragment:

     <entry key="answer" value="42"/>
     
    Here the data defined for the key and the value is directly passed to the owning MapTag. If this tag defines key and value classes, these classes will be used for performing a type conversion if needed. It is also possible to specify the desired classes using attributes of this tag:
     <entry key="answer" value="42"
       valueClassName="java.lang.Long"/>
     
    Classes for key or value defined at the EntryTag level will override the settings of the MapTag. If the value is a complex value, it can be defined in the tag's body:
     <entry key="answers">
       <list>
         <element value="42"/>
         <element value="4711"/>
         <element value="0815"/>
       </list>
     </entry>
     
    If the key is a complex value, a nested EntryKeyTag must be used as in the following example:
     <entry>
       <entryKey>
         <list>
           <element value="answer"/>
           <element value="universe"/>
         </list>
       </entryKey>
       <list>
         <element value="42"/>
         <element value="?"/>
       </list>
     </entry>
     
    This would create a map entry which uses lists as key and value.

    The following table lists all attributes supported by this tag:

    Attribute Description Optional
    value With this attribute the value can be directly set. If the value is specified as a string constant and a value class is defined, an automatic type conversion will be performed. yes
    valueClass Here the class of the value can be specified. The tag will try to convert the value to this class if necessary. yes
    valueClassName This attribute has the same effect as valueClass, but the name of the value class is specified rather than the class object itself. yes
    valueClassLoader If the name of the value class is specified, with this attribute a class loader for resolving the class can be defined. The name specified here will be passed to the current ClassLoaderProvider for obtaining the desired class loader. yes
    refName With this attribute another bean can be referenced by its name. This bean will be resolved and become the value of this tag. yes
    refClass It is possible to refer to another bean by its class (for this purpose there should only be a single bean with this class so there are no ambiguities). The class of this bean can be specified by this attribute. yes
    refClassName This attribute has the same meaning as the refClass attribute, but the class of the bean that is referenced can be specified by its name. yes
    refClassLoader If the refClassName attribute is used for specifying the class of a bean referenced, with this attribute a class loader can be determined for resolving the class. yes
    key Sets the key of the entry directly. This is analogous to the value attribute for the key value. yes
    keyClass Here the class of the key can be specified. This is analogous to the valueClass attribute for the key. yes
    keyClassName Defines the name of the class of the key. This is analogous to the valueClassName attribute for the key. yes
    keyClassLoader Allows specifying the name of a class loader to be used for resolving the key class. This is analogous to the valueClassLoader attribute for the key. yes

    Version:
    $Id: EntryTag.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • EntryTag

        public EntryTag()
        Creates a new instance of EntryTag.
    • Method Detail

      • getKeyDependency

        public Dependency getKeyDependency()
        Returns the dependency for the key of the map entry.
        Returns:
        the dependency for the key
      • setKeyDependency

        public void setKeyDependency​(Dependency keyDependency)
        Sets the dependency for the key of the map entry. This method can be called by tags in the body of this tag to set a complex dependency for the entry's key.
        Parameters:
        keyDependency - the dependency for the key
      • getKeyData

        public ValueData getKeyData()
        Returns the data object for the value of the key.
        Returns:
        the data for the value
      • setKey

        public void setKey​(Object key)
        Sets the key of this entry. This method can be used as attribute setter or be called by tag handler classes in the body of this tag.
        Parameters:
        key - the value of the key of this entry
      • setKeyClass

        public void setKeyClass​(Class<?> cls)
        Set method for the keyClass attribute.
        Parameters:
        cls - the value of the attribute
      • setKeyClassName

        public void setKeyClassName​(String clsName)
        Set method for the keyClassName attribute.
        Parameters:
        clsName - the value of the attribute
      • setKeyClassLoader

        public void setKeyClassLoader​(String loader)
        Set method for the keyClassLoader attribute.
        Parameters:
        loader - the value of the attribute
      • doTag

        public void doTag​(org.apache.commons.jelly.XMLOutput output)
                   throws org.apache.commons.jelly.JellyTagException
        Executes this tag. This implementation checks whether this tag is in the body of a MapTag. If this is the case, the addEntry() method of the map tag will be called.
        Parameters:
        output - the output object
        Throws:
        org.apache.commons.jelly.JellyTagException - if an error occurs or the tag is incorrectly used
      • createValueDependency

        protected Dependency createValueDependency()
                                            throws org.apache.commons.jelly.JellyTagException
        Creates the dependency if a value is defined for this tag. This implementation ensures that a class description for the value specified at the map level will be used as default if none is provided for the entry level.
        Overrides:
        createValueDependency in class DependencyTag
        Returns:
        the dependency for the value
        Throws:
        org.apache.commons.jelly.JellyTagException - in case of an error