[rules-users] Adding a custom operator to drools?
Michael Zimmermann
list at incunabulum.de
Wed Sep 17 08:19:43 EDT 2008
Hi Edson,
I think I got it working :-)
Edson Tirelli wrote:
> For an example, look at the file SetEvaluatorsDefinition and look at
> the BaseMemberOf inner class. So, all the logic is in there, but we
> still used subclasses just to set the constructor attributes and
> override the toString() method, but you could still implement
> everything in a single class I guess.
Yes, this approach makes sense as long as you don't need to use the
different VariableContextEntry subclasses for handling double, char etc.
Yet, this can be handled, too.
toString():
You can avoid subclassing from your BaseMyEvaluatorClass to override
toString() by using a string method like:
public String toString() {
return getValueType().getName() + " " +
getOperator().getOperatorString();
}
Regarding the evaluator API:
If you only need one evaluator class (subclassed from BaseEvaluator),
personally I don't like the > 10 static calls to
addEvaluator(type, operator, myEvaluatorInstance)
in the EvaluatorDefinition class.
So, how about adding the method addDefaultEvaluator(operator,
evaluatorClass) to EvaluatorCache, see attachment?
This would allow you to register a evaluator as default and only overide
the special cases...
PS: If you are interested I will write some small tutorial about custom
evaluators / operators in drools trunk. This might take a week or two,
though. Any preferences regarding the format?
Thanks for the help....
cu, Michael
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: addDefaultEvaluator.txt
Url: http://lists.jboss.org/pipermail/rules-users/attachments/20080917/c5187094/attachment.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EvaluatorCache.java
Type: text/x-java
Size: 6275 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20080917/c5187094/attachment.bin
More information about the rules-users
mailing list