org/objectweb/proactive/core/body/http/util/messages/BodyRequest.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.body.http.util.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.Body;
00040 import org.objectweb.proactive.core.UniqueID;
00041 import org.objectweb.proactive.core.body.http.util.HttpUtils;
00042 import org.objectweb.proactive.ext.security.exceptions.SecurityNotAvailableException;
00043 
00044 
00050 public class BodyRequest extends ReflectRequest implements Serializable {
00051     private static HashMap hMapMethods;
00052 
00053     static {
00054         hMapMethods = getHashMapReflect(Body.class);
00055     }
00056 
00057     private String methodName;
00058     private ArrayList parameters = new ArrayList();
00059     private UniqueID oaid;
00060     private Body body = null;
00061 
00068     public BodyRequest(String methodName, ArrayList parameters, UniqueID oaid,
00069         String url) {
00070         super(url);
00071         this.methodName = methodName;
00072         this.parameters = parameters;
00073         this.oaid = oaid;
00074     }
00075 
00076     public String getMethodName() {
00077         return this.methodName;
00078     }
00079 
00080     public Object getReturnedObject() throws Exception {
00081         if (this.returnedObject instanceof Exception) {
00082             //            System.out.println("J'ai choppe une exception ( " + ClassServer.getUrl() + ")");
00083             throw (Exception) this.returnedObject;
00084         }
00085         return this.returnedObject;
00086     }
00087 
00095     public Object processMessage() throws Exception {
00096         Object result = null;
00097 
00098         if (body == null) {
00099             this.body = HttpUtils.getBody(this.oaid);
00100         }
00101 
00102         //System.out.println("invocation de la methode");
00103         Method m = getProActiveRuntimeMethod(methodName, parameters,
00104                 hMapMethods.get(methodName));
00105 
00106         try {
00107             result = m.invoke(body, parameters.toArray());
00108         } catch (IllegalArgumentException e) {
00109             //               e.printStackTrace();
00110             throw e;
00111         } catch (IllegalAccessException e) {
00112             //                e.printStackTrace();
00113             throw e;
00114         } catch (InvocationTargetException e) {
00115             // TODO Auto-generated catch block 
00116             //                e.printStackTrace();
00117             throw new SecurityNotAvailableException(e.getCause());
00118         } catch (Exception e) {
00119 //            System.out.println("----------------------- Exception : " +
00120 //                e.getClass());
00121             throw e;
00122         }
00123 
00124         return result;
00125     }
00126 }

Generated on Mon Jan 22 15:16:05 2007 for ProActive by  doxygen 1.5.1