Rule Execution Server API

ilog.rules.bom.util
Class IlrFormat

java.lang.Object
  extended by ilog.rules.bom.util.IlrFormat
All Implemented Interfaces:
Serializable

public final class IlrFormat
extends Object
implements Serializable

Instances of this class are literal formats: they are used by the object model and rule parser to read objects from strings and to print them into strings. An instance of this class maintains a list of Java formats and selects one of them to use according to the IlrType of the object, or according to the Java class. Initially, a SimpleDateFormat is created using the pattern M/d/yyyy H:mm. The locale provided by the engine resource mechanism. This format is associated with the Java class java.util.Date.

Since:
4.0
See Also:
Serialized Form

Constructor Summary
IlrFormat(IlrObjectModel objectModel)
           
 
Method Summary
 void applyDatePattern(String pattern)
          Changes the pattern of the simple date format used to parse and write the date literals.
 String format(IlrType type, Object obj)
          Prints an object to a string.
 String format(Object obj)
          Prints an object to a string.
 String formatWithClassname(Object obj)
          Print
 Format getFormat(Class aclass)
          Gets the Java format for a Java class.
 Format getFormat(IlrType type)
          Gets the Java format for an IlrType.
 Format[] getFormats()
          Gets all the Java formats currently known by this instance.
 Class getInheritedNativeClass(IlrType type)
           
 boolean isSupported(Class aclass)
           
 boolean isSupported(IlrType type)
          Returns true if the objects of type can be formatted.
 Object parse(Class aclass, String source)
          Parses a string and constructs an object of the specified class.
 Object parse(IlrType type, String source)
          Parses a string and constructs an object.
 void setFormat(Class aclass, Format format)
          Associates a format object with a Java class.
 void setFormat(IlrType type, Format format)
          Associates a format object with an IlrType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlrFormat

public IlrFormat(IlrObjectModel objectModel)
Method Detail

getFormat

public Format getFormat(IlrType type)
Gets the Java format for an IlrType.

Parameters:
type - An IlrType.
Returns:
A format, or null if no format can be obtained of the instances of the passed class.

setFormat

public void setFormat(IlrType type,
                      Format format)
Associates a format object with an IlrType. Later on, the format will be used to convert instances of this type into strings and vice versa.

Parameters:
type - An IlrType.
format - A Java format.

getFormat

public Format getFormat(Class aclass)
Gets the Java format for a Java class.

Parameters:
aclass - A Java class.
Returns:
A format, or null if no format can be obtained of the instances of the passed class.

setFormat

public void setFormat(Class aclass,
                      Format format)
Associates a format object with a Java class. Later on, the format will be used to convert instances of this class into strings and vice versa.

Parameters:
aclass - A Java class.
format - A Java format.

getFormats

public Format[] getFormats()
Gets all the Java formats currently known by this instance.

Returns:
An array of Java formats. The array is never null.

applyDatePattern

public void applyDatePattern(String pattern)
Changes the pattern of the simple date format used to parse and write the date literals. The passed string must follow the description of SimpleDateFormat.

Parameters:
pattern - The new pattern used to read and write date literals.

parse

public Object parse(IlrType type,
                    String source)
             throws ParseException
Parses a string and constructs an object. If there is a format for the type, it is used to parse the string. Otherwise, if the type represents a native class (see IlrType.getNativeClass(), the format for the native type is used. If no format is found, an exception is thrown. If exceptions are encountered during parsing, a ParseException is thrown.

Throws:
IlrMissingFormatException - If no format is found for the requested class.
ParseException - If the passed string raises parsing errors.
Parameters:
type - The type of the object to be constructed.
source - A string to be parsed using a format.
Returns:
The parsed object.

isSupported

public boolean isSupported(IlrType type)
Returns true if the objects of type can be formatted.


isSupported

public boolean isSupported(Class aclass)

getInheritedNativeClass

public Class getInheritedNativeClass(IlrType type)

parse

public Object parse(Class aclass,
                    String source)
             throws ParseException
Parses a string and constructs an object of the specified class. If no format is capable of read and write instances of the class, an exception is thrown. Otherwise, the format is used to parse the passed string. If exceptions are encountered during parsing, a ParseException is thrown.

Throws:
IlrMissingFormatException - If no format is found for the requested class.
ParseException - If the passed string raises parsing errors.
NumberFormatException - If the passed string was considered but cannot be parsed as a number.
Parameters:
aclass - The class of the object to be constructed.
source - A string to be parsed using a format.
Returns:
The parsed object.

format

public String format(IlrType type,
                     Object obj)
Prints an object to a string. A format is selected, according to the type parameter. The format is then used to format the passed object into a string. If no format is selected, the method applies toString() on the object and returns the result.

Parameters:
type - The type used to select a format.
obj - The object to format.
Returns:
A string.

formatWithClassname

public String formatWithClassname(Object obj)
Print


format

public String format(Object obj)
Prints an object to a string. A format is selected, according to the Java class of the object. The format is then used to format the passed object into a string. If no format is selected, the method applies toString() on the object and returns the result.

Parameters:
obj - The object to format.
Returns:
A string.

Rule Execution Server API

© Copyright IBM Corp. 1987, 2012