Class ConverterImpl

  • All Implemented Interfaces:
    PropertyConverter

    class ConverterImpl
    extends Converter
    The converter (singleton). Converts strings to objects and back. This is the entrypoint to the converter framework.
    Version:
    $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/convert/ConverterImpl.java#1 $
    See Also:
    Converter.registerConverter(Class, PropertyConverter)
    • Constructor Summary

      Constructors 
      Constructor Description
      ConverterImpl()
      Creates a Converter.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private PropertyConverter getConverterForType​(java.lang.Class pType)
      Gets the registered converter for the given type.
      java.lang.Object toObject​(java.lang.String pString, java.lang.Class pType, java.lang.String pFormat)
      Converts the string to an object of the given type, parsing after the given format.
      java.lang.String toString​(java.lang.Object pBean, java.lang.String pFormat)
      Converts the object to a string, using object.toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConverterImpl

        ConverterImpl()
        Creates a Converter.
    • Method Detail

      • getConverterForType

        private PropertyConverter getConverterForType​(java.lang.Class pType)
        Gets the registered converter for the given type.
        Parameters:
        pType - the type to convert to
        Returns:
        an instance of a PropertyConverter or null
      • toObject

        public java.lang.Object toObject​(java.lang.String pString,
                                         java.lang.Class pType,
                                         java.lang.String pFormat)
                                  throws ConversionException
        Converts the string to an object of the given type, parsing after the given format.
        Specified by:
        toObject in interface PropertyConverter
        Specified by:
        toObject in class Converter
        Parameters:
        pString - the string to convert
        pType - the type to convert to
        pFormat - the vonversion format
        Returns:
        the object created from the given string.
        Throws:
        ConversionException - if the string cannot be converted for any reason.
      • toString

        public java.lang.String toString​(java.lang.Object pBean,
                                         java.lang.String pFormat)
                                  throws ConversionException
        Converts the object to a string, using object.toString()
        Specified by:
        toString in interface PropertyConverter
        Specified by:
        toString in class Converter
        Parameters:
        pBean - the object to convert
        pFormat - the conversion format
        Returns:
        the string representation of the object, on the correct format.
        Throws:
        ConversionException - if the object cannot be converted to a string for any reason.