Hi,
i was trying to make use of JSR94 RI wrapper for the Jess rule engine to rewrite
your example for jess/example/pump. I wasn't sure how to go about it because the Java
API is quite vague, but below is what i came up with.
package org.jcp.jsr94.jess;
import javax.rules.RuleRuntime;
import javax.rules.RuleServiceProvider;
import javax.rules.RuleServiceProviderManager;
import javax.rules.StatefulRuleSession;
import javax.rules.admin.LocalRuleExecutionSetProvider;
import javax.rules.admin.RuleAdministrator;
import javax.rules.admin.RuleExecutionSet;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.List;
import java.util.HashMap;
public class Test {
public static final String TEST_URI = "http://jess/rules/test";
public static void main( String[] args ) throws Exception
{
// First, setup the RuleServiceProvider and RuleAdministrator
RuleServiceProviderManager.registerRuleServiceProvider( "http://jess/rules",
RuleServiceProviderImpl.class );
RuleServiceProvider ruleServiceProvider =
RuleServiceProviderManager.getRuleServiceProvider( "http://jess/rules" );
RuleAdministrator ruleAdministrator =
ruleServiceProvider.getRuleAdministrator();
// Load the rules
LocalRuleExecutionSetProvider ruleSetProvider =
ruleAdministrator.getLocalRuleExecutionSetProvider( null );
Reader ruleReader = new InputStreamReader(
Test.class.getClassLoader().getResourceAsStream(
"C:/Jess61p2/org/cp/jsr94/jess/pumps-fromjava.clp" ) );
RuleExecutionSet ruleSet = ruleSetProvider.createRuleExecutionSet( ruleReader,
null );
// register the rule set
ruleAdministrator.registerRuleExecutionSet( TEST_URI, ruleSet, null );
// Create some application specific data that will be needed by our
consequence.
HashMap map = new HashMap();
map.put( "message", "This came from the appData HashMap" );
// obtain the stateless rule session
RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime();
StatefulRuleSession session = (StatefulRuleSession)
ruleRuntime.createRuleSession( SISTERS_RULES_URI, map,
RuleRuntime.STATEFUL_SESSION_TYPE );
// Create the Beans
Tank t = new Tank("MAIN");
session.addObject( t);
Pump p = new Pump("MAIN", t);
session.addObject( p);
// execute the rules
session.executeRules();
List outList = session.getObjects();
session.release();
}
}
Well, it managed to compile however when i tried to run it, it gave me a null pointer
exception
C:\Jess61p2>java org.jcp.jsr94.jess.Test
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at org.jcp.jsr94.jess.Test.main(Test.java:34)
So here's my question,
1)Can i use files like "pumps-fromjava.clp" as an input for my Rule Set? If not, what
can i do to parse a whole list of rules at the same time? How about the functions?
where do i put them? can i put them in the same file?
2)Why did my program give me such an error. The file is definitely there, but they got
a null pointer exception. I can't understand why...
I would very appreciate your help. Thanks in advance.
regards,
LSP
--
______________________________________________
http://www.asiamail.com/
Now with POP3 access for only US$24.95/yr
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------