1 55 package org.jboss.axis.utils.bytecode; 56 57 import org.jboss.axis.utils.Messages; 58 59 import java.io.IOException ; 60 import java.lang.reflect.Method ; 61 import java.lang.reflect.Modifier ; 62 import java.util.HashMap ; 63 import java.util.Map ; 64 65 79 public class ParamReader 80 extends ClassReader 81 { 82 private String methodName; 83 private Map methods = new HashMap (); 84 private Class [] paramTypes; 85 86 93 public ParamReader(Class c) throws IOException 94 { 95 this(getBytes(c)); 96 } 97 98 104 public ParamReader(byte[] b) throws IOException 105 { 106 super(b, findAttributeReaders(ParamReader.class)); 107 108 if (readInt() != 0xCAFEBABE) 110 { 111 throw new IOException (Messages.getMessage("badClassFile00")); 113 } 114 115 readShort(); readShort(); 118 readCpool(); 120 readShort(); readShort(); readShort(); 124 int count = readShort(); for (int i = 0; i < count; i++) 126 { 127 readShort(); } 129 130 count = readShort(); for (int i = 0; i < count; i++) 132 { 133 readShort(); readShort(); readShort(); skipAttributes(); } 138 139 count = readShort(); for (int i = 0; i < count; i++) 141 { 142 readShort(); int m = readShort(); String name = resolveUtf8(m); 145 int d = readShort(); this.methodName = name + resolveUtf8(d); 147 readAttributes(); } 149 150 } 151 152 public void readCode() throws IOException 153 { 154 readShort(); int maxLocals = readShort(); 157 MethodInfo info = new MethodInfo(maxLocals); 158 if (methods != null && methodName != null) 159 { 160 methods.put(methodName, info); 161 } 162 163 skipFully(readInt()); skipFully(8 * readShort()); readAttributes(); 168 } 169 170 179 public String [] getParameterNames(Method method) 180 { 181 paramTypes = method.getParameterTypes(); 182 183 MethodInfo info = (MethodInfo)methods.get(getSignature(method, paramTypes)); 185 186 189 if (info != null) 190 { 191 String [] paramNames = new String [paramTypes.length]; 192 int j = Modifier.isStatic(method.getModifiers()) ? 0 : 1; 193 194 boolean found = false; for (int i = 0; i < paramNames.length; i++) 196 { 197 if (info.names[j] != null) 198 { 199 found = true; 200 paramNames[i] = info.names[j]; 201 } 202 j++; 203 if (paramTypes[i] == double.class || paramTypes[i] == long.class) 204 { 205 j++; 207 } 208 } 209 210 if (found) 211 { 212 return paramNames; 213 } 214 else 215 { 216 return null; 217 } 218 } 219 else 220 { 221 return null; 222 } 223 } 224 225 private static class MethodInfo 226 { 227 String [] names; 228 int maxLocals; 229 230 public MethodInfo(int maxLocals) 231 { 232 this.maxLocals = maxLocals; 233 names = new String [maxLocals]; 234 } 235 } 236 237 private MethodInfo getMethodInfo() 238 { 239 MethodInfo info = null; 240 if (methods != null && methodName != null) 241 { 242 info = (MethodInfo)methods.get(methodName); 243 } 244 return info; 245 } 246 247 252 public void readLocalVariableTable() throws IOException 253 { 254 int len = readShort(); MethodInfo info = getMethodInfo(); 256 for (int j = 0; j < len; j++) 257 { 258 readShort(); readShort(); int nameIndex = readShort(); readShort(); int index = readShort(); if (info != null) 264 { 265 info.names[index] = resolveUtf8(nameIndex); 266 } 267 } 268 } 269 } 270 | Popular Tags |