ilog.rules.bom.util

Class IlrFormat

  • java.lang.Object
    • ilog.rules.bom.util.IlrFormat
  • All Implemented Interfaces:
    java.io.Serializable


    public final class IlrFormat
    extends java.lang.Object
    implements java.io.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
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void applyDatePattern(java.lang.String pattern)
      Changes the pattern of the simple date format used to parse and write the date literals.
      java.lang.String format(IlrType type, java.lang.Object obj)
      Prints an object to a string.
      java.lang.String format(java.lang.Object obj)
      Prints an object to a string.
      java.lang.String formatWithClassname(java.lang.Object obj)
      Print
      java.text.Format getFormat(java.lang.Class aclass)
      Gets the Java format for a Java class.
      java.text.Format getFormat(IlrType type)
      Gets the Java format for an IlrType.
      java.text.Format[] getFormats()
      Gets all the Java formats currently known by this instance.
      java.lang.Class getInheritedNativeClass(IlrType type) 
      boolean isSupported(java.lang.Class aclass) 
      boolean isSupported(IlrType type)
      Returns true if the objects of type can be formatted.
      java.lang.Object parse(java.lang.Class aclass, java.lang.String source)
      Parses a string and constructs an object of the specified class.
      java.lang.Object parse(IlrType type, java.lang.String source)
      Parses a string and constructs an object.
      void setFormat(java.lang.Class aclass, java.text.Format format)
      Associates a format object with a Java class.
      void setFormat(IlrType type, java.text.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
    • Method Detail

      • getFormat

        public java.text.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,
                     java.text.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 java.text.Format getFormat(java.lang.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(java.lang.Class aclass,
                     java.text.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 java.text.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(java.lang.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 java.lang.Object parse(IlrType type,
                             java.lang.String source)
                               throws java.text.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.
        java.text.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(java.lang.Class aclass)
      • getInheritedNativeClass

        public java.lang.Class getInheritedNativeClass(IlrType type)
      • parse

        public java.lang.Object parse(java.lang.Class aclass,
                             java.lang.String source)
                               throws java.text.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.
        java.text.ParseException - If the passed string raises parsing errors.
        java.lang.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 java.lang.String format(IlrType type,
                              java.lang.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 java.lang.String formatWithClassname(java.lang.Object obj)
        Print
      • format

        public java.lang.String format(java.lang.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.

© Copyright IBM Corp. 1987, 2017