%@ page import="
java.lang.reflect.Method,
java.lang.reflect.Modifier
"%>
OpenEJB Tomcat Integration/1.0
<%!
String tab = " ";
boolean hasMethods;
public void printClass(Class clazz, javax.servlet.jsp.JspWriter out) throws Exception {
out.print(""+clazz.getName()+" ");
Method[] methods = clazz.getDeclaredMethods();
hasMethods = (methods.length > 0);
for (int i=0; i < methods.length; i++){
printMethod( methods[i], out );
}
/* //out.print(" Public Methods: ");
for (int i=0; i < methods.length; i++){
if (Modifier.isPublic(methods[i].getModifiers())){
printMethod( methods[i], out );
}
}
//out.print(" Private Methods: ");
for (int i=0; i < methods.length; i++){
if (Modifier.isPrivate(methods[i].getModifiers())){
printMethod( methods[i], out );
}
}
for (int i=0; i < methods.length; i++){
if (Modifier.isProtected(methods[i].getModifiers())){
printMethod( methods[i], out );
}
}
for (int i=0; i < methods.length; i++){
if (!Modifier.isSrict(methods[i].getModifiers())){
printMethod( methods[i], out );
}
}
*/
Class sup = clazz.getSuperclass();
if (sup != null) {
out.print("Extends: ");
out.print(tab+getClassRef(sup)+" ");
}
Class[] intf = clazz.getInterfaces();
if (intf.length > 0) {
out.print("Implements: ");
for (int i=0; i < intf.length; i++){
out.print(tab+getClassRef(intf[i])+" ");
}
}
}
public void printMethod(Method m, javax.servlet.jsp.JspWriter out) throws Exception {
out.print(tab);
out.print(" "+getModifier(m));
out.print(" "+getShortClassRef(m.getReturnType())+" ");
out.print(""+m.getName()+" ");
Class[] params = m.getParameterTypes();
out.print("( ");
for (int j=0; j < params.length; j++){
out.print(getShortClassRef(params[j]));
if (j != params.length-1) {
out.print(", ");
}
}
out.print(") ");
Class[] excp = m.getExceptionTypes();
if (excp.length > 0) {
out.print(" throws ");
for (int j=0; j < excp.length; j++){
out.print(getShortClassRef(excp[j]));
if (j != excp.length-1) {
out.print(", ");
}
}
}
out.print(" ");
}
public String getModifier(Method m) throws Exception {
int mod = m.getModifiers();
String color = "";
if (Modifier.isPublic(mod)) {
color = "green";
} else if (Modifier.isPrivate(mod)) {
color = "red";
} else if (Modifier.isProtected(mod)) {
color = "blue";
} else {
color = "yellow";
}
return "* ";
}
public String getClassRef(Class clazz) throws Exception {
String name = clazz.getName();
return ""+name+" ";
}
public String getClassRef(String name) throws Exception {
return ""+name+" ";
}
public String getShortClassRef(Class clazz) throws Exception {
if (clazz.isPrimitive()) {
return ""+clazz.getName()+" ";
} else if (clazz.isArray() && clazz.getComponentType().isPrimitive()) {
return ""+clazz.getComponentType()+"[] ";
} else if (clazz.isArray()) {
String name = clazz.getComponentType().getName();
int dot = name.lastIndexOf(".")+1;
String shortName = name.substring(dot,name.length());
return ""+shortName+"[] ";
} else {
String name = clazz.getName();
int dot = name.lastIndexOf(".")+1;
String shortName = name.substring(dot,name.length());
return ""+shortName+" ";
}
}
%>