I have included a reference to "expander" in my DRL. The files look as
follows:
(src/main/rules/mylang.dsl)
[consequence][]Log "{msg}"=System.out.println("{msg}");
(src/main/rules/Sample.drl)
package com.sample
expander mylang.dsl
import com.sample.DroolsTest.Message;
rule "Hello World"
when
m : Message( status == Message.HELLO, message : message )
then
System.out.println( message );
m.setMessage( "Goodbye cruel world" );
m.setStatus( Message.GOODBYE );
update( m );
end
rule "GoodBye"
no-loop true
when
m : Message( status == Message.GOODBYE, message : message )
then
System.out.println( message );
m.setMessage( message );
end
(src/main/java/DroolsTest.java)
package com.sample;
import java.io.InputStreamReader;
import java.io.Reader;
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
/**
* This is a sample file to launch a rule package from a rule source file.
*/
public class DroolsTest {
public static final void main(String[] args) {
try {
//load up the rulebase
RuleBase ruleBase = readRule();
WorkingMemory workingMemory = ruleBase.newStatefulSession();
//go !
Message message = new Message();
message.setMessage( "Hello World" );
message.setStatus( Message.HELLO );
workingMemory.insert( message );
workingMemory.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
/**
* Please note that this is the "low level" rule assembly API.
*/
private static RuleBase readRule() throws Exception {
//read in the source
Reader source = new InputStreamReader(
DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );
//optionally read in the DSL (if you are using it).
Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream(
"/mylang.dsl" ) );
//Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can also be used...
PackageBuilder builder = new PackageBuilder();
//this wil parse and compile in one step
//NOTE: There are 2 methods here, the one argument one is for normal DRL.
//builder.addPackageFromDrl( source );
//Use the following instead of above if you are using a DSL:
builder.addPackageFromDrl( source, dsl );
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus( int status ) {
this.status = status;
}
}
}
Anstis, Michael (M.) wrote:
Can you provide your DRL and DSL?
Have you included a reference to "expander" in your DRL?
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of tansey
Sent: 31 October 2007 07:55
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Problem with DSL in Drools 4.0.3
I'm new to Drools, and I've setup the latest version of it in Eclipse 3.2.
I'm having trouble whenever I try to use a DSL though. I took the
standard
Hello World example and added the 'mylang.dsl' file, and changed the lines
in DroolsTest.readRule() as follows:
private static RuleBase readRule() throws Exception {
//read in the source
Reader source = new InputStreamReader(
DroolsTest.class.getResourceAsStream( "/Sample.drl" ) );
//optionally read in the DSL (if you are using it).
Reader dsl = new InputStreamReader(
DroolsTest.class.getResourceAsStream(
"/mylang.dsl" ) );
//Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can
also be used...
PackageBuilder builder = new PackageBuilder();
//this wil parse and compile in one step
//NOTE: There are 2 methods here, the one argument one is
for normal DRL.
//builder.addPackageFromDrl( source );
//Use the following instead of above if you are using a DSL:
builder.addPackageFromDrl( source, dsl );
//get the compiled package (which is serializable)
Package pkg = builder.getPackage();
//add the package to a rulebase (deploy the rule package).
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
return ruleBase;
}
Even if I remove all rules from the dsl file, it still gives me the same
error:
org.drools.rule.InvalidRulePackage:
[4] Unable to expand: m : Message( status == Message.HELLO, message :
message )
[6] Unable to expand: System.out.println( message );
[7] Unable to expand: m.setMessage( "Goodbye cruel world" );
[8] Unable to expand: m.setStatus( Message.GOODBYE );
[9] Unable to expand: update( m );
[5] Unable to expand: m : Message( status == Message.GOODBYE, message :
message )
[7] Unable to expand: System.out.println( message );
[8] Unable to expand: m.setMessage( message );
at org.drools.rule.Package.checkValidity(Package.java:424)
at
org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:361)
at com.sample.DroolsTest.readRule(DroolsTest.java:64)
at com.sample.DroolsTest.main(DroolsTest.java:21)
Anyone have an idea of what's wrong?
--
View this message in context:
http://www.nabble.com/Problem-with-DSL-in-Drools-4.0.3-tf4722439.html#a13501
597
Sent from the drools - user mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context:
http://www.nabble.com/Problem-with-DSL-in-Drools-4.0.3-tf4722439.html#a13...
Sent from the drools - user mailing list archive at
Nabble.com.