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.body.http.util.messages;
00032
00033 import java.lang.reflect.Method;
00034 import java.util.ArrayList;
00035 import java.util.HashMap;
00036
00037 import org.apache.log4j.Logger;
00038 import org.objectweb.proactive.core.body.http.util.HttpMessage;
00039 import org.objectweb.proactive.core.util.log.Loggers;
00040 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00041
00042
00046 public abstract class ReflectRequest extends HttpMessage {
00047 private static Logger logger = ProActiveLogger.getLogger(Loggers.HTTP_TRANSPORT);
00048
00049 public ReflectRequest(String url) {
00050 super(url);
00051 }
00052
00058 protected static HashMap<String, Object> getHashMapReflect(Class theclass) {
00059
00060
00061
00062 Method[] allmethods = theclass.getMethods();
00063 int numberOfMethods = allmethods.length;
00064 HashMap<String, Object> hMapMethods = new HashMap<String, Object>(numberOfMethods);
00065
00066 for (int i = 0; i < numberOfMethods; i++) {
00067 String methodname = allmethods[i].getName();
00068
00069 if (hMapMethods.containsKey(methodname)) {
00070 Object obj = hMapMethods.get(methodname);
00071
00072 if (!(obj instanceof ArrayList)) {
00073 ArrayList<Method> array = new ArrayList<Method>();
00074 array.add((Method) obj);
00075 array.add(allmethods[i]);
00076 hMapMethods.put(methodname, array);
00077 } else {
00078 ((ArrayList<Method>) obj).add(allmethods[i]);
00079 hMapMethods.put(methodname, (ArrayList<Method>) obj);
00080 }
00081 } else {
00082 hMapMethods.put(methodname, allmethods[i]);
00083 }
00084 }
00085
00086 return hMapMethods;
00087 }
00088
00096 protected Method getProActiveRuntimeMethod(String methodsearch,
00097 ArrayList paramsearch, Object hashobjet) {
00098 Object mret = hashobjet;
00099
00100 if (mret instanceof ArrayList) {
00101 ArrayList allSameMethod = (ArrayList) ((ArrayList) mret).clone();
00102
00103 int sameMethodSize = allSameMethod.size();
00104 int paramsearchsize = paramsearch.size();
00105
00106 for (int i = sameMethodSize - 1; i >= 0; i--) {
00107 if (((Method) allSameMethod.get(i)).getParameterTypes().length != paramsearchsize) {
00108 allSameMethod.remove(i);
00109 }
00110 }
00111
00112 sameMethodSize = allSameMethod.size();
00113
00114 if (sameMethodSize == 1) {
00115 mret = allSameMethod.get(0);
00116 } else {
00117 Class[] paramtypes = null;
00118 boolean isgood = true;
00119 boolean ispossible = true;
00120
00121 for (int i = sameMethodSize - 1; i >= 0; i--) {
00122 paramtypes = ((Method) allSameMethod.get(i)).getParameterTypes();
00123
00124 for (int j = 0; j < paramsearchsize; j++) {
00125 Class<? extends Object> classtest = paramsearch.get(j).getClass();
00126
00127 if (paramtypes[j] != classtest) {
00128 isgood = false;
00129
00130 if (classtest.isAssignableFrom(paramtypes[j]) == false) {
00131 ispossible = false;
00132
00133 break;
00134 }
00135 }
00136 }
00137
00138 if (isgood == true) {
00139 mret = allSameMethod.get(i);
00140
00141 break;
00142 } else if (ispossible == false) {
00143 allSameMethod.remove(i);
00144 }
00145
00146 isgood = true;
00147 ispossible = true;
00148 }
00149 }
00150
00151 if (allSameMethod.size() == 1) {
00152 mret = allSameMethod.get(0);
00153 } else {
00154 logger.error(
00155 "----------------------------------------------------------------------------");
00156 logger.error(
00157 "----- ERROR : two functions in ProActiveRuntimeImpl can t have the same name");
00158 logger.error(
00159 "----- ERROR : and the same type of paramters (Extends Implements)");
00160 logger.error("----- search : " + methodsearch + " nb param " +
00161 paramsearch.size());
00162 logger.error(
00163 "----------------------------------------------------------------------------");
00164 }
00165 } else if (mret == null) {
00166 logger.error(
00167 "----------------------------------------------------------------------------");
00168 logger.error("----- ERROR : no method (invoke) find ");
00169 logger.error("----- search : " + methodsearch + " nb param " +
00170 paramsearch.size());
00171 logger.error(
00172 "----------------------------------------------------------------------------");
00173 }
00174
00175 return (Method) mret;
00176 }
00177 }