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>.ListandIlr<className>.Iteratorhave been replaced byListandIteratorrespectively. The methods from the removed classes that work using the model element's name are inIlrModelUtilities. -
IlrObjectModel.Visitoris deprecated. It is now replaced byIlrVisitorwhich 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.Selectoris deprecated. It is now replaced byIlrSelector, 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.Selectoras a parameter now have anIlrSelector. You can wrap your implementations ofIlrObjectModel.Selectorby using theIlrObjectModel.SelectorWrapperclass.
- See Also:
IlrPackage,IlrType,IlrClass,IlrEnum,IlrPrimitiveType
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface and Description static interfaceIlrObjectModel.ClassLoadingErrorHandlerstatic classIlrObjectModel.KindA kind of object model.static classIlrObjectModel.Platformstatic interfaceIlrObjectModel.SelectorDeprecated.UseIlrSelectorinstead.static classIlrObjectModel.SelectorWrapperCompatibility wrapper for selectors.static interfaceIlrObjectModel.VisitorDeprecated.UseIlrVisitorinstead
-
Method Summary
Methods Modifier and Type Method and Description IlrTypeaddJavaClass(java.lang.Class javaClass)Adds the description of the Java class namedjavaClassto the object model.java.util.IteratorallClasses()Returns an iterator that iterates over all classes contained in this object model.java.util.IteratorallEnums()Returns an iterator that iterates over all of the enumerations contained in this object model.java.util.IteratorallPackages()Returns an iterator that iterates over all of the packages contained in this object model.IlrTypegetBooleanType()Returns thebooleanprimitive type.IlrTypegetByteType()Returns thebyteprimitive type.IlrTypegetCharType()Returns thecharprimitive type.IlrClassgetClass(java.lang.String fullyQualifiedName)Returns the class which has the fully qualified namefullyQualifiedName.IlrClassgetClass(java.lang.String rawClassName, IlrType[] typeParameters)An instance of a generic class calledrawClassNamebound to the given type parameters.java.lang.ClassLoadergetClassLoader()Returns the class loader set by a call tosetClassLoader.IlrClassgetClassReference(java.lang.Class javaClass)Returns the class corresponding to the Java class.IlrClassgetClassReference(java.lang.String fqn)Returns the class corresponding to the fqn.IlrClassgetClassReference(java.lang.String fqn, IlrType[] typeParameters)Returns the class corresponding to the fqn AND the type parameters.IlrPackagegetDefaultPackage()Returns the default package of the object model.IlrTypegetDoubleType()Returns thedoubleprimitive type.IlrTypegetFloatType()Returns thefloatprimitive type.IlrClassgetGenericClass(java.lang.String rawClassName, int numberOfTypeParameters)IlrTypegetIntType()Returns theintprimitive type.IlrObjectModel.KindgetKind()Returns the kind of object model.IlrTypegetLongType()Returns thelongprimitive type.IlrPackagegetPackage(java.lang.String fullyQualifiedName)Returns the package which has the fully qualified namefullyQualifiedName.IlrObjectModel.PlatformgetPlatform()Returns the platform referenced by this object modelIlrPrimitiveTypegetPrimitiveType(java.lang.String name)Returns the primitive type namedname.java.util.ListgetPrimitiveTypes()Returns a list of all the primitive types in this object model.IlrResourcesgetResources()Returns the resource bundle.IlrTypegetShortType()Returns theshortprimitive type.IlrClassgetStringClass()Returns thejava.lang.Stringclass.IlrTypegetType(java.lang.String fullyQualifiedName)Returns the type having the fully qualified namefullyQualifiedName.IlrTypegetTypeReference(java.lang.Class javaClass)Returns the type corresponding to the Java class.IlrTypegetTypeReference(java.lang.String fqn)Returns the type corresponding to the fqn.IlrTypegetVoidType()Returns thevoidprimitive type.booleanisDynamicallyLoadingClasses()Returnstrueif the Java class lookup is enabled.booleanisMappingComponentProperties()Returnstrueif the mapping of component properties is enabled.IlrClassmapJavaClass(java.lang.Class javaClass)CallsmapJavaType(Class)and, if the returned type is anIlrClass, it is returned, otherwisenullis returned.IlrClassmapJavaClass(java.lang.String className)CallsmapJavaType(String)and, if the returned type is anIlrClass, it is returned, otherwisenullis returned.IlrClassmapJavaClass(java.lang.String className, IlrObjectModel.ClassLoadingErrorHandler errorHandler)IlrClassmapJavaClass(java.lang.String rawClassName, IlrObjectModel.ClassLoadingErrorHandler errorHandler, IlrType... typeParameters)IlrClassmapJavaClass(java.lang.String rawClassName, IlrType... typeParameters)Creates an instance of a generic class calledrawClassNamebound to the given type parameters.IlrTypemapJavaType(java.lang.Class javaClass)Adds the description of the Java classjavaClassto the object model.IlrTypemapJavaType(java.lang.String className)Adds the description of the Java class namedclassNameto the object model.IlrTypemapJavaType(java.lang.String className, IlrObjectModel.ClassLoadingErrorHandler errorHandler)booleanmerge(IlrObjectModel objectModel)MergesobjectModelinto this object model.booleanmerge(IlrObjectModel objectModel, IlrSelector selector)Merges the subset ofobjectModeldefined byselectorinto this object model.booleanmerge(IlrObjectModel objectModel, IlrSelector selector, java.util.Iterator initialTypes)Merges the subset ofobjectModeldefined byselectorandinitialTypesinto this object model.booleanremove(IlrSelector selector)Removes the subset of this object model defined by theselectorargument.booleanremoveClass(IlrClass aClass)Removes the classaClassfrom this object model.voidsetClassLoader(java.lang.ClassLoader classLoader)Sets the class loader used by themapJavaType(String)andmapJavaClass(String)methods.voidsetJavaClassLookupEnabled(boolean flag)Deprecated.As of JRules 6.0, useIlrObjectModel.Kindpassed at creation time instead.voidsetMappingComponentProperties(boolean flag)Enables or disables mapping of component properties.booleanvisit(IlrObjectModel.Visitor visitor)Deprecated.UseIlrVisitorinstead.-
Methods inherited from interface ilog.rules.bom.IlrProperties
isPropertyPersistent, setPersistentProperty, setPersistentProperty
-
Methods inherited from interface ilog.rules.bom.IlrTransientProperties
getPropertyValue, getPropertyValue, propertyNames, removeProperty, setPropertyValue
-
Methods inherited from interface ilog.rules.util.IlrVisitable
accept
-
-
-
-
Method Detail
-
getClassLoader
java.lang.ClassLoader getClassLoader()
Returns the class loader set by a call tosetClassLoader.
-
setClassLoader
void setClassLoader(java.lang.ClassLoader classLoader)
Sets the class loader used by themapJavaType(String)andmapJavaClass(String)methods. If the class loader isnull, then theClass.forNamemethod 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.
-
getKind
IlrObjectModel.Kind getKind()
Returns the kind of object model.- Since:
- JRules 6.0
-
getPlatform
IlrObjectModel.Platform getPlatform()
Returns the platform referenced by this object model- Since:
- JRules 7.0
-
isDynamicallyLoadingClasses
boolean isDynamicallyLoadingClasses()
Returnstrueif the Java class lookup is enabled. When disabled themapJavaType(String)method behaves the same as thegetType(String)method. This also applies to themapJavaClass(String)that behaves as thegetClass(String)method.
-
setJavaClassLookupEnabled
void setJavaClassLookupEnabled(boolean flag)
Deprecated. As of JRules 6.0, useIlrObjectModel.Kindpassed 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 initiallyfalse, otherwise it istrue.- 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:- In the case of a
IlrObjectModel.Kind.NATIVEobject model, the get and set methods are mapped to correspondingIlrMethods and toIlrComponentPropertyorIlrIndexedComponentProperty, in accordance with the JavaBeans conventions. - In the case of a
IlrObjectModel.Kind.BUSINESSobject model, the get and set methods are linked to correspondingIlrAttributes, in accordance with the JavaBeans conventions.- A
setXXXmethod without a correspondinggetXXXmethod will be mapped to a read only attribute (seeIlrAttribute.isReadonly()). - A
getXXXmethod without a correspondingsetXXXmethod will be mapped to a write only attribute (seeIlrAttribute.isWriteonly()). - A pair of
getXXXandsetXXXmethods will be mapped to one attribute.
- A
mappingComponentPropertiesproperty 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
- In the case of a
-
isMappingComponentProperties
boolean isMappingComponentProperties()
Returnstrueif the mapping of component properties is enabled.- Since:
- JRules 6.0
- See Also:
setMappingComponentProperties(boolean)
-
merge
boolean merge(IlrObjectModel objectModel)
MergesobjectModelinto this object model.- Throws:
java.lang.RuntimeException- if the target object model is not mutable- Parameters:
objectModel- The source object model.- Returns:
trueif successful.
-
merge
boolean merge(IlrObjectModel objectModel, IlrSelector selector)
Merges the subset ofobjectModeldefined byselectorinto 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 typeC, 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. Ifnullthe object model is completely merged.- Returns:
trueif successful.
-
merge
boolean merge(IlrObjectModel objectModel, IlrSelector selector, java.util.Iterator initialTypes)
Merges the subset ofobjectModeldefined byselectorandinitialTypesinto this object model.This method merges the classes and enums given by the
initialTypesiterator along with their members (attributes, methods and tags). Other types, not present ininitialTypesbut 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 theinitialTypesparameter 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:
trueif successful.
-
addJavaClass
IlrType addJavaClass(java.lang.Class javaClass)
Adds the description of the Java class namedjavaClassto the object model. The Java reflection API is used.This method adds an
IlrClassreflecting the given Java class along with itspublicattributes, constructors and methods. It also adds all of the other required classes (such as the types ofpublicattributes, and so forth), but without their attributes and methods. None of the added classes are bound to their original Java classes (for example: theIlrType.getJavaClassmethod returnsnull).If an
IlrClassthat has the same fully qualified name as the given Java class existed prior to the call to this method, then thisIlrClassis updated to reflect the given Java class.- Parameters:
javaClass- The source Java class.- Returns:
- The added type. It is either an
IlrClassor anIlrPrimitiveType.
-
mapJavaType
IlrType mapJavaType(java.lang.Class javaClass)
Adds the description of the Java classjavaClassto 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,
nullis returned. Otherwise, a newIlrTypemapping the givenjavaClassis added to the object model and it is returned.Note: Only the
publicmembers of the Java class are reflected through the mappedIlrClassobject.What happens when a Java class is mapped to an
IlrTypedepends on the kind of object model.- In the case of a
IlrObjectModel.Kind.NATIVEobject model, the returned type contains a reference to the original Java class which can be retrieved by calling theIlrType.getNativeClass()method. TheIlrTypeelement is said to be bound to the Java class.If a given
IlrClasselement 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
mapJavaType(Class)method. - In the case of a
IlrObjectModel.Kind.BUSINESSobject model, the returned type does not contain a reference to the original Java class. All the Java class members are mapped toIlrMemberinstances. 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 (seeIlrType.isMissingReference().
- Parameters:
javaClass- The source Java class.- Returns:
- The added type. It is either an
IlrClassor anIlrPrimitiveType.
- In the case of a
-
mapJavaClass
IlrClass mapJavaClass(java.lang.Class javaClass)
CallsmapJavaType(Class)and, if the returned type is anIlrClass, it is returned, otherwisenullis returned.- Parameters:
javaClass- The source Java class.- Returns:
- The added type. It is either an
IlrClassor anIlrPrimitiveType.
-
mapJavaClass
IlrClass mapJavaClass(java.lang.String rawClassName, IlrType... typeParameters)
Creates an instance of a generic class calledrawClassNamebound to the given type parameters.- Since:
- JRules 6.0
- Parameters:
rawClassName-typeParameters-
-
mapJavaClass
IlrClass mapJavaClass(java.lang.String rawClassName, IlrObjectModel.ClassLoadingErrorHandler errorHandler, IlrType... typeParameters)
-
mapJavaType
IlrType mapJavaType(java.lang.String className)
Adds the description of the Java class namedclassNameto the object model. Note that although the class loader defined in this object model is used to retrieve the Java class, theclassNameparameter should be specified using the Java language convention instead of thejava.lang.ClassLoader.loadClassconvention (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
IlrClasswill be returned. In its generic information (IlrClass.getGenericInfo()), the type parameters (IlrGenericInfo.getTypeParameters()) will contain theIlrClass 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 returnsnull.- Since:
- JRules 6.0 Support of generic class name
- Parameters:
className- The source Java class name.- Returns:
- The mapped class.
-
mapJavaType
IlrType mapJavaType(java.lang.String className, IlrObjectModel.ClassLoadingErrorHandler errorHandler)
-
mapJavaClass
IlrClass mapJavaClass(java.lang.String className)
CallsmapJavaType(String)and, if the returned type is anIlrClass, it is returned, otherwisenullis returned.- Parameters:
className- The source Java class name.- Returns:
- The mapped class.
-
mapJavaClass
IlrClass mapJavaClass(java.lang.String className, IlrObjectModel.ClassLoadingErrorHandler errorHandler)
-
remove
boolean remove(IlrSelector selector)
Removes the subset of this object model defined by theselectorargument.- 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 classaClassfrom 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 asjava,ilog, and so forth). The default package may also contain classes and enumerations.
-
getStringClass
IlrClass getStringClass()
Returns thejava.lang.Stringclass.
-
getPackage
IlrPackage getPackage(java.lang.String fullyQualifiedName)
Returns the package which has the fully qualified namefullyQualifiedName.- 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 namefullyQualifiedName.- 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 namefullyQualifiedName.- 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 calledrawClassNamebound to the given type parameters.- Since:
- JRules 6.0
- Parameters:
rawClassName- The instance of therawClassNamegeneric 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 asmapJavaClass(Class). For a business model, it returns a regular class if the Java class has already been mapped, otherwise it returns a missing reference (seeIlrType.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 asmapJavaType(Class). For a business model, it returns a regular type if the Java class has already been mapped, otherwise it returns a missing reference (seeIlrType.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 (seeIlrType.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 (seeIlrType.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 anIlrType.isMissingReference().- Since:
- JRules 6.0
-
visit
boolean visit(IlrObjectModel.Visitor visitor)
Deprecated. UseIlrVisitorinstead.Visits the model elements of this object model. This method calls thevisitPackgemethod of the visitor applied to the default package of the object model.- Parameters:
visitor- A visitor.- Returns:
trueif the visitor'svisitPackagemethod returnstrue.
-
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 namedname.- Returns:
- A primitive type or null.
-
getVoidType
IlrType getVoidType()
Returns thevoidprimitive type.- Returns:
- A primitive type.
-
getBooleanType
IlrType getBooleanType()
Returns thebooleanprimitive type.- Returns:
- A primitive type.
-
getByteType
IlrType getByteType()
Returns thebyteprimitive type.- Returns:
- A primitive type.
-
getCharType
IlrType getCharType()
Returns thecharprimitive type.- Returns:
- A primitive type.
-
getFloatType
IlrType getFloatType()
Returns thefloatprimitive type.- Returns:
- A primitive type.
-
getDoubleType
IlrType getDoubleType()
Returns thedoubleprimitive type.- Returns:
- A primitive type.
-
getShortType
IlrType getShortType()
Returns theshortprimitive type.- Returns:
- A primitive type.
-
getIntType
IlrType getIntType()
Returns theintprimitive type.- Returns:
- A primitive type.
-
getLongType
IlrType getLongType()
Returns thelongprimitive type.- Returns:
- A primitive type.
-
getResources
IlrResources getResources()
Returns the resource bundle.- Returns:
- The resource bundle. It is never
null.
-
-