Runtime components : Core components : Typed data : Concepts : Converters
  
Converters
Converters transform business objects to Strings (formatting) and Strings to business objects (unformatting). The difference between converters and formatters is that converters only format or unformat a given object (a typed data) that does not have to be in the context while formatters format, unformat, and apply decorators to a set of objects located in different contexts.
One responsibility of a property descriptor is to identify the converters for the business object. The converters belong to following categories:
Default - The toolkit typically uses converters in this category to convert data between data elements and GUI presentation components (HTML or Java) and the result is readable by humans. This category of converter formats and unformats data without losing information and defines how to handle null values.
Note Default category converters return null when unformatting an empty String except when unformatting the String type, in which case it returns an empty String.
Serialization - The toolkit typically uses converters in this category to serialize data for client/server messaging and the result is not necessarily readable by humans. This category of converter formats and unformats data without losing information and defines how to handle null values.
Output - The toolkit uses converters in this category to convert data into a special non-reversible format for presentation only. Information may be lost in the conversion. For example, an output category converter may round a number to the nearest 1000.
XML - The toolkit uses converters in this category to render an object as an XML output stream.
Host - The toolkit uses converters in this category to convert data into a format understood by a legacy host. The host determines the rules used to do the conversion.
Each type in the toolkit must support a default category converter because its validator uses it to validate typed data. The other converter categories are optional. A single instance of a converter may support more than one category of conversion, and if coded appropriately, can support all categories. The toolkit allows you to add categories if needed.
Converters use attributes (such as pattern) to perform the formatting and unformatting of an object. You can define the attributes using parameters (defined as key-value pairs) within the converter definition or you can define them in the owning property descriptor. The converter first looks for the required parameters in the property descriptor before looking in its own Hashtable for the required parameters.
See
Converters implementation
See also
Concepts
Converters implementation
The hierarchy of converter classes mirrors the hierarchy of property descriptor classes. In the same way that AbstractPropertyDescriptor is the parent for all property descriptors, AbstractConverter is the parent for all property descriptors and implements the Conversion interface. Converters for simple types inherit directly from this abstract super class in a similar way that simple property descriptor classes inherit directly from AbstractPropertyDescriptor. The toolkit provides converters for basic types such as String, Integer, and Float (StringConverter, IntegerConverter, and FloatConverter). These classes are sample implementations of converters for simple types. Depending on application requirements, you may need to extend them or replace them with another implementation.
Converters for compound business objects extending DataCollection (that is, from either KeyedCollection or IndexedCollection) should extend the KCollConverter and IcollConverter provided by the toolkit. These classes extend AbstractConverter. The following diagram shows the relationships between the classes in the converter hierarchy:
This graphic is described in the surrounding text.
See also
Converters