Class ValueData


  • public class ValueData
    extends Object

    A data class for holding all information required for creating a value.

    Some tag handler classes support the creation of a constant value. Such a value is defined by the value object itself and optionally by a target class used for type conversion. This class supports all properties required for defining a value. The value is passed to the value attribute. Its target class can be specified using the valueClass, valueClassName, and valueClassLoader attributes (which gather the data supported by a ClassDescription object. There are also some helper methods for validating the passed in data and creating a constant bean provider.

    Tag handler implementations that need to support a value definition can define a member variable of this type. Then they have to define set methods for the attributes determining the value and its class and delegate to the corresponding set methods of this class.

    Implementation note: This class is not thread-safe.

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

      • ValueData

        public ValueData​(org.apache.commons.jelly.Tag owningTag)
        Creates a new instance of ValueData.
        Parameters:
        owningTag - the tag that owns this object (must not be null)
        Throws:
        IllegalArgumentException - if the reference to the owner is null
    • Method Detail

      • getOwner

        public org.apache.commons.jelly.Tag getOwner()
        Returns a reference to the owning tag.
        Returns:
        the owner
      • getValueClassData

        public ClassDescData getValueClassData()
        Returns the ClassDescData object that defines the target class of the value.
        Returns:
        the target class data of the value
      • getValue

        public Object getValue()
        Returns the value for a constant dependency.
        Returns:
        the value
      • setValue

        public void setValue​(Object value)
        Set method of the value attribute. Here the actual value can be set.
        Parameters:
        value - the attribute's value
      • setValueClass

        public void setValueClass​(Class<?> c)
        Set method for the valueClass attribute. This attribute allows defining the class of the value. When creating the value bean provider a conversion to this type will be performed.
        Parameters:
        c - the attribute's value
      • setValueClassName

        public void setValueClassName​(String s)
        Set method for the valueClassName attribute. This is analogous to setValueClass(), but the value's class can be specified by name.
        Parameters:
        s - the attribute's value
      • setValueClassLoader

        public void setValueClassLoader​(String s)
        Set method for the valueClassLoader attribute. If the value class is specified by name, with this property a class loader can be selected, which is to be used for resolving the actual value class.
        Parameters:
        s - the attribute's value
      • isValueDefined

        public boolean isValueDefined()
        Returns a flag whether the value is defined. Defined means that the setValue(Object) method has been called at least once - even if a value of null was passed. This makes it possible to set null values.
        Returns:
        a flag whether a value for this tag was specified
      • createValueProvider

        public ConstantBeanProvider createValueProvider()
                                                 throws org.apache.commons.jelly.JellyTagException
        Creates the bean provider for the specified value. If necessary, type conversion is performed.
        Returns:
        the bean provider managing the constant value specified for this tag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the target class for a conversion is ambiguous
        IllegalArgumentException - if type conversion fails
      • createValueProvider

        public ConstantBeanProvider createValueProvider​(ClassDescription defClass)
                                                 throws org.apache.commons.jelly.JellyTagException
        Creates the bean provider for the specified value using the given default class description. If a class of the value is specified using the properties of this instance, this class will be used. Otherwise the passed in class description (if defined) will be used.
        Parameters:
        defClass - the default class description
        Returns:
        the bean provider managing the constant value specified for this tag
        Throws:
        org.apache.commons.jelly.JellyTagException - if the target class for a conversion is ambiguous
        IllegalArgumentException - if type conversion fails
      • resolveClassDescData

        public static Class<?> resolveClassDescData​(org.apache.commons.jelly.JellyContext context,
                                                    ClassDescData cdata)
                                             throws org.apache.commons.jelly.JellyTagException
        Resolves the specified ClassDescData object. This method obtains an optional ClassDescription from the class data object (this may be null if the class is undefined or throw an exception if the class definition is ambiguous). Then resolveClassDescription() is invoked.
        Parameters:
        context - the Jelly context
        cdata - the class description data object
        Returns:
        the resolved class (can be null if no class is defined)
        Throws:
        org.apache.commons.jelly.JellyTagException - if the class description is invalid
      • resolveClassDescription

        public static Class<?> resolveClassDescription​(org.apache.commons.jelly.JellyContext context,
                                                       ClassDescription cd)
        Resolves the specified ClassDescription. This method obtains the ClassLoaderProvider from the DIBuilderData object found in the passed in Jelly context and uses it to obtain the target class from the class description. The passed in description can be null, then result will also be null.
        Parameters:
        context - the Jelly context
        cd - the class description to resolve (can be null)
        Returns:
        the class the class description refers to