Class EntryKeyTag

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

    public class EntryKeyTag
    extends DependencyTag

    A tag handler class for defining the key of an EntryTag.

    When defining maps with the dependency injection framework the MapTag together with the EntryTag are used. However if the map uses complex objects as keys, it is not directly possible to set the key value with the EntryTag (for the value this is no problem because an arbitrary dependency - including an AbstractBeanTag in the body of the EntryTag - can be defined for specifying the desired value).

    With this tag the same is possible for the key. When it gets executed the tag checks whether its parent is an EntryTag. By inheriting from DependencyTag all possibilities of defining values are supported, including the usage of complex value tags in this tag's body. The following example shows how an entry for a map can be created whose key is a list:

     <map>
       <entry value="42">
         <entryKey>
           <list elementClass="java.lang.Integer">
             <element value="10"/>
             <element value="20"/>
           </list>
         </entryKey>
       </entry>
     </map>
     
    Of course it is possible defining both the key and the value as complex objects in the body of the EntryTag. The next fragment shows the definition of an entry with a list as key and a set as value:
     <entry>
       <entryKey>
         <list elementClass="java.lang.Integer">
           <element value="10"/>
           <element value="20"/>
         </list>
       </entryKey>
       <set>
         <element value="ten"/>
         <element value="twenty"/>
       </set>
     </entry>
     

    No matter how (either directly using the value attribute or by a tag in the body), a value has to be defined for this tag, otherwise an exception will be thrown. The following table lists all attributes supported by this tag (these are the typical attributes of a DependencyTag:

    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

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

      • EntryKeyTag

        public EntryKeyTag()
    • Method Detail

      • doTag

        public void doTag​(org.apache.commons.jelly.XMLOutput output)
                   throws org.apache.commons.jelly.JellyTagException
        Executes this tag. Checks whether the parent tag is an EntryTag. If this is the case, the key value will be set based on the attributes defined for this tag.
        Parameters:
        output - the output object
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is incorrectly used or an error occurs