Class DependencyTag

  • All Implemented Interfaces:
    ValueSupport, org.apache.commons.jelly.Tag
    Direct Known Subclasses:
    ElementTag, EntryKeyTag, EntryTag, FactoryTag, InvocationTargetTag, ParameterTag, SetPropertyTag

    public abstract class DependencyTag
    extends org.apache.commons.jelly.TagSupport
    implements ValueSupport

    A base class for tag handler classes that support the definition of a dependency.

    This base class supports multiple ways of defining a dependency to another bean:

    • By specifying the name of the affected bean; this can be done using the refName attribute.
    • By specifying the class of the required bean; for this purpose the attributes refClass, refClassName, and refClassLoader are available, which gather the information needed for a ClassDescData object.
    • By specifying a constant value for the dependency; to achieve this the constant value can be set using the value attribute. Optionally the class of the value can be specified (to cause an automatic conversion). For this use case the attributes valueClass, valueClassName, and valueClassLoader are responsible, which again fill the properties of a ClassDescData.
    • If this dependency is defined in the scope of a ChainedInvocation, it is possible to create a dependency to a local variable. Use the var attribute in this case.

    The class checks whether the definition of the dependency is consistent. This means that only a single way of specifying a dependency can be used.

    Version:
    $Id: DependencyTag.java 207 2012-02-09 07:30:13Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • DependencyTag

        protected DependencyTag()
        Creates a new instance of DependencyTag.
    • Method Detail

      • getValueData

        public ValueData getValueData()
        Returns the data object with information about the tag's (constant) value.
        Returns:
        the value data object
      • getRefClassData

        public ClassDescData getRefClassData()
        Returns the class description data for the specification of a class dependency.
        Returns:
        the class description data for a class dependency
      • getRefName

        public String getRefName()
        Returns the name of the dependent bean.
        Returns:
        the name reference
      • setRefName

        public void setRefName​(String refName)
        Set method of the refName attribute.
        Parameters:
        refName - the attribute's value
      • setRefClass

        public void setRefClass​(Class<?> c)
        Set method for the refClass attribute.
        Parameters:
        c - the attribute's value
      • setRefClassName

        public void setRefClassName​(String s)
        Set method for the refClassName attribute.
        Parameters:
        s - the attribute's value
      • setRefClassLoader

        public void setRefClassLoader​(String s)
        Set method for the refClassLoader attribute.
        Parameters:
        s - the attribute's value
      • setValue

        public void setValue​(Object value)
        Set method for the value attribute.
        Specified by:
        setValue in interface ValueSupport
        Parameters:
        value - the attribute's value
      • setValueClass

        public void setValueClass​(Class<?> cls)
        Set method for the valueClass attribute.
        Parameters:
        cls - the attribute's value
      • setValueClassName

        public void setValueClassName​(String clsName)
        Set method for the valueClassName attribute.
        Parameters:
        clsName - the attribute's value
      • setValueClassLoader

        public void setValueClassLoader​(String loader)
        Set method for the valueClassLoader attribute.
        Parameters:
        loader - the attribute's value
      • getVar

        public String getVar()
        Returns the name of the local variable to be used as dependency. This way of defining a dependency is available only if the current dependency is in the scope of a chained invocation.
        Returns:
        the local variable to be used as dependency
      • setVar

        public void setVar​(String var)
        Set method of the var attribute.
        Parameters:
        var - the attribute's value
      • processDependencyDefinitions

        protected int processDependencyDefinitions()
                                            throws org.apache.commons.jelly.JellyTagException
        Evaluates the definitions of the dependency. The return value is number of found definitions (for performing a validity check). If there is exactly one definition, the dependency is created and stored by invoking setDependency(Dependency).
        Returns:
        the number of found dependency definitions
        Throws:
        org.apache.commons.jelly.JellyTagException - if the creation of the dependency causes an error
      • createDependency

        protected Dependency createDependency()
                                       throws org.apache.commons.jelly.JellyTagException
        Creates the Dependency based on the values of the attributes. This method also checks for consistency of the defined properties and throws an exception if something is strange.
        Returns:
        the Dependency defined by this tag's attributes
        Throws:
        org.apache.commons.jelly.JellyTagException - if the attributes are not consistent
      • getDependency

        protected Dependency getDependency()
                                    throws org.apache.commons.jelly.JellyTagException
        Returns the Dependency defined by this tag. If this dependency has not yet been created, createDependency() is called. Otherwise the existing Dependency object is returned.
        Returns:
        the Dependency defined by this tag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the tag is incorrectly used or an error occurred
      • setDependency

        protected void setDependency​(Dependency dep)
        Sets the internal dependency. This method is called when the tag's dependency could be successfully created. It stores the dependency in an internal field where it can be directly accessed from getDependency().
        Parameters:
        dep - the dependency to store
      • hasDependency

        protected boolean hasDependency()
        Checks whether a dependency is defined by this tag.
        Returns:
        a flag whether a dependency is defined
      • createValueDependency

        protected Dependency createValueDependency()
                                            throws org.apache.commons.jelly.JellyTagException
        Creates the dependency when a direct value is set. This method is called by processDependencyDefinitions() when a value for this tag is set. The base implementation delegates to the createValueDependency() method of the ValueData object.
        Returns:
        the dependency referring to the constant value
        Throws:
        org.apache.commons.jelly.JellyTagException - if creation of the dependency causes an error