| ILOG JRules User Guide > Integrating Application Data > Tasks > Using the Dynamic XOM API > Creating a Dynamic Class |
Creating a Dynamic Class |
PREVIOUS NEXT |
You create a dynamic class when you create a dynamic XOM for some applications, to bind unusual data for use by the engine; for example, Lightweight Directory Access Protocol (LDAP).
To create a dynamic class using the API:
ilog.rules.bom packages.
Here is a simple example that creates a class with a field. The class is placed in a package in the XOM, whose name can be any valid Java package name. This class inherits form IlrHashObject, the concrete Java implementation of the dynamic class.
// Sets a package name. This can be any name..
String packageName = "myappli.dynamic";
// The class name.
String className = "Person";
// The field name.
String fieldName = "age";
// Sets the class driver's name.
String driverClassName = "ilog.rules.factory.IlrHashDriver";
// Maps the base Java class.
IlrClass baseClass = reflect.mapJavaClass(IlrHashObject.class);
// Gets or creates the package. Use a convenient method
// defined in IlrReflect. Adds a class in this package
// with a superclass.
IlrModelFactory factory = reflect.getModelFactory();
IlrMutablePackage pck = model.createPackage(packageName);
IlrMutableClass clazz = factory.createClass(pcl, className);
clazz.addSuperclass(baseClass);
// Sets the class as public. Otherwise, it cannot be used.
// Also sets the persistent property indicating the driver's
// class name.
clazz.setPublic();
clazz.setPersistentProperty("ilog.rules.engine.driver",driverClassName);
// Creates a field of type int and sets it as public. Non-public fields
// cannot be used in the rules.
IlrMutableAttribute att = factory.createAttribute(clazz, fieldName);
att.setMemberType(reflect.getIntType());
att.setPublic();
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |