<div dir="ltr"><br>&nbsp;&nbsp; Hi Michael,<br><br>&nbsp;&nbsp; All good suggestions. I will create a JIRA with them and apply as soon as possible.<br><br>&nbsp;&nbsp; Regarding the tutorial, it would be great. We can add it to the Drools documentation with proper credits to you!<br>
<br>&nbsp;&nbsp; Thanks,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson<br><br><div class="gmail_quote">2008/9/17 Michael Zimmermann <span dir="ltr">&lt;<a href="mailto:list@incunabulum.de">list@incunabulum.de</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Edson,<br>
<br>
I think I got it working :-)<br>
<div class="Ih2E3d"><br>
Edson Tirelli wrote:<br>
&gt; For an example, look at the file SetEvaluatorsDefinition and look at<br>
&gt; the BaseMemberOf inner class. So, all the logic is in there, but we<br>
&gt; still used subclasses just to set the constructor attributes and<br>
&gt; override the toString() method, but you could still implement<br>
&gt; everything in a single class I guess.<br>
<br>
</div>Yes, this approach makes sense as long as you don&#39;t need to use the<br>
different VariableContextEntry subclasses for handling double, char etc.<br>
Yet, this can be handled, too.<br>
<br>
toString():<br>
You can avoid subclassing from your BaseMyEvaluatorClass to override<br>
toString() by using a string method like:<br>
<br>
public String toString() {<br>
 &nbsp;return getValueType().getName() + &quot; &quot; +<br>
 &nbsp; &nbsp; &nbsp; &nbsp; getOperator().getOperatorString();<br>
}<br>
<br>
Regarding the evaluator API:<br>
If you only need one evaluator class (subclassed from BaseEvaluator),<br>
personally I don&#39;t like the &gt; 10 static calls to<br>
 &nbsp; &nbsp;addEvaluator(type, operator, myEvaluatorInstance)<br>
in the EvaluatorDefinition class.<br>
<br>
So, how about adding the method addDefaultEvaluator(operator,<br>
evaluatorClass) to EvaluatorCache, see attachment?<br>
This would allow you to register a evaluator as default and only overide<br>
the special cases...<br>
<br>
<br>
PS: If you are interested I will write some small tutorial about custom<br>
evaluators / operators in drools trunk. This might take a week or two,<br>
though. Any preferences regarding the format?<br>
<br>
Thanks for the help....<br>
<br>
cu, Michael<br>
<br>
<br>@SuppressWarnings(&quot;unchecked&quot;)<br>
public void addDefaultEvaluator(final Operator operator, Class evaluatorClass) {<br>
// define the constructor<br>
Class[] evaluatorParameters = new Class[2];<br>
evaluatorParameters[0] = ValueType.class;<br>
evaluatorParameters[1] = Operator.class;<br>
<br>
// get the constructor<br>
 &nbsp; &nbsp; &nbsp; &nbsp;try {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;Constructor&lt;BaseEvaluator&gt; constructor;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;constructor = evaluatorClass.getConstructor( evaluatorParameters );<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// add feault operators<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.ARRAY_TYPE, operator, constructor.newInstance(ValueType.ARRAY_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.BIG_DECIMAL_TYPE, operator, constructor.newInstance(ValueType.BIG_DECIMAL_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.BIG_INTEGER_TYPE, operator, constructor.newInstance(ValueType.BIG_INTEGER_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.BOOLEAN_TYPE, operator, constructor.newInstance(ValueType.BOOLEAN_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PBOOLEAN_TYPE, operator, constructor.newInstance(ValueType.PBOOLEAN_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.BYTE_TYPE, operator, constructor.newInstance(ValueType.BYTE_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PBYTE_TYPE, operator, constructor.newInstance(ValueType.PBYTE_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.CHAR_TYPE, operator, constructor.newInstance(ValueType.CHAR_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PCHAR_TYPE, operator, constructor.newInstance(ValueType.PCHAR_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.DATE_TYPE, operator, constructor.newInstance(ValueType.DATE_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.DOUBLE_TYPE, operator, constructor.newInstance(ValueType.DOUBLE_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PDOUBLE_TYPE, operator, constructor.newInstance(ValueType.PDOUBLE_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.FLOAT_TYPE, operator, constructor.newInstance(ValueType.FLOAT_TYPE , operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PFLOAT_TYPE, operator, constructor.newInstance(ValueType.PFLOAT_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.INTEGER_TYPE, operator, constructor.newInstance(ValueType.INTEGER_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PINTEGER_TYPE, operator, constructor.newInstance(ValueType.PINTEGER_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.LONG_TYPE, operator, constructor.newInstance(ValueType.LONG_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PLONG_TYPE, operator, constructor.newInstance(ValueType.PLONG_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.OBJECT_TYPE, operator, constructor.newInstance(ValueType.OBJECT_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.SHORT_TYPE, operator, constructor.newInstance(ValueType.SHORT_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.PSHORT_TYPE, operator, constructor.newInstance(ValueType.PSHORT_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;addEvaluator(ValueType.STRING_TYPE, operator, constructor.newInstance(ValueType.STRING_TYPE, operator));<br>
 &nbsp; &nbsp; &nbsp; &nbsp;} catch (SecurityException e) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TODO Auto-generated catch block<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;} catch (NoSuchMethodException e) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TODO Auto-generated catch block<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;} catch (IllegalArgumentException e) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TODO Auto-generated catch block<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;} catch (InstantiationException e) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TODO Auto-generated catch block<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;} catch (IllegalAccessException e) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TODO Auto-generated catch block<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;} catch (InvocationTargetException e) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// TODO Auto-generated catch block<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;e.printStackTrace();<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
}<br>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>
</div>