%@ page import="
javax.naming.InitialContext,
javax.naming.Context,
javax.naming.*,
java.util.Properties,
javax.naming.Context,
javax.naming.InitialContext,
javax.servlet.ServletConfig,
javax.servlet.ServletException,
javax.servlet.http.HttpServlet,
javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse,
java.io.PrintWriter,
java.io.*,
java.lang.reflect.Method
"%>
OpenEJB Tomcat Integration/1.0
<%!
String ctxID;
Context ctx;
class Node {
static final int CONTEXT = 1;
static final int BEAN = 2;
static final int OTHER = 3;
Node parent;
Node[] children = new Node[0];
String name;
int type = 0;
public String getID(){
if (parent instanceof RootNode) {
return name;
} else {
return parent.getID()+"/"+name;
}
}
public String getName(){
return name;
}
public int getType(){
return type;
}
public void addChild(Node child){
int len = children.length;
Node[] newChildren = new Node[len+1];
System.arraycopy(children,0,newChildren,0,len);
newChildren[len] = child;
children = newChildren;
child.parent = this;
}
}
class RootNode extends Node{
public String getID() {
return "";
}
public String getName() {
return "";
}
public int getType() {
return Node.CONTEXT;
}
}
public void buildNode(Node parent, Context ctx) throws Exception{
if (false) throw new NullPointerException();
NamingEnumeration enum = ctx.list( "" );
while (enum.hasMoreElements()){
NameClassPair pair = (NameClassPair)enum.next();
Node node = new Node();
parent.addChild(node);
node.name = pair.getName();
Object obj = ctx.lookup(node.getName());
if ( obj instanceof Context ){
node.type = Node.CONTEXT;
buildNode(node,(Context)obj);
} else if (obj instanceof java.rmi.Remote) {
node.type = Node.BEAN;
} else {
node.type = Node.OTHER;
}
}
}
String openImg = "";
String closedImg = "";
String ejbImg = "";
String javaImg = "";
public void printNodes(Node node, javax.servlet.jsp.JspWriter out, String tabs, String selected) throws Exception {
switch (node.getType()) {
case Node.CONTEXT: printContextNode(node,out,tabs,selected); break;
case Node.BEAN: printBeanNode(node,out,tabs,selected); break;
default: printOtherNode(node,out,tabs,selected); break;
}
}
public void printContextNode(Node node, javax.servlet.jsp.JspWriter out, String tabs, String selected) throws Exception {
String id = node.getID();
if ( selected.startsWith(id) ) {
if (ctxID != null) {
out.print(tabs+""+openImg+" "+node.getName()+"
");
} else {
out.print(tabs+""+openImg+" "+node.getName()+"
");
}
for (int i=0; i < node.children.length; i++){
Node child = node.children[i];
printNodes(child,out,tabs+" ",selected);
}
} else {
if (ctxID != null) {
out.print(tabs+""+closedImg+" "+node.getName()+"
");
} else {
out.print(tabs+""+closedImg+" "+node.getName()+"
");
}
}
}
public void printBeanNode(Node node, javax.servlet.jsp.JspWriter out, String tabs, String selected) throws Exception {
String id = node.getID();
if (ctxID != null && ctxID.startsWith("enc")) {
// HACK!
try{
Object ejb = ctx.lookup(id);
Object handler = org.openejb.util.proxy.ProxyManager.getInvocationHandler(ejb);
Object deploymentID = ((org.openejb.core.ivm.BaseEjbProxyHandler)handler).deploymentID;
out.print(tabs+""+ejbImg+" "+node.getName()+"
");
} catch (Exception e){
out.print(tabs+ejbImg+" "+node.getName()+"
");
}
} else {
out.print(tabs+""+ejbImg+" "+node.getName()+"
");
}
}
public void printOtherNode(Node node, javax.servlet.jsp.JspWriter out, String tabs, String selected) throws Exception {
String id = node.getID();
Object obj = ctx.lookup(id);
String clazz = obj.getClass().getName();
out.print(tabs+""+javaImg+" "+node.getName()+"
");
}
%>