Krishna,
"this" is a special field that always refers to the fact itself, instead
of an attribute. Your use of "this" is fine.
== used as a top level constraint evaluator always calls for the equals()
method on the object in question, or the appropriate comparator when dealing
with primitives.
[]s
Edson
2008/1/31, Krishna Satya <krishna.ksatya(a)gmail.com>:
Greetings.
I am trying to find the correct approach to defining and using Java5
Enum's in Drools constraints.
*Psudo code:*
Class RuleRequest {
... other attributes ...
// RequestType is an enum type.
RequestType type ;
public RequestType getRequestType() {
return type;
}
}
public enum RequestType {
INTERNAL("internal"), EXTERNAL("external");
}
*Drools Rule:*
# 1st Constraint - I could have listed the type in the constraint for
RuleRequest but say I want that to be in a separate constraint
# 2nd Constraint - on the nested RequestType enum
*req: RuleRequest(..some match not based on the RequestType but other
attributes of RuleRequest...)
type: RequestType( ??? == RequestType.INTERNAL ) from req.requestType
*
What should be plugged in ??? to be able to match the requestType.
Interestingly, if I say
*type: RequestType( this == RequestType.INTERNAL ) from req.requestType *when
the ruleRequest has an RequestType of INTERNAL, the matching works. But I
do not see any examples/reference in the Drools documentation on the usage
of "this" in constraints. I saw a posting from Edson T. using this which is
why I tried it in the first place.
*Question
*- What is the expectation for the Enum. Should it have methods (getters)
that return the Enum type itself or methods that return the strigified value
of the Enum?
- What is syntax and usage practices for the usage of the "this" keyword
- What really happens when the Drools engine does the == comparison on
Enum's. Does it convert to the string value of the enum and then compare
that or is there something else in play.
I hope I have asked valid questions as I see many questions relating to
Enum but maybe a definitive/suggested approach and explanation from the
drools dream team may serve as a good reference on this subject.
Thanks.
- Krishna
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @
www.jboss.com