public class IlpDefaultTypeConverter extends Object implements IlpTypeConverter
This class is used by the default context implementation.
This implementation is able to convert the following classes:
java.lang.Booleanjava.lang.Bytejava.lang.Characterjava.lang.Doublejava.lang.Floatjava.lang.Integerjava.lang.Longjava.lang.Shortjava.lang.Stringjava.awt.Colorjava.awt.Fontjava.awt.Image: the image is retrieved from the image
repository present in the current application context.java.util.Datejavax.swing.SwingConstants: using introspection to
retrieve the constant value that corresponds to the value being
converted.javax.swing.KeyStroke: converts a String
value to a KeyStroke using the syntax described in
javax.swing.KeyStroke.getKeyStroke(java.lang.String).ilog.util.IlEnumilog.cpl.graphic.IlpPointilog.cpl.graphic.IlpRectilog.cpl.graphic.views.IlpShelfItemPositionOther classes can also be automatically converted if one of the following mechanisms is available:
registerEditor(java.lang.Class, java.lang.Class).toString method. The toString method is used
to convert the instance to a String to be written in XML.
The String-based constructor is used to convert the XML
String value to an instance.This class contains a logger
(IlpUtilLoggers.ilog_cpl_util_typeconverter).
IlpSystem.GetDefaultContext(),
IlpContext.getTypeConverter(),
IlpImageRepository,
IlpUtilLoggers.ilog_cpl_util_typeconverter| Constructor and Description |
|---|
IlpDefaultTypeConverter(IlpContext context)
Creates a type converter.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public IlpDefaultTypeConverter(IlpContext context)
context - Service context used to access the
URL access service and the image repository.public Object createJavaInstance(Class type, String value)
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.
createJavaInstance in interface IlpTypeConvertertype - The class of the instance to be created.value - The value to be assigned to the new instance.public String createStringValue(Class type, Object value)
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.
createStringValue in interface IlpTypeConvertertype - 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.Object instance.public IlpSAXSerializable getAttributeValueHandler(Class attributeValueClass)
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.
getAttributeValueHandler in interface IlpTypeConverterattributeValueClass - The class of the attribute to be read from or written in XML.IlpSAXSerializable that contains the way the attribute should be
read from or written in XML.public void setAttributeValueHandler(Class attributeValueClass, IlpSAXSerializable serializableAttribute)
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.public void registerEditor(Class targetType, Class editorClass)
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:
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).public Object convertTo(Class type, Object value)
This method is able to:
String value to a given
type (See createJavaInstance(Class, String))
String (See createStringValue(Class, Object))
You can override this method to extend this behavior providing different types of conversions.
convertTo in interface IlpTypeConvertertype - Target class to convert.value - The instance to be converted.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.