ilog.cpl.util
Class IlpDefaultTypeConverter

java.lang.Object
  extended by ilog.cpl.util.IlpDefaultTypeConverter
All Implemented Interfaces:
IlpTypeConverter

public class IlpDefaultTypeConverter
extends Object
implements IlpTypeConverter

The type converter is used when parsing or writing XML.

This class is used by the default context implementation.

This implementation is able to convert the following classes:

Other classes can also be automatically converted if one of the following mechanisms is available:

This class contains a logger (IlpUtilLoggers.ilog_cpl_util_typeconverter).

Since:
JTGO 3.0
See Also:
IlpSystem.GetDefaultContext(), IlpContext.getTypeConverter(), IlpImageRepository, IlpUtilLoggers.ilog_cpl_util_typeconverter

Constructor Summary
IlpDefaultTypeConverter(IlpContext context)
          Creates a type converter.
 
Method Summary
 Object convertTo(Class type, Object value)
          General conversion method to convert a non-null value.
 Object createJavaInstance(Class type, String value)
          Creates a Java instance from a class type.
 String createStringValue(Class type, Object value)
          Creates a String value from a general Java Object.
 IlpSAXSerializable getAttributeValueHandler(Class attributeValueClass)
          Returns the way an attribute should be read from or written in XML, depending on its Java class.
 void registerEditor(Class targetType, Class editorClass)
          Registers a property editor for a given target class.
 void setAttributeValueHandler(Class attributeValueClass, IlpSAXSerializable serializableAttribute)
          Sets the way an attribute should be read from or written in XML depending on its Java class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlpDefaultTypeConverter

public IlpDefaultTypeConverter(IlpContext context)
Creates a type converter.

Parameters:
context - Service context used to access the URL access service and the image repository.
Method Detail

createJavaInstance

public Object createJavaInstance(Class type,
                                 String value)
Creates a Java instance from a class type.

The value is initialized with the supplied string value. IlEnum, dates, colors, and fonts are specifically supported. Icons are also specifically supported to add a full path to the icon name. Otherwise, all Java basic types and any Java class that has a string constructor are supported.

Specified by:
createJavaInstance in interface IlpTypeConverter
Parameters:
type - The class of the instance to be created.
value - The value to be assigned to the new instance.
Returns:
The Java instance from the given type.

createStringValue

public String createStringValue(Class type,
                                Object value)
Creates a String value from a general Java Object.

This method produces string values that can be used in an XML file. Dates, colors and fonts produce strings that are correctly formatted for use in data storage XML files. Any types that are not specifically handled return the result by calling toString() on the value.

Specified by:
createStringValue in interface IlpTypeConverter
Parameters:
type - Target type. The type may be null for general conversion. It can be set to a different value when the conversion is done, to a type that should be different from the value type. This implementation only considers this parameter when the conversion is being done from Integer to SwingConstants, or when using a PropertyEditor. Please note that the PropertyEditor implementation must be able to execute the conversion from the instance to String appropriately.
value - The instance to be converted to a string value.
Returns:
The string value associated with the Object instance.

getAttributeValueHandler

public IlpSAXSerializable getAttributeValueHandler(Class attributeValueClass)
Returns the way an attribute should be read from or written in XML, depending on its Java class.

Note that the subclasses of IlEnum are considered as not having a corresponding IlpSAXSerializable if the method setAttributeValueHandler has not been called explicitly for this class. This avoids calling Class.forName for each subclass of IlEnum.

Specified by:
getAttributeValueHandler in interface IlpTypeConverter
Parameters:
attributeValueClass - The class of the attribute to be read from or written in XML.
Returns:
The IlpSAXSerializable that contains the way the attribute should be read from or written in XML.

setAttributeValueHandler

public void setAttributeValueHandler(Class attributeValueClass,
                                     IlpSAXSerializable serializableAttribute)
Sets the way an attribute should be read from or written in XML depending on its Java class.

Parameters:
attributeValueClass - The class of the attribute to be read from or written in XML.
serializableAttribute - The IlpSAXSerializable that contains the way the attribute should be read from or written in XML.

registerEditor

public void registerEditor(Class targetType,
                           Class editorClass)
Registers a property editor for a given target class.

The property editor is used to convert the target class from an instance to a String and vice-versa, so that it can be written in XML format.

The following predefined target classes should not be modified:

Parameters:
targetType - The Class object of the type to be edited.
editorClass - The Class object of the property editor class. If this is null, then any existing editor for the given target class is removed (doing so for a predefined target class will lead to errors).
Since:
JTGO 4.0

convertTo

public Object convertTo(Class type,
                        Object value)
General conversion method to convert a non-null value.

This method is able to:

You can override this method to extend this behavior providing different types of conversions.

Specified by:
convertTo in interface IlpTypeConverter
Parameters:
type - Target class to convert.
value - The instance to be converted.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.