Skip to content

Commit

Permalink
Allowing rule to specify a RuleExecutor instance for #60
Browse files Browse the repository at this point in the history
  • Loading branch information
cduplichien committed May 25, 2014
1 parent 5bd6270 commit d9c12e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,11 @@ protected boolean passes(ValidationRule rule, ValidationEvaluationContext contex

// call method
boolean isValid;
RuleExecutor executor = ruleExecutorContainer.getRuleExecutorByName(rule.getType());
RuleExecutor executor = rule.getRuleExecutor();
if (executor == null) {
executor = ruleExecutorContainer.getRuleExecutorByName(rule.getType());
}

try {
// perform conversion on argument
Object convertedRuleArg = convertRuleArgument(ruleArg, executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.ArrayList;

import org.springjutsu.validation.executors.RuleExecutor;

/**
* Java representation of an XML validation rule.
* @author Clark Duplichien
Expand All @@ -37,6 +39,14 @@ public class ValidationRule extends AbstractRuleHolder {
*/
protected String type;

/**
* An actual rule executor implementation,
* as an optional replacement for a String type declaration.
* Useful for creating rules whose logic is defined
* in a lamda expression, or SPEL expression (future feature).
*/
protected RuleExecutor<?, ?> ruleExecutor;

/**
* This is the argument to be passed
* to the rule executor.
Expand Down Expand Up @@ -160,6 +170,14 @@ public void setType(String type) {
this.type = type;
}

public RuleExecutor<?, ?> getRuleExecutor() {
return ruleExecutor;
}

public void setRuleExecutor(RuleExecutor<?, ?> ruleExecutor) {
this.ruleExecutor = ruleExecutor;
}

/**
* @return the value / argument
*/
Expand Down

0 comments on commit d9c12e9

Please sign in to comment.