Using a JSR-94 Implementation in Java Code

The following Java code provides a template of what is involved in using a JSR-94 implementation in Java code, only the RuleServiceProvider registration string and the name of CA's implementation class are specific to CA Rule Engine:

String RULE_SERVICE_PROVIDER = "com.ca.cleverpath.aion.jsr94";

// Load the rule service provider of the vendor implementation.
// For more information on loading the service provider, see
// Acquiring the RuleServiceProvider.
Class.forName("com.ca.cleverpath.aion.jsr94.RuleServiceProviderImpl");

// Get the rule service provider from the provider manager.
RuleServiceProvider svcProvider =
	RuleServiceProviderManager.getRuleServiceProvider(RULE_SERVICE_PROVIDER);

// For the next series of steps, see Rule Administration: Acquiring
// and Registering the RuleExecutionSet.
// Get the Rule Administrator
RuleAdministrator ruleAdmin = svcProvider.getRuleAdministrator();

// Get the RuleExecutionSet provider
RuleExecutionSetProvider ruleSetProvider = 
	ruleAdmin.getRuleExecutionSetProvider(null);

// Get a sample rulebase file.
RuleExecutionSet ruleSet = ruleSetProvider.createRuleExecutionSet(
	"file:/D:/InstallSoftware/JSR94/lib/rulebase.bin",null);

String ruleSetUri = "rulebases://" + ruleSet.getName();
ruleAdmin.registerRuleExecutionSet(ruleSetUri, ruleSet, null);

// For the next series of steps, see Establish a Rule Session.
// Create a RuleRuntime
RuleRuntime runtime = svcProvider.getRuleRuntime();

// Create a Stateless Rule Session using the RuleRuntime
StatelessRuleSession session = (StatelessRuleSession)runtime.createRuleSession(
	ruleSetUri, null, RuleRuntime.STATELESS_SESSION_TYPE);

// Enter local code to create client instances on the Java side.
//  (Assume an instance, inst1, is created for input and an
//  inst2 is created for output.)
// Enter local code to set properties of created instances

// Perform inferencing over the added objects with the rules
// passed to this session at create time. See Stateless versus
// Stateful Rule Sessions.

List inputObjects = (List) new LinkedList();
inputObjects.add(inst1);
inputObjects.add(inst2);  //NOTE: Also pass the output instance to the rulebase
List objectsReadBack = session.executeRules(inputObjects);

// Enter local code to process results, for example, iterate over
// objectsReadBack.

// Close the session with the inference engine.
session.release();


ruleAdmin.deregisterRuleExecutionSet("rulebases://" + ruleSet.getName(), null);

For a detailed explanation of this code, see Construction of Java Client Applications. For a detailed example of an actual client application, see Client Application Class.