Class AbstractConverter

java.lang.Object
java.beans.PropertyEditorSupport
org.apache.xbean.propertyeditor.AbstractConverter
All Implemented Interfaces:
PropertyEditor, Converter
Direct Known Subclasses:
AbstractCollectionConverter, AbstractMapConverter, BigDecimalEditor, BigIntegerEditor, BooleanEditor, ByteEditor, CharacterEditor, ClassEditor, ConstructorConverter, DateEditor, DoubleEditor, EnumConverter, FileEditor, FloatEditor, Inet4AddressEditor, Inet6AddressEditor, InetAddressEditor, IntegerEditor, JndiConverter, LoggerConverter, LongEditor, ObjectNameEditor, PatternConverter, PropertyEditorConverter, ShortEditor, StaticFactoryConverter, StringEditor, URIEditor, URLEditor

public abstract class AbstractConverter extends PropertyEditorSupport implements Converter
A base class for converters. This class handles all converter methods, and redirects all conversion requests to toStringImpl and toObjectImpl. These methods can assume that the supplied value or text is never null, and that type checking has been applied to the value.
Version:
$Rev: 6680 $
  • Field Details

    • type

      private final Class type
    • trim

      private final boolean trim
  • Constructor Details

    • AbstractConverter

      protected AbstractConverter(Class type)
      Creates an abstract converter for the specified type.
      Parameters:
      type - type of the property editor
    • AbstractConverter

      protected AbstractConverter(Class type, boolean trim)
  • Method Details

    • getType

      public final Class getType()
      Description copied from interface: Converter
      Gets the the type of object supported by this converter.
      Specified by:
      getType in interface Converter
      Returns:
      the type used for that converter.
    • getAsText

      public final String getAsText()
      Specified by:
      getAsText in interface PropertyEditor
      Overrides:
      getAsText in class PropertyEditorSupport
    • setAsText

      public final void setAsText(String text)
      Specified by:
      setAsText in interface PropertyEditor
      Overrides:
      setAsText in class PropertyEditorSupport
    • getValue

      public final Object getValue()
      Specified by:
      getValue in interface PropertyEditor
      Overrides:
      getValue in class PropertyEditorSupport
    • setValue

      public final void setValue(Object value)
      Specified by:
      setValue in interface PropertyEditor
      Overrides:
      setValue in class PropertyEditorSupport
    • toString

      public final String toString(Object value)
      Description copied from interface: Converter
      Converts the supplied object to text. If value is null, null will be returned. If value is not an instance of the this converter's type, a PropertyEditorException will be thrown.
      Specified by:
      toString in interface Converter
      Parameters:
      value - an instance of the editor type
      Returns:
      the text equivalent of the value
    • toObject

      public final Object toObject(String text)
      Description copied from interface: Converter
      Converts the supplied text in to an instance of the editor type. If text is null, null will be returned.
      Specified by:
      toObject in interface Converter
      Parameters:
      text - the text to convert
      Returns:
      an instance of the editor type
    • toStringImpl

      protected String toStringImpl(Object value)
      Converts the supplied object to text. The supplied object will always be an instance of the editor type, and specifically will never be null or a String (unless this is the String editor).
      Parameters:
      value - an instance of the editor type
      Returns:
      the text equivalent of the value
    • toObjectImpl

      protected abstract Object toObjectImpl(String text)
      Converts the supplied text in to an instance of the editor type. The text will never be null, and trim() will already have been called.
      Parameters:
      text - the text to convert
      Returns:
      an instance of the editor type