Class StaticTextDataTransformer

  • All Implemented Interfaces:
    Transformer

    public class StaticTextDataTransformer
    extends Object
    implements Transformer

    A special implementation of the Transformer interface for converting data to StaticTextData objects.

    This transformer class is useful if StaticTextTag is used to produce labels in forms which should display some data. The data is to be provided as part of the form's model. If only textual data is involved, it is pretty inconvenient to expose properties of type StaticTextData in the model bean. Rather, this class can be assigned as Transformer to the static text fields. It creates StaticTextData objects and populates them from the object passed to the transform(Object, TransformerContext) method. The following objects can be handled:

    • Objects implementing the CharSequence interface become the text of the StaticTextData object.
    • Objects of type TextIconAlignment are passed to the alignment property.
    • If the object passed to transform() is already of type StaticTextData, it is returned without changes.
    • Other objects are interpreted as icons and stored in the icon property.

    An instance defines properties for all elements of a StaticTextData object. If set, the corresponding values are written in the newly created objects. For instance, if the icon property is set and a CharSequence object is passed to transform(), the resulting object will have this icon and the text of the CharSequence. These properties can be overridden by properties in the TransformerContext. Here the following properties are supported:

    Property Description Default
    text The text to be written into the StaticTextData object. undefined
    icon The icon to be written into the StaticTextData object. undefined
    alignment The alignment for the StaticTextData object. undefined

    Version:
    $Id: StaticTextDataTransformer.java 208 2012-02-11 20:57:33Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • StaticTextDataTransformer

        public StaticTextDataTransformer()
    • Method Detail

      • getText

        public String getText()
        Returns the default text for the newly created StaticTextData objects.
        Returns:
        the default text
      • setText

        public void setText​(String text)
        Sets the default text for the newly created StaticTextData objects.
        Parameters:
        text - the default text
      • getIcon

        public Object getIcon()
        Returns the default icon for the newly created StaticTextData objects.
        Returns:
        the default icon
      • setIcon

        public void setIcon​(Object icon)
        Sets the default icon for the newly created StaticTextData objects.
        Parameters:
        icon - the default icon
      • getAlignment

        public TextIconAlignment getAlignment()
        Returns the default TextIconAlignment.
        Returns:
        the default alignment
      • setAlignment

        public void setAlignment​(TextIconAlignment alignment)
        Sets the default TextIconAlignment.
        Parameters:
        alignment - the default alignment
      • transform

        public Object transform​(Object o,
                                TransformerContext ctx)
                         throws Exception
        The main method of the Transformer interface. This method takes the object to be transformed and returns an appropriate converted representation of it. The also passed in TransformerContext object can be used to access system information that may be needed for generating the transformed representation, e.g. the actual Locale. Performs the transformation as described in the class comment.
        Specified by:
        transform in interface Transformer
        Parameters:
        o - the object to be transformed
        ctx - the TransformerContext object
        Returns:
        the transformed instance
        Throws:
        Exception - Transformers can throw arbitrary exceptions if the conversion is not possible
      • populate

        protected void populate​(StaticTextDataImpl data,
                                TransformerContext ctx)
        Fills the specified data object with default values. This method is called by transform() to write default values into the result object. It evaluates the properties in the context and the member fields of this instance.
        Parameters:
        data - the data object to be filled
        ctx - the TransformerContext
      • convertProperty

        protected void convertProperty​(Object o,
                                       StaticTextDataImpl data,
                                       TransformerContext ctx)
                                throws Exception
        Performs the transformation if the object to be converted must be set as a property of a StaticTextData object. This method is called by transform() if the passed in object is not null and not a StaticTextData object. The base implementation sets the corresponding property in the passed in data object based on the class of the object to be converted.
        Parameters:
        o - the object to be converted
        data - the data object to be filled
        ctx - the TransformerContext
        Throws:
        Exception - if an error occurs