public Example3(String path)
{
this.path=path;
}
public void getExecute()
{
try {
// Load the rule service provider of the reference
// implementation.
// Loading this class will automatically register this
// provider with the provider manager.
Class.forName( "org.jruleengine.RuleServiceProviderImpl" );
// Get the rule service provider from the provider manager.
RuleServiceProvider serviceProvider = RuleServiceProviderManager.getRuleServiceProvider( "org.jruleengine" );
// get the RuleAdministrator
RuleAdministrator ruleAdministrator = serviceProvider.getRuleAdministrator();
System.out.println("\nAdministration API\n");
System.out.println( "Acquired RuleAdministrator: " + ruleAdministrator );
// get an input stream to a test XML ruleset
// This rule execution set is part of the TCK.
InputStream inStream = new FileInputStream("WebContent\\example3.xml");
System.out.println("Acquired InputStream to example3.xml: " + inStream );
// parse the ruleset from the XML document
RuleExecutionSet res1 = ruleAdministrator.getLocalRuleExecutionSetProvider( null ).createRuleExecutionSet( inStream, null );
inStream.close();
System.out.println( "Loaded RuleExecutionSet: " + res1);
// register the RuleExecutionSet
String uri = res1.getName();
ruleAdministrator.registerRuleExecutionSet(uri, res1, null );
System.out.println( "Bound RuleExecutionSet to URI: " + uri);
// Get a RuleRuntime and invoke the rule engine.
System.out.println( "\nRuntime API\n" );
}
catch (NoClassDefFoundError e) {
if (e.getMessage().indexOf("Exception") != -1) {
System.err.println("Error: The Rule Engine Implementation could not be found.");
}
else {
System.err.println("Error: " + e.getMessage());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
In jsp page i created an instance of Example3 object. When i run the jsp page i'm getting FileNotFoundException showing message "example3.xml is not found? How to get rid of it? Please help me?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
public class Example3 {
String path;
public Example3(){}
public Example3(String path)
{
this.path=path;
}
public void getExecute()
{
try {
// Load the rule service provider of the reference
// implementation.
// Loading this class will automatically register this
// provider with the provider manager.
Class.forName( "org.jruleengine.RuleServiceProviderImpl" );
// Get the rule service provider from the provider manager.
RuleServiceProvider serviceProvider = RuleServiceProviderManager.getRuleServiceProvider( "org.jruleengine" );
// get the RuleAdministrator
RuleAdministrator ruleAdministrator = serviceProvider.getRuleAdministrator();
System.out.println("\nAdministration API\n");
System.out.println( "Acquired RuleAdministrator: " + ruleAdministrator );
// get an input stream to a test XML ruleset
// This rule execution set is part of the TCK.
InputStream inStream = new FileInputStream("WebContent\\example3.xml");
System.out.println("Acquired InputStream to example3.xml: " + inStream );
// parse the ruleset from the XML document
RuleExecutionSet res1 = ruleAdministrator.getLocalRuleExecutionSetProvider( null ).createRuleExecutionSet( inStream, null );
inStream.close();
System.out.println( "Loaded RuleExecutionSet: " + res1);
// register the RuleExecutionSet
String uri = res1.getName();
ruleAdministrator.registerRuleExecutionSet(uri, res1, null );
System.out.println( "Bound RuleExecutionSet to URI: " + uri);
// Get a RuleRuntime and invoke the rule engine.
System.out.println( "\nRuntime API\n" );
RuleRuntime ruleRuntime = serviceProvider.getRuleRuntime();
System.out.println( "Acquired RuleRuntime: " + ruleRuntime );
// create a StatefulRuleSession
StatefulRuleSession statefulRuleSession =
(StatefulRuleSession) ruleRuntime.createRuleSession( uri,
new HashMap(),
RuleRuntime.STATEFUL_SESSION_TYPE );
System.out.println( "Got Stateful Rule Session: " + statefulRuleSession );
// Add some clauses…
ArrayList input = new ArrayList();
input.add(new Clause("Socrate is human"));
// add an Object to the statefulRuleSession
statefulRuleSession.addObjects( input );
System.out.println( "Called addObject on Stateful Rule Session: "
+ statefulRuleSession );
statefulRuleSession.executeRules();
System.out.println( "Called executeRules" );
// extract the Objects from the statefulRuleSession
List results = statefulRuleSession.getObjects();
System.out.println( "Result of calling getObjects: " +
results.size() + " results." );
// Loop over the results.
Iterator itr = results.iterator();
while(itr.hasNext()) {
Object obj = itr.next();
System.out.println("Clause Found: "+obj.toString());
}
// release the statefulRuleSession
statefulRuleSession.release();
System.out.println( "Released Stateful Rule Session." );
System.out.println();
}
catch (NoClassDefFoundError e) {
if (e.getMessage().indexOf("Exception") != -1) {
System.err.println("Error: The Rule Engine Implementation could not be found.");
}
else {
System.err.println("Error: " + e.getMessage());
}
}
catch (Exception e) {
e.printStackTrace();
}
}
In jsp page i created an instance of Example3 object. When i run the jsp page i'm getting FileNotFoundException showing message "example3.xml is not found? How to get rid of it? Please help me?
Hi,
Sounds like a path issue. Use a File() object, do checks isExists() and isFile() and then use this File object for the input stream.
--- sample -----
// load the rules
FileInputStream fis = null;
try {
File rulesSrc = new File(rulesDirectory, rulesFile);
System.out.println("Loading rules set from ("+rulesSrc+")");
if (! (rulesSrc.exists() && rulesSrc.isFile()))
throw new IllegalStateException("Couldn't find the rule file ("+rulesSrc.getAbsolutePath()+")");
fis = new FileInputStream(rulesSrc);
// parse the ruleset from the XML document
ruleExecutionSet = ruleAdministrator.getLocalRuleExecutionSetProvider(null).createRuleExecutionSet(fis, null);
System.out.println( "Loaded RuleExecutionSet: " + ruleExecutionSet);
} finally {
if (fis != null) fis.close();
}