1 16 package org.apache.axis.utils.bytecode; 17 18 import org.apache.axis.utils.Messages; 19 20 import java.io.IOException ; 21 import java.lang.reflect.Method ; 22 import java.lang.reflect.Constructor ; 23 import java.lang.reflect.Member ; 24 import java.lang.reflect.Modifier ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 42 public class ParamReader 43 extends ClassReader { 44 private String methodName; 45 private Map methods = new HashMap (); 46 private Class [] paramTypes; 47 48 54 public ParamReader(Class c) throws IOException { 55 this(getBytes(c)); 56 } 57 58 63 public ParamReader(byte[] b) throws IOException { 64 super(b, findAttributeReaders(ParamReader.class)); 65 66 if (readInt() != 0xCAFEBABE) { 68 throw new IOException (Messages.getMessage("badClassFile00")); 70 } 71 72 readShort(); readShort(); 75 readCpool(); 77 readShort(); readShort(); readShort(); 81 int count = readShort(); for (int i = 0; i < count; i++) { 83 readShort(); } 85 86 count = readShort(); for (int i = 0; i < count; i++) { 88 readShort(); readShort(); readShort(); skipAttributes(); } 93 94 count = readShort(); for (int i = 0; i < count; i++) { 96 readShort(); int m = readShort(); String name = resolveUtf8(m); 99 int d = readShort(); this.methodName = name + resolveUtf8(d); 101 readAttributes(); } 103 104 } 105 106 public void readCode() throws IOException 107 { 108 readShort(); int maxLocals = readShort(); 111 MethodInfo info = new MethodInfo(maxLocals); 112 if (methods != null && methodName != null) 113 { 114 methods.put(methodName, info); 115 } 116 117 skipFully(readInt()); skipFully(8 * readShort()); readAttributes(); 122 } 123 124 132 public String [] getParameterNames(Constructor ctor) { 133 paramTypes = ctor.getParameterTypes(); 134 return getParameterNames(ctor, paramTypes); 135 } 136 137 145 public String [] getParameterNames(Method method) { 146 paramTypes = method.getParameterTypes(); 147 return getParameterNames(method, paramTypes); 148 } 149 150 protected String [] getParameterNames(Member member,Class [] paramTypes) { 151 MethodInfo info = (MethodInfo) methods.get(getSignature(member, paramTypes)); 153 154 157 if (info != null) { 158 String [] paramNames = new String [paramTypes.length]; 159 int j = Modifier.isStatic(member.getModifiers()) ? 0 : 1; 160 161 boolean found = false; for (int i = 0; i < paramNames.length; i++) { 163 if (info.names[j] != null) { 164 found = true; 165 paramNames[i] = info.names[j]; 166 } 167 j++; 168 if (paramTypes[i] == double.class || paramTypes[i] == long.class) { 169 j++; 171 } 172 } 173 174 if (found) { 175 return paramNames; 176 } else { 177 return null; 178 } 179 } else { 180 return null; 181 } 182 } 183 184 private static class MethodInfo 185 { 186 String [] names; 187 int maxLocals; 188 189 public MethodInfo(int maxLocals) 190 { 191 this.maxLocals = maxLocals; 192 names = new String [maxLocals]; 193 } 194 } 195 196 private MethodInfo getMethodInfo() 197 { 198 MethodInfo info = null; 199 if (methods != null && methodName != null) 200 { 201 info = (MethodInfo) methods.get(methodName); 202 } 203 return info; 204 } 205 206 210 public void readLocalVariableTable() throws IOException { 211 int len = readShort(); MethodInfo info = getMethodInfo(); 213 for (int j = 0; j < len; j++) { 214 readShort(); readShort(); int nameIndex = readShort(); readShort(); int index = readShort(); if (info != null) { 220 info.names[index] = resolveUtf8(nameIndex); 221 } 222 } 223 } 224 } 225 | Popular Tags |