org.jdesktop.binding.metadata
Interface Converter

All Known Implementing Classes:
Converters.DateConverter

public interface Converter

Interface for defining objects which perform bi-directional conversion between string values and Java objects. A unified conversion interface is required for serializing and de-serializing data values to and from a textual representation, which is a common requirement when interacting with a network or web-based data source.

For many Java classes (Date, Color, etc), an instance may be represented in a variety of string formats, hence both conversion methods take an optional format parameter for specifying an unambiguous string format to use during conversion. A Converter class must document the format classes it supports and must also accept a null value for the format parameter, in which case a suitable and well-documented default should be used. Converters should support standard formats whenever possible.

Version:
1.0
Author:
Amy Fowler
See Also:
Converters.get(java.lang.Class)

Method Summary
 java.lang.Object decode(java.lang.String value, java.lang.Object format)
          Converts the specified String value to an object that is an instance of the class associated with this converter instance.
 java.lang.String encode(java.lang.Object value, java.lang.Object format)
          Converts the specified Object value to a string representation.
 

Method Detail

encode

java.lang.String encode(java.lang.Object value,
                        java.lang.Object format)
                        throws ConversionException
Converts the specified Object value to a string representation. The value must be an instance of the class associated with this converter, else an exception will be thrown.

Parameters:
value - the object to be converted
format - object containing string format information, or null if format information is either not relevant or unspecified
Returns:
String containing the converted string representation of the value
Throws:
ConversionException - if the conversion could not be performed

decode

java.lang.Object decode(java.lang.String value,
                        java.lang.Object format)
                        throws ConversionException
Converts the specified String value to an object that is an instance of the class associated with this converter instance.

Parameters:
value - String object to be converted
format - object containing string format information, or null if format information is either not relevant or unspecified
Returns:
Object which contains the converted value as an instance of the class associated with this converter
Throws:
ConversionException - if the conversion could not be performed


Copyright © 2005 Sun Microsystems All Rights Reserved.