| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.validation; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
| 20 | |
import org.kuali.rice.kew.api.validation.RuleValidationContext; |
| 21 | |
import org.kuali.rice.kew.api.validation.ValidationResults; |
| 22 | |
import org.kuali.rice.kew.framework.KewFrameworkServiceLocator; |
| 23 | |
import org.kuali.rice.kew.framework.validation.RuleValidationAttributeExporterService; |
| 24 | |
import org.kuali.rice.kew.rule.RuleValidationAttribute; |
| 25 | |
|
| 26 | |
import java.lang.reflect.InvocationHandler; |
| 27 | |
import java.lang.reflect.Method; |
| 28 | |
import java.lang.reflect.Proxy; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | public class RuleValidationAttributeResolverImpl implements RuleValidationAttributeResolver { |
| 39 | |
@Override |
| 40 | |
public RuleValidationAttribute resolveRuleValidationAttribute(final String attributeName, String applicationId) throws Exception { |
| 41 | 0 | final RuleValidationAttributeExporterService service = findRuleValidationAttributeExporterService(applicationId); |
| 42 | 0 | return (RuleValidationAttribute) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { RuleValidationAttribute.class }, new RuleValidationAttributeInvocationHandler() { |
| 43 | |
@Override |
| 44 | |
protected ValidationResults invokeValidate(RuleValidationContext context) throws Exception { |
| 45 | 0 | return service.validate(attributeName, context); |
| 46 | |
} |
| 47 | |
}); |
| 48 | |
} |
| 49 | |
|
| 50 | |
protected RuleValidationAttributeExporterService findRuleValidationAttributeExporterService(String applicationId) { |
| 51 | 0 | RuleValidationAttributeExporterService service = KewFrameworkServiceLocator.getRuleValidationAttributeExporterService(applicationId); |
| 52 | 0 | if (service == null) { |
| 53 | 0 | throw new WorkflowRuntimeException("Failed to locate RuleValidationAttributeExporterService for applicationId: " + applicationId); |
| 54 | |
} |
| 55 | 0 | return service; |
| 56 | |
} |
| 57 | |
|
| 58 | 0 | protected static abstract class RuleValidationAttributeInvocationHandler implements InvocationHandler { |
| 59 | |
@Override |
| 60 | |
public ValidationResults invoke(Object o, Method method, Object[] objects) throws Throwable { |
| 61 | 0 | if (!StringUtils.equals(method.getName(), "validate")) { |
| 62 | 0 | throw new UnsupportedOperationException("RuleValidationAttribute only supports 'validate'"); |
| 63 | |
} |
| 64 | 0 | return invokeValidate((RuleValidationContext) objects[0]); |
| 65 | |
} |
| 66 | |
protected abstract ValidationResults invokeValidate(RuleValidationContext context) throws Exception; |
| 67 | |
} |
| 68 | |
} |