Accessing Session Beans from a Rule

From DOC

Jump to: navigation, search

You can access any session bean known to the Tolven application server including custom session beans from within a Rule Package.

First, import the local interface to the session bean you are interested in accessing. The following example will provide access to the TolvenProperties bean.

import org.tolven.core.TolvenPropertiesLocal;

global org.tolven.app.AppEvalAdaptor app;

If the bean is custom, then be sure the bean and its local inteface are included in the application server. See Customize tolvenEJB Plugin. If not already included in your rule package, also declare the global variable which gives you access to the Tolven rule wrapper functions.

Define a rule that looks up the bean and inserts it into working memory. In the following example, the rule executes unconditionally though you may want make it conditional. The parameter to the app.lookupResource method is the JNDI name of the session bean interface.

rule "Initialize Properties"
	when
		eval(true)
	then
		insert(app.lookupResource( "tolven/TolvenProperties/local"));
end

This will assert the session bean's interface into working memory.

Now we can include the resulting interface in rules. The following simple example just displays the OID of this Tolven instance.


rule "Display Database OID"
    when
    	$properties: TolvenPropertiesLocal()
    then
	app.info( "repository OID: " + $properties.getProperty( "tolven.repository.oid" ));
end
Personal tools