| ProxyRequest.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
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 /**
35 * <a href="ProxyRequest.java.html"><b><i>View Source</i></b></a>
36 *
37 * @author Micha Kiener
38 * @author Michael C. Han
39 * @author Brian Wing Shun Chan
40 */
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 e) {
80 throw new Exception(e.getTargetException());
81 }
82 }
83
84 public MethodWrapper getMethodWrapper() {
85 return _methodWrapper;
86 }
87
88 public boolean hasReturnValue() {
89 return _hasReturnValue;
90 }
91
92 public boolean isSynchronous() {
93 return _synchronous;
94 }
95
96 private boolean _hasReturnValue;
97 private MethodWrapper _methodWrapper;
98 private boolean _synchronous;
99
100 }