thrownewIllegalArgumentException("Condition method "+conditionMethod+" defined in rule "+rule+" must be public, have no parameters and return boolean type.");
thrownewIllegalArgumentException("Rule "+rule+" have more than one method annotated with "+Priority.class.getClass());
}
//exactly one method annotated with @Priority
if(!priorityMethods.isEmpty()){
MethodpriorityMethod=priorityMethods.get(0);
if(!isPriorityMethodWellDefined(priorityMethod)){
thrownewIllegalArgumentException("Priority method "+priorityMethod+" defined in rule "+rule+" must be public, have no parameters and return integer type.");
}
try{
priority=(Integer)priorityMethod.invoke(rule);
}catch(IllegalAccessExceptione){
thrownewIllegalArgumentException("Unable to access method "+priorityMethod+" to get priority of rule "+rule,e);
}catch(InvocationTargetExceptione){
thrownewIllegalArgumentException("Unable to invoke method "+priorityMethod+" to get priority of rule "+rule,e);
}
}
intpriority=getPriority(rule);
ruleBeans.add(newRuleBean(priority,rule));
}
@ -231,6 +187,72 @@ public class AnnotatedRulesEngine extends AbstractRulesEngine<Object> {
*PrivateUtilitymethods
*/
privatevoidcheckRuleClass(Objectrule){
//check if the rule class is annotated with @Rule
if(!isRuleClassWellDefined(rule)){
thrownewIllegalArgumentException(String.format("Rule '%s' is not annotated with '%s'",rule,Rule.class.getClass()));
}
}
privatevoidcheckConditionMethod(Objectrule){
//check if condition method is well defined
MethodconditionMethod=getConditionMethod(rule);
if(null==conditionMethod){
thrownewIllegalArgumentException(String.format("Rule '%s' does not have a public method annotated with '%s'",rule,Condition.class.getClass()));
thrownewIllegalArgumentException(String.format("Condition method '%s' defined in rule '%s' must be public, have no parameters and return boolean type.",conditionMethod,rule));
thrownewIllegalArgumentException(String.format("Priority method '%s' defined in rule '%s' must be public, have no parameters and return integer type.",priorityMethod,rule));
}
try{
priority=(Integer)priorityMethod.invoke(rule);
}catch(IllegalAccessExceptione){
thrownewIllegalArgumentException(String.format("Unable to access method '%s' to get priority of rule '%s'",priorityMethod,rule),e);
}catch(InvocationTargetExceptione){
thrownewIllegalArgumentException(String.format("Unable to invoke method '%s' to get priority of rule '%s'",priorityMethod,rule),e);