001
014
015 package com.liferay.portal.kernel.messaging.proxy;
016
017 import com.liferay.portal.kernel.util.MethodInvoker;
018 import com.liferay.portal.kernel.util.MethodWrapper;
019 import com.liferay.portal.kernel.util.NullWrapper;
020
021 import java.io.Serializable;
022
023 import java.lang.reflect.InvocationTargetException;
024 import java.lang.reflect.Method;
025
026
031 public class ProxyRequest implements Serializable {
032
033 public ProxyRequest(Method method, Object[] arguments) throws Exception {
034 Class<?>[] argumentTypes = method.getParameterTypes();
035
036 for (int i = 0; i < arguments.length; i++) {
037 if (arguments[i] == null) {
038 arguments[i] = new NullWrapper(argumentTypes[i].getName());
039 }
040 }
041
042 _methodWrapper = new MethodWrapper(method, arguments);
043
044 _hasReturnValue = false;
045
046 if (method.getReturnType() != Void.TYPE) {
047 _hasReturnValue = true;
048 }
049
050 MessagingProxy messagingProxy = method.getAnnotation(
051 MessagingProxy.class);
052
053 if (messagingProxy == null) {
054 messagingProxy = method.getDeclaringClass().getAnnotation(
055 MessagingProxy.class);
056 }
057
058 if ((messagingProxy != null) &&
059 (messagingProxy.mode().equals(ProxyMode.SYNC))) {
060
061 _synchronous = true;
062 }
063 }
064
065 public Object execute(Object object) throws Exception {
066 try {
067 return MethodInvoker.invoke(_methodWrapper, object);
068 }
069 catch (InvocationTargetException ite) {
070 Throwable t = ite.getCause();
071
072 if (t instanceof Exception) {
073 throw (Exception)t;
074 }
075 else {
076 throw new Exception(t);
077 }
078 }
079 }
080
081 public MethodWrapper getMethodWrapper() {
082 return _methodWrapper;
083 }
084
085 public boolean hasReturnValue() {
086 return _hasReturnValue;
087 }
088
089 public boolean isSynchronous() {
090 return _synchronous;
091 }
092
093 private boolean _hasReturnValue;
094 private MethodWrapper _methodWrapper;
095 private boolean _synchronous;
096
097 }