1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.messaging.proxy;
16  
17  import com.liferay.portal.kernel.util.MethodHandler;
18  
19  import java.io.Serializable;
20  
21  import java.lang.reflect.InvocationTargetException;
22  import java.lang.reflect.Method;
23  
24  /**
25   * <a href="ProxyRequest.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Micha Kiener
28   * @author Michael C. Han
29   * @author Brian Wing Shun Chan
30   */
31  public class ProxyRequest implements Serializable {
32  
33      public ProxyRequest(Method method, Object[] arguments) throws Exception {
34          _methodHandler = new MethodHandler(method, arguments);
35  
36          _hasReturnValue = false;
37  
38          if (method.getReturnType() != Void.TYPE) {
39              _hasReturnValue = true;
40          }
41  
42          MessagingProxy messagingProxy = method.getAnnotation(
43              MessagingProxy.class);
44  
45          if (messagingProxy == null) {
46              messagingProxy = method.getDeclaringClass().getAnnotation(
47                  MessagingProxy.class);
48          }
49  
50          if ((messagingProxy != null) &&
51              (messagingProxy.mode().equals(ProxyMode.SYNC))) {
52  
53              _synchronous = true;
54          }
55      }
56  
57      public Object execute(Object object) throws Exception {
58          try {
59              return _methodHandler.invoke(object);
60          }
61          catch (InvocationTargetException ite) {
62              Throwable t = ite.getCause();
63  
64              if (t instanceof Exception) {
65                  throw (Exception)t;
66              }
67              else {
68                  throw new Exception(t);
69              }
70          }
71      }
72  
73      public Object[] getArguments() {
74          return _methodHandler.getArguments();
75      }
76  
77      public boolean hasReturnValue() {
78          return _hasReturnValue;
79      }
80  
81      public boolean isSynchronous() {
82          return _synchronous;
83      }
84  
85      private boolean _hasReturnValue;
86      private MethodHandler _methodHandler;
87      private boolean _synchronous;
88  
89  }