00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030  
00031 package org.objectweb.proactive.core.runtime.http.messages;
00032 
00033 import java.io.Serializable;
00034 import java.lang.reflect.InvocationTargetException;
00035 import java.lang.reflect.Method;
00036 import java.util.ArrayList;
00037 import java.util.HashMap;
00038 
00039 import org.objectweb.proactive.core.body.http.util.messages.ReflectRequest;
00040 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
00041 
00042 
00049 public class RuntimeRequest extends ReflectRequest implements Serializable {
00050     private String methodName;
00051     private ArrayList<Object> parameters = new ArrayList<Object>();
00052     private static HashMap hMapMethods;
00053     private static ProActiveRuntimeImpl runtime;
00054 
00055     static {
00056         
00057         
00058         
00059         runtime = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00060         hMapMethods = getHashMapReflect(runtime.getClass());
00061     }
00062 
00063     public RuntimeRequest(String newmethodName, String url) {
00064         super(url);
00065         this.methodName = newmethodName;
00066     }
00067 
00068     public Object getReturnedObject() throws Exception {
00069         if (this.returnedObject instanceof Exception) {
00070             throw (Exception) this.returnedObject;
00071         }
00072         return this.returnedObject;
00073     }
00074 
00075     public RuntimeRequest(String newmethodName, ArrayList<Object> newparameters,
00076         String url) {
00077         this(newmethodName, url);
00078         this.parameters = newparameters;
00079     }
00080 
00081     public RuntimeRequest(String newmethodName, ArrayList<Object> newparameters,
00082         ArrayList newparamsTypes, String url) {
00083         this(newmethodName, newparameters, url);
00084     }
00085 
00086     public Object processMessage() throws Exception {
00087         Object[] params = parameters.toArray();
00088         Object result = null;
00089 
00090         Method m = getProActiveRuntimeMethod(methodName, parameters,
00091                 hMapMethods.get(methodName));
00092         try {
00093             result = m.invoke(runtime, parameters.toArray());
00094         } catch (IllegalArgumentException e) {
00095             
00096             
00097             
00098             throw e;
00099         } catch (IllegalAccessException e) {
00100             
00101             
00102             
00103             throw e;
00104         } catch (InvocationTargetException e) {
00105             
00106             
00107             
00108             
00109             throw (Exception) e.getCause();
00110         } catch (Exception e) {
00111             
00112             throw e;
00113         }
00114         return result;
00115     }
00116 
00117     public String getMethodName() {
00118         return this.methodName;
00119     }
00120 
00121     public ArrayList getParameters() {
00122         return this.parameters;
00123     }
00124 
00125     public String toString() {
00126         return "[ " + methodName + " ( " + parameters + " )" + " ]";
00127     }
00128 }