%@ 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.HttpSession,
javax.servlet.http.HttpServlet,
javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse,
org.openejb.DeploymentInfo,
java.io.PrintWriter,
java.io.*,
java.lang.reflect.Method,
java.lang.reflect.Modifier,
javax.ejb.*,
java.util.HashMap
"%>
OpenEJB Tomcat Integration/1.0
<%!
String tab = " ";
public void printEjb(String name, javax.servlet.jsp.JspWriter out, HttpSession session) throws Exception {
String id = (name.startsWith("/"))?name.substring(1,name.length()):name;
org.openejb.DeploymentInfo ejb = org.openejb.OpenEJB.getDeploymentInfo(id);
if (ejb == null) {
out.print("No such EJB: "+id);
return;
}
String type = null;
switch (ejb.getComponentType()) {
case org.openejb.core.DeploymentInfo.CMP_ENTITY :
type = "EntityBean with Container-Managed Persistence";
break;
case org.openejb.core.DeploymentInfo.BMP_ENTITY :
type = "EntityBean with Bean-Managed Persistence";
break;
case org.openejb.core.DeploymentInfo.STATEFUL :
type = "Stateful SessionBean";
break;
case org.openejb.core.DeploymentInfo.STATELESS :
type = "Stateless SessionBean";
break;
default :
type = "Unkown Bean Type";
break;
}
out.print(""+type+"
");
out.print("");
printRow("JNDI Name",name,out);
printRow("Remote Interface", getClassRef(ejb.getRemoteInterface()) ,out);
printRow("Home Interface", getClassRef(ejb.getHomeInterface()) ,out);
printRow("Bean Class", getClassRef(ejb.getBeanClass()) ,out);
if (ejb.getComponentType() == DeploymentInfo.BMP_ENTITY ||
ejb.getComponentType() == DeploymentInfo.CMP_ENTITY ) {
printRow("Primary Key", getClassRef(ejb.getPrimaryKeyClass()) ,out);
}
String pepperImg = "";
out.print("
");
out.print("
Actions:
");
out.print("");
// Browse JNDI with this ejb
//javax.servlet.http.HttpSession session = this.session;
HashMap objects = (HashMap)session.getAttribute("objects");
if (objects == null) {
objects = new HashMap();
session.setAttribute("objects",objects);
}
InitialContext ctx;
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory");
p.put("openejb.loader", "embed");
ctx = new InitialContext( p );
Object obj = ctx.lookup(name);
String objID = ejb.getHomeInterface().getName()+"@"+obj.hashCode();
objects.put(objID,obj);
String invokerURL = "Invoke this EJB";
printRow(pepperImg,invokerURL, out);
Context enc = ((org.openejb.core.DeploymentInfo)ejb).getJndiEnc();
String ctxID = "enc"+enc.hashCode();
session.setAttribute(ctxID, enc);
String jndiURL = "Browse this EJB's private JNDI namespace";
printRow(pepperImg,jndiURL, out);
out.print("
");
}
protected void printRow(String col1, String col2, javax.servlet.jsp.JspWriter out) throws IOException{
out.print("" );
out.print(col1);
out.print(" | ");
out.print(col2);
out.print(" |
");
}
public String getClassRef(Class clazz) throws Exception {
String name = clazz.getName();
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+"";
}
}
%>