I was just debugging my rules and monitored my working memory and
variables, trying to figure out why a certain Pattern match was not
firing, and noticed that a property value for a fact I inserted earlier
via the RHS does not seem to be inserted into working memory along with
the object. The fact's delegate (?) has the property value, but the fact
(as displayed in the variables tab) has a null value for the property.
Here is the rule that inserts the fact into memory:
rule "Explode Globals"
when
$request : DecisionRequest( )
$input : Object() from $request.getRequestObjects().values()
then
insert ( $input );
end
Just before the insert executes, $input looks like this in the variables
tab:
$input - NamedCollection<T> (id=61)
list - LinkedList<E> (id=62)
name - "constraints"
After the insert however, when the engine checks the name value in my
java class, the same fact now looks like this in the variables tab:
this - NamedCollectionShadowProxy (id=83)
delegate - NamedCollection<T> (id=61)
list - LinkedList<E> (id=62)
name - "constraints"
list - LinkedList<E> (id=87)
name - null << ??
So, when I next have a rule that looks like this:
rule "Assemble Constraints"
when
$const : OrderConstraint()
$coll : NamedCollection( name == "constraints" )
then
$coll.add($const);
update($coll);
end
Here is the java class:
public class NamedCollection<T> implements Collection<T>{
private static final long serialVersionUID = -457439174592908333L;
private Collection<T> list = new LinkedList<T>();
private String name;
public NamedCollection(){
}
public NamedCollection(String name){
this.name = name;
}
...more methods...
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
}
The pattern does not match since the value for name is null! When I
place a breakpoint in my java code during drools debugging, the name
value will return null each time. I also have another rule that creates
a new OrderConstraint, so all conditions for the last rule to fire
exist...other than the name property being null although it is set in
the delegate. I do not have any other rules that modify the
NamedCollection.
What am I doing wrong? Is this again related to having a class implement
a collection?
HC
Show replies by date