| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.krad.workflow.attribute; |
| 17 | |
|
| 18 | |
import java.lang.reflect.Method; |
| 19 | |
import java.util.HashMap; |
| 20 | |
|
| 21 | |
import net.sf.cglib.proxy.Enhancer; |
| 22 | |
import net.sf.cglib.proxy.InvocationHandler; |
| 23 | |
|
| 24 | |
import org.kuali.rice.core.web.format.BooleanFormatter; |
| 25 | |
import org.kuali.rice.krad.bo.BusinessObject; |
| 26 | |
import org.kuali.rice.krad.util.ObjectUtils; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public class WorkflowLookupableInvocationHandler implements InvocationHandler { |
| 36 | |
private BusinessObject proxiedBusinessObject; |
| 37 | |
private ClassLoader classLoader; |
| 38 | |
|
| 39 | |
private String returnUrl; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 0 | public WorkflowLookupableInvocationHandler(BusinessObject proxiedBusinessObject, ClassLoader classLoader) { |
| 47 | 0 | this.proxiedBusinessObject = proxiedBusinessObject; |
| 48 | 0 | this.classLoader = classLoader; |
| 49 | 0 | } |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | 0 | public WorkflowLookupableInvocationHandler(BusinessObject proxiedBusinessObject, String returnUrl, ClassLoader classLoader) { |
| 58 | 0 | this.proxiedBusinessObject = proxiedBusinessObject; |
| 59 | 0 | this.returnUrl = returnUrl; |
| 60 | 0 | this.classLoader = classLoader; |
| 61 | 0 | } |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
| 73 | 0 | ClassLoader oldClassloader = Thread.currentThread().getContextClassLoader(); |
| 74 | |
try { |
| 75 | 0 | Thread.currentThread().setContextClassLoader(classLoader); |
| 76 | 0 | if ("getReturnUrl".equals(method.getName())) { |
| 77 | 0 | return returnUrl; |
| 78 | |
} |
| 79 | 0 | else if ("getWorkflowLookupableResult".equals(method.getName())) { |
| 80 | 0 | return Enhancer.create(HashMap.class, new Class[] { WorkflowLookupableResult.class }, this); |
| 81 | |
} |
| 82 | 0 | else if ("get".equals(method.getName())) { |
| 83 | 0 | Object propertyValue = ObjectUtils.getNestedValue(proxiedBusinessObject, args[0].toString()); |
| 84 | 0 | if (propertyValue instanceof BusinessObject) { |
| 85 | 0 | return Enhancer.create(propertyValue.getClass(), new WorkflowLookupableInvocationHandler((BusinessObject) propertyValue, classLoader)); |
| 86 | |
} |
| 87 | |
else { |
| 88 | 0 | if (propertyValue instanceof Boolean) { |
| 89 | 0 | return new BooleanFormatter().format(propertyValue); |
| 90 | |
} |
| 91 | 0 | return propertyValue; |
| 92 | |
} |
| 93 | |
} |
| 94 | |
else { |
| 95 | 0 | return method.invoke(proxiedBusinessObject, args); |
| 96 | |
} |
| 97 | |
} |
| 98 | 0 | catch (Exception e) { |
| 99 | 0 | throw (e.getCause() != null ? e.getCause() : e); |
| 100 | |
} |
| 101 | |
finally { |
| 102 | 0 | Thread.currentThread().setContextClassLoader(oldClassloader); |
| 103 | |
} |
| 104 | |
} |
| 105 | |
} |