1
22
23 package com.liferay.portal.kernel.messaging.proxy;
24
25 import com.liferay.portal.kernel.util.MethodInvoker;
26 import com.liferay.portal.kernel.util.MethodWrapper;
27 import com.liferay.portal.kernel.util.NullWrapper;
28
29 import java.io.Serializable;
30
31 import java.lang.reflect.InvocationTargetException;
32 import java.lang.reflect.Method;
33
34
41 public class ProxyRequest implements Serializable {
42
43 public ProxyRequest(Method method, Object[] arguments) throws Exception {
44 Class<?>[] argumentTypes = method.getParameterTypes();
45
46 for (int i = 0; i < arguments.length; i++) {
47 if (arguments[i] == null) {
48 arguments[i] = new NullWrapper(argumentTypes[i].getName());
49 }
50 }
51
52 _methodWrapper = new MethodWrapper(method, arguments);
53
54 _hasReturnValue = false;
55
56 if (method.getReturnType() != Void.TYPE) {
57 _hasReturnValue = true;
58 }
59
60 MessagingProxy messagingProxy = method.getAnnotation(
61 MessagingProxy.class);
62
63 if (messagingProxy == null) {
64 messagingProxy = method.getDeclaringClass().getAnnotation(
65 MessagingProxy.class);
66 }
67
68 if ((messagingProxy != null) &&
69 (messagingProxy.mode().equals(ProxyMode.SYNC))) {
70
71 _synchronous = true;
72 }
73 }
74
75 public Object execute(Object object) throws Exception {
76 try {
77 return MethodInvoker.invoke(_methodWrapper, object);
78 }
79 catch (InvocationTargetException ite) {
80 Throwable t = ite.getCause();
81
82 if (t instanceof Exception) {
83 throw (Exception)t;
84 }
85 else {
86 throw new Exception(t);
87 }
88 }
89 }
90
91 public MethodWrapper getMethodWrapper() {
92 return _methodWrapper;
93 }
94
95 public boolean hasReturnValue() {
96 return _hasReturnValue;
97 }
98
99 public boolean isSynchronous() {
100 return _synchronous;
101 }
102
103 private boolean _hasReturnValue;
104 private MethodWrapper _methodWrapper;
105 private boolean _synchronous;
106
107 }