ilog.rules.bom

Interface IlrObjectModel

  • All Superinterfaces:
    IlrProperties, IlrTransientProperties, IlrVisitable
    All Known Subinterfaces:
    IlrMutableObjectModel
    All Known Implementing Classes:
    IlrDynamicObjectModel, IlrReflect


    public interface IlrObjectModel
    extends IlrProperties, IlrVisitable
    This interface represents an object model.

    An object model is composed of a default package which is itself composed of other packages, of classes and of enumerations.

    Note that the API changed slightly in JRules 5.0.

    • Ilr<className>.List and Ilr<className>.Iterator have been replaced by List and Iterator respectively. The methods from the removed classes that work using the model element's name are in IlrModelUtilities.
    • IlrObjectModel.Visitor is deprecated. It is now replaced by IlrVisitor which supports the new kinds of model elements and permits to select easily the classes to visit. For example, if you want to count the number of members, except methods:
      
       public static class MemberCounter extends IlrVisitor { // The class has to be static and public!
         public int counter;
         public void inspect(IlrMember member) { // The accepts methods have to be public
           counter++;
         }
         public void inspect(IlrMethod method) {
           // do nothing
         }
       }
       
    • IlrObjectModel.Selector is deprecated. It is now replaced by IlrSelector, which supports the new kinds of model elements and permits to select easily the classes to be tested. For example, if you want to accept all public members, except methods:
      
       public static class MemberSelector extends IlrSelector { // The class has to be static and public!
         public boolean accepts(IlrMember member) { // The inspect methods have to be public
           return true;
         }
         public boolean accepts(IlrMethod method) {
           return false;
         }
       }
       

      The methods that previously had an IlrObjectModel.Selector as a parameter now have an IlrSelector. You can wrap your implementations of IlrObjectModel.Selector by using the IlrObjectModel.SelectorWrapper class.

    See Also:
    IlrPackage, IlrType, IlrClass, IlrEnum, IlrPrimitiveType
    • Method Detail

      • getClassLoader

        java.lang.ClassLoader getClassLoader()
        Returns the class loader set by a call to setClassLoader.
      • setClassLoader

        void setClassLoader(java.lang.ClassLoader classLoader)
        Sets the class loader used by the mapJavaType(String) and mapJavaClass(String) methods. If the class loader is null, then the Class.forName method is used to load the classes. If the class loader has to be set, do it just after creating the object model, before any classes are added to it.

        Initially the class loader property is null.

      • getPlatform

        IlrObjectModel.Platform getPlatform()
        Returns the platform referenced by this object model
        Since:
        JRules 7.0
      • setJavaClassLookupEnabled

        void setJavaClassLookupEnabled(boolean flag)
        Deprecated. As of JRules 6.0, use IlrObjectModel.Kind passed at creation time instead.
        Enables or disables the Java class lookup.

        If this property must be set, do it just after creating the object model, before any classes are added to it.

        If the type of object model is IlrObjectModel.Kind.NONNATIVE, this property is initially false, otherwise it is true.

        Throws:
        java.lang.UnsupportedOperationException - if the class lookup cannot be enabled/disabled.
      • setMappingComponentProperties

        void setMappingComponentProperties(boolean flag)
        Enables or disables mapping of component properties.

        This property modifies the way Java classes are mapped to IlrClasses.

        By default this property is true. Component properties are mapped as described here:

        If the mappingComponentProperties property is false, then there is no special treatement of get and set methods. They are simply mapped as methods and no component property, indexed component property or attributes are created.
        Since:
        JRules 6.0
      • isMappingComponentProperties

        boolean isMappingComponentProperties()
        Returns true if the mapping of component properties is enabled.
        Since:
        JRules 6.0
        See Also:
        setMappingComponentProperties(boolean)
      • merge

        boolean merge(IlrObjectModel objectModel)
        Merges objectModel into this object model.
        Throws:
        java.lang.RuntimeException - if the target object model is not mutable
        Parameters:
        objectModel - The source object model.
        Returns:
        true if successful.
      • merge

        boolean merge(IlrObjectModel objectModel,
                    IlrSelector selector)
        Merges the subset of objectModel defined by selector into this object model.

        For a model element to be merged it must be accepted by the selector along with all other model elements on which it depends.

        If the given selector rejects a class (for example, C) but accepts an attribute of another class of type C, then the attribute will not be merged since its type has been rejected. The same goes for methods with respect to their parameter types, return type and exception types and also for classes with respect to their superclasses and superinterfaces.

        Throws:
        java.lang.RuntimeException - if the target object model is not mutable
        Parameters:
        objectModel - A source object model.
        selector - An object model subset selector. If null the object model is completely merged.
        Returns:
        true if successful.
      • merge

        boolean merge(IlrObjectModel objectModel,
                    IlrSelector selector,
                    java.util.Iterator initialTypes)
        Merges the subset of objectModel defined by selector and initialTypes into this object model.

        This method merges the classes and enums given by the initialTypes iterator along with their members (attributes, methods and tags). Other types, not present in initialTypes but indirectly required (such as the types of attributes, and so forth) are also written, but their members are omitted.

        Note: For a model element to be merged, it must also be accepted by the given selector along with all of the other model elements on which it depends.

        It is recommended to use IlrSelectors.dynamicTypes(model) as the value of the initialTypes parameter so that classes bound to actual Java classes are not serialized.

        Throws:
        java.lang.RuntimeException - if the target object model is not mutable
        Parameters:
        objectModel - A source object model.
        selector - An object model subset selector.
        initialTypes - An iterator which iterates over the classes that must be fully merged.
        Returns:
        true if successful.
      • addJavaClass

        IlrType addJavaClass(java.lang.Class javaClass)
        Adds the description of the Java class named javaClass to the object model. The Java reflection API is used.

        This method adds an IlrClass reflecting the given Java class along with its public attributes, constructors and methods. It also adds all of the other required classes (such as the types of public attributes, and so forth), but without their attributes and methods. None of the added classes are bound to their original Java classes (for example: the IlrType.getJavaClass method returns null).

        If an IlrClass that has the same fully qualified name as the given Java class existed prior to the call to this method, then this IlrClass is updated to reflect the given Java class.

        Parameters:
        javaClass - The source Java class.
        Returns:
        The added type. It is either an IlrClass or an IlrPrimitiveType.
      • mapJavaType

        IlrType mapJavaType(java.lang.Class javaClass)
        Adds the description of the Java class javaClass to the object model.

        Note: If a type with the same name already exists, it is simply returned. Otherwise, if the name is already used by a package, null is returned. Otherwise, a new IlrType mapping the given javaClass is added to the object model and it is returned.

        Note: Only the public members of the Java class are reflected through the mapped IlrClass object.

        What happens when a Java class is mapped to an IlrType depends on the kind of object model.

        • In the case of a IlrObjectModel.Kind.NATIVE object model, the returned type contains a reference to the original Java class which can be retrieved by calling the IlrType.getNativeClass() method. The IlrType element is said to be bound to the Java class.

          If a given IlrClass element is bound to a Java class, and one of the following elements is requested :

          • the types of its attributes
          • the return type of its methods
          • the types of its parameters
          • the exceptions thrown
          and if any of these types were not previously present in the object model, then they are lazily added by calls to the mapJavaType(Class) method.
        • In the case of a IlrObjectModel.Kind.BUSINESS object model, the returned type does not contain a reference to the original Java class. All the Java class members are mapped to IlrMember instances. If a type used in a member or as a superclass was not previously present in the object model, then it is created as a missing refence (see IlrType.isMissingReference().
        Parameters:
        javaClass - The source Java class.
        Returns:
        The added type. It is either an IlrClass or an IlrPrimitiveType.
      • mapJavaClass

        IlrClass mapJavaClass(java.lang.Class javaClass)
        Calls mapJavaType(Class) and, if the returned type is an IlrClass, it is returned, otherwise null is returned.
        Parameters:
        javaClass - The source Java class.
        Returns:
        The added type. It is either an IlrClass or an IlrPrimitiveType.
      • mapJavaClass

        IlrClass mapJavaClass(java.lang.String rawClassName,
                            IlrType... typeParameters)
        Creates an instance of a generic class called rawClassName bound to the given type parameters.
        Since:
        JRules 6.0
        Parameters:
        rawClassName -
        typeParameters -
      • mapJavaType

        IlrType mapJavaType(java.lang.String className)
        Adds the description of the Java class named className to the object model. Note that although the class loader defined in this object model is used to retrieve the Java class, the className parameter should be specified using the Java language convention instead of the java.lang.ClassLoader.loadClass convention (for example: int[] as "int[]" and not "[I").

        Beware that if a type with the given qualified name exists in the object model prior to the call to this method, then that type is returned although it may be defined differently than the Java class with the same name.

        The class name may be the name of an instance of a generic class. For example, this method may be called with "java.util.Collection<java.lang.String>" as parameter. If the current Java platform supports generics, an instance of IlrClass will be returned. In its generic information (IlrClass.getGenericInfo()), the type parameters (IlrGenericInfo.getTypeParameters()) will contain the IlrClass java.lang.String.

        Note: This method is sensitive to the value returned by isDynamicallyLoadingClasses(). If the Java class lookup is not enabled, then this method returns null.

        Since:
        JRules 6.0 Support of generic class name
        Parameters:
        className - The source Java class name.
        Returns:
        The mapped class.
      • mapJavaClass

        IlrClass mapJavaClass(java.lang.String className)
        Calls mapJavaType(String) and, if the returned type is an IlrClass, it is returned, otherwise null is returned.
        Parameters:
        className - The source Java class name.
        Returns:
        The mapped class.
      • remove

        boolean remove(IlrSelector selector)
        Removes the subset of this object model defined by the selector argument.
        Since:
        JRules 6.0, for the return of a result.
        Parameters:
        selector - The object model subset selector.
        Returns:
        true If at least one model element was removed.
      • removeClass

        boolean removeClass(IlrClass aClass)
        Removes the class aClass from this object model.
        Since:
        JRules 6.0 for the return of a result.
        Parameters:
        aClass - The class to be removed.
        Returns:
        true if the class was removed
      • getDefaultPackage

        IlrPackage getDefaultPackage()
        Returns the default package of the object model. This is the package that contains all of the top-level named packages (such as java, ilog, and so forth). The default package may also contain classes and enumerations.
      • getStringClass

        IlrClass getStringClass()
        Returns the java.lang.String class.
      • getPackage

        IlrPackage getPackage(java.lang.String fullyQualifiedName)
        Returns the package which has the fully qualified name fullyQualifiedName.
        Parameters:
        fullyQualifiedName - A fully qualified name.
        Returns:
        A package or null.
      • getType

        IlrType getType(java.lang.String fullyQualifiedName)
        Returns the type having the fully qualified name fullyQualifiedName.
        Parameters:
        fullyQualifiedName - A fully qualified name.
        Returns:
        A type or null.
      • getClass

        IlrClass getClass(java.lang.String fullyQualifiedName)
        Returns the class which has the fully qualified name fullyQualifiedName.
        Parameters:
        fullyQualifiedName - A fully qualified name.
        Returns:
        A class or null.
      • getClass

        IlrClass getClass(java.lang.String rawClassName,
                        IlrType[] typeParameters)
        An instance of a generic class called rawClassName bound to the given type parameters.
        Since:
        JRules 6.0
        Parameters:
        rawClassName - The instance of the rawClassName generic class.
        typeParameters - The given type parameters.
        Returns:
        A class, or null.
      • getGenericClass

        IlrClass getGenericClass(java.lang.String rawClassName,
                               int numberOfTypeParameters)
      • getClassReference

        IlrClass getClassReference(java.lang.Class javaClass)
        Returns the class corresponding to the Java class. For an execution model, it does the same as mapJavaClass(Class). For a business model, it returns a regular class if the Java class has already been mapped, otherwise it returns a missing reference (see IlrType.isMissingReference().
        Since:
        JRules 6.0
      • getTypeReference

        IlrType getTypeReference(java.lang.Class javaClass)
        Returns the type corresponding to the Java class. For an execution model, it does the same as mapJavaType(Class). For a business model, it returns a regular type if the Java class has already been mapped, otherwise it returns a missing reference (see IlrType.isMissingReference().
        Since:
        JRules 6.0
      • getClassReference

        IlrClass getClassReference(java.lang.String fqn)
        Returns the class corresponding to the fqn. It returns a regular class if the fqn is already the fqn of a class, null if it is the fqn of type (not a class), otherwise it returns a missing reference (see IlrType.isMissingReference().
        Since:
        JRules 6.0
      • getClassReference

        IlrClass getClassReference(java.lang.String fqn,
                                 IlrType[] typeParameters)
        Returns the class corresponding to the fqn AND the type parameters. It returns a regular class if the fqn is already the fqn of a class, null if it is the fqn of type (not a class), otherwise it returns a missing reference (see IlrType.isMissingReference().
        Since:
        JRules 6.0
      • getTypeReference

        IlrType getTypeReference(java.lang.String fqn)
        Returns the type corresponding to the fqn. It returns a regular type if the fqn is already the fqn of a class, otherwise it returns an IlrType.isMissingReference().
        Since:
        JRules 6.0
      • visit

        boolean visit(IlrObjectModel.Visitor visitor)
        Deprecated. Use IlrVisitor instead.
        Visits the model elements of this object model. This method calls the visitPackge method of the visitor applied to the default package of the object model.
        Parameters:
        visitor - A visitor.
        Returns:
        true if the visitor's visitPackage method returns true.
      • allPackages

        java.util.Iterator allPackages()
        Returns an iterator that iterates over all of the packages contained in this object model.
        Returns:
        A package iterator.
      • allEnums

        java.util.Iterator allEnums()
        Returns an iterator that iterates over all of the enumerations contained in this object model.
        Returns:
        An enumeration iterator.
      • allClasses

        java.util.Iterator allClasses()
        Returns an iterator that iterates over all classes contained in this object model.
        Returns:
        A class iterator.
      • getPrimitiveTypes

        java.util.List getPrimitiveTypes()
        Returns a list of all the primitive types in this object model.
        Returns:
        A primitive type list.
      • getPrimitiveType

        IlrPrimitiveType getPrimitiveType(java.lang.String name)
        Returns the primitive type named name.
        Returns:
        A primitive type or null.
      • getVoidType

        IlrType getVoidType()
        Returns the void primitive type.
        Returns:
        A primitive type.
      • getBooleanType

        IlrType getBooleanType()
        Returns the boolean primitive type.
        Returns:
        A primitive type.
      • getByteType

        IlrType getByteType()
        Returns the byte primitive type.
        Returns:
        A primitive type.
      • getCharType

        IlrType getCharType()
        Returns the char primitive type.
        Returns:
        A primitive type.
      • getFloatType

        IlrType getFloatType()
        Returns the float primitive type.
        Returns:
        A primitive type.
      • getDoubleType

        IlrType getDoubleType()
        Returns the double primitive type.
        Returns:
        A primitive type.
      • getShortType

        IlrType getShortType()
        Returns the short primitive type.
        Returns:
        A primitive type.
      • getIntType

        IlrType getIntType()
        Returns the int primitive type.
        Returns:
        A primitive type.
      • getLongType

        IlrType getLongType()
        Returns the long primitive type.
        Returns:
        A primitive type.
      • getResources

        IlrResources getResources()
        Returns the resource bundle.
        Returns:
        The resource bundle. It is never null.

© Copyright IBM Corp. 1987, 2020