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