Greetings.<br>I am trying to find the correct approach to defining and using Java5 Enum's in Drools constraints.<br><br><b>Psudo code:</b><br>Class RuleRequest {<br> ... other attributes ...<br> // RequestType is an enum type.<br>
RequestType type ;<br><br> public RequestType getRequestType() {<br> return type;<br> }<br>}<br><br>public enum RequestType {<br> INTERNAL("internal"), EXTERNAL("external");<br>
}<br><br><b>Drools Rule:</b><br># 1st Constraint - I could have listed the type in the constraint for RuleRequest but say I want that to be in a separate constraint<br># 2nd Constraint - on the nested RequestType enum<br>
<b>req: RuleRequest(..some match not based on the RequestType but other attributes of RuleRequest...)<br>type: RequestType( ??? == RequestType.INTERNAL ) from req.requestType<br></b><br>What should be plugged in ??? to be able to match the requestType. Interestingly, if I say <br>
<b>type: RequestType( this == RequestType.INTERNAL ) from req.requestType </b>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.<br>
<br><b>Question<br></b>- 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?<br>- What is syntax and usage practices for the usage of the "this" keyword<br>
- 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. <br><br>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.<br>
<br>Thanks.<br>- Krishna<br><br><br><br><br><br>