1 22 package org.aspectj.tools.ajdoc.rootmakers; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 27 import org.aspectj.tools.ajdoc.ErrPrinter; 28 29 35 public abstract class Javadoc { 36 37 38 protected ErrPrinter err; 39 40 41 public Javadoc() {} 42 43 44 56 protected final Object invoke(Method method, Object owner, Object [] args) { 57 if (method == null || owner == null) return null; 58 String classname = owner.getClass().getName(); 59 String methodName = method.getName(); 60 try { 61 Thread.currentThread().setContextClassLoader 62 (owner.getClass().getClassLoader()); 63 return method.invoke(owner, args); 64 } catch (InvocationTargetException e) { 65 err.invocationTargetException(e, classname, methodName); 66 } catch (IllegalAccessException e) { 67 err.ex(e, "method_not_accessible", classname, methodName); 68 } catch (Exception e) { 69 err.ex(e, "exception_thrown", "List", 70 classname, methodName, e != null ? e.getMessage() : e+""); 71 } 72 return null; 73 } 74 75 83 protected final Class type(String classname) { 84 try { 85 return Class.forName(classname); 86 } catch (ClassNotFoundException e) { 87 err.ex(e, "class_not_found", "Hashtable", classname); 88 } 89 return null; 90 } 91 92 104 protected final Method method(String name, Class [] params, Class type) { 105 if (type == null) return null; 106 try { 107 return type.getMethod(name, params); 108 } catch (NoSuchMethodException e) { 109 err.ex(e, "method_not_found", type.getClass().getName(), name); 110 } 111 return null; 112 } 113 114 125 protected final Object newInstance(String classname) { 126 return newInstance(type(classname)); 127 } 128 129 139 protected final Object newInstance(Class type) { 140 if (type == null) return null; 141 try { 142 return type.newInstance(); 143 } catch (InstantiationException e) { 144 err.ex(e, "must_have_default_ctor", type.getClass().getName()); 145 return null; 146 } catch (IllegalAccessException e) { 147 err.ex(e, "method_not_accessible", type.getClass().getName(), "new()"); 148 return null; 149 } 150 } 151 } 152 | Popular Tags |