I am trying to add a rule to a package.
First I create a PackageDescr, then I create a RuleDescr
and set some properties in it
com.deepak.development.Trade class is loaded into the working memory before
I try to create this rule
Upon doing a DrlDump, I get the following (which is correctly formed; if I
copy paste this in a drl file, the rule gets executed as expected)
rule "Added new Rule"
when
trade : com.deepak.development.Trade( )
then
System.out.println("Whatever");end
//////////////////////////
// CODE
//////////////////////////
//Create a PackageDescr
//packages[0] is the package that is already available,
//since I create a new PackageDescr with same name,
//I expect the new rule to be appended to the existing package
final PackageDescr packageDescr = new PackageDescr(new
Package(packages[0].getName()).getName());
//Create a RuleDescr
RuleDescr ruleDescr = new RuleDescr("Added new Rule");
String consequence = "System.out.println(\"Whatever\");";
AndDescr lhs = new AndDescr();
ruleDescr.setLhs( lhs );
final PatternDescr pattern = new PatternDescr(
com.deepak.development.Trade.class.getName(),"trade");
lhs.addDescr( pattern );
ruleDescr.setConsequence( consequence );
PackageBuilder builder = new PackageBuilder(packages[0]);
packageDescr.addRule( ruleDescr );
DrlDumper drlDumper = new DrlDumper();
System.out.println("Dumping Package Descriptor for all rules: "+
drlDumper.dump(packageDescr));
//Nullpointer Exception caught
builder.addPackage(packageDescr);
ruleBase.addPackage(builder.getPackage());
Doing a debug in eclipse I can see that a NullPointerException is caught in
the line ###builder.addPackage(packageDescr)###
Is there any other property I need to set in packageDescr before it can be
added to a builder?
I can see the following in the debug section of eclipse
PackageStore.read(String) line: 58
The following is shown in the Variables side (in eclispe debug mode)
[corresponds to PackageStore]
this PackageStore (id=13923)
errors ArrayList<E> (id=15898)
elementData Object[10] (id=19840)
modCount 0
size 0
javaDialectRuntimeData null
resourceName "java/lang/Object.class" (id=13925)
count 22
hash 0
offset 0
value (id=15896)
clazz null
--
View this message in context:
http://old.nabble.com/exception-while-adding-a-packageDescr-to-a-PackageB...
Sent from the drools - user mailing list archive at
Nabble.com.