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