1 package org.apache.ws.jaxme.js.pattern; 2 3 import java.lang.reflect.Method ; 4 5 import org.apache.ws.jaxme.js.JavaMethod; 6 import org.apache.ws.jaxme.js.JavaQNameImpl; 7 import org.apache.ws.jaxme.js.JavaSource; 8 import org.apache.ws.jaxme.js.JavaSourceFactory; 9 10 11 13 public class CompiledClassReflector implements Reflector { 14 private final Class compiledClass; 15 16 20 public CompiledClassReflector(Class pClass) { 21 compiledClass = pClass; 22 } 23 24 28 public CompiledClassReflector(String pName, ClassLoader pClassLoader) 29 throws ClassNotFoundException { 30 this(pClassLoader.loadClass(pName)); 31 } 32 33 36 protected JavaMethod getMethod(JavaSource pSource, Method pMethod) { 37 JavaMethod method = pSource.newJavaMethod(pMethod.getName(), 38 JavaQNameImpl.getInstance(pMethod.getReturnType()), 39 JavaSource.PUBLIC); 40 Class [] classes = pMethod.getParameterTypes(); 41 for (int i = 0; i < classes.length; i++) { 42 method.addParam(classes[i], "arg" + i); 43 } 44 Class [] exceptions = pMethod.getExceptionTypes(); 45 for (int i = 0; i < exceptions.length; i++) { 46 method.addThrows(exceptions[i]); 47 } 48 return method; 49 } 50 51 53 public Class getCompiledClass() { 54 return compiledClass; 55 } 56 57 60 public JavaSource getJavaSource(JavaSourceFactory pFactory) { 61 Class c = getCompiledClass(); 62 JavaSource js = new JavaSourceFactory().newJavaSource(JavaQNameImpl.getInstance(c.getName(), true)); 63 Method [] methods = c.getMethods(); 64 for (int i = 0; i < methods.length; i++) { 65 Method m = methods[i]; 66 getMethod(js, m); 67 } 68 return js; 69 } 70 } 71 | Popular Tags |