%@ page import="
org.apache.openejb.BeanType,
org.apache.openejb.BeanContext,
org.apache.openejb.loader.SystemInstance,
org.apache.openejb.spi.ContainerSystem,
javax.naming.Context,
javax.naming.InitialContext
"%>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpSession" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Properties" %>
<%@ page import="java.lang.reflect.Field" %>
<%@ page import="java.lang.reflect.Method" %>
OpenEJB/Tomcat
<%!
private BeanContext getDeployment(String deploymentID) {
try {
ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
BeanContext ejb = containerSystem.getBeanContext(deploymentID);
return ejb;
} catch (Exception e) {
return null;
}
}
String tab = " ";
public void printEjb(String name,String jndiName, String contextID, javax.servlet.jsp.JspWriter out, HttpSession session) throws Exception {
String id = (name.startsWith("/")) ? name.substring(1, name.length()) : name;
BeanContext ejb = getDeployment(id);
if (ejb == null) {
out.print("No such EJB: " + id);
return;
}
String type = null;
switch (ejb.getComponentType()) {
case CMP_ENTITY:
type = "EntityBean with Container-Managed Persistence";
break;
case BMP_ENTITY:
type = "EntityBean with Bean-Managed Persistence";
break;
case STATEFUL:
type = "Stateful SessionBean";
break;
case STATELESS:
type = "Stateless SessionBean";
break;
case SINGLETON:
type = "Singleton SessionBean";
break;
case MANAGED:
type = "Managed SessionBean";
break;
default:
type = "Unkown Bean Type";
break;
}
out.print("" + type + "
");
out.print("");
printRow("JNDI Name", jndiName, out);
if(ejb.getRemoteInterface() != null)
printRow("Remote Interface", getClassRef(ejb.getRemoteInterface(),session), out);
if(ejb.getHomeInterface() != null)
printRow("Home Interface", getClassRef(ejb.getHomeInterface(),session), out);
if(ejb.getBeanClass() != null)
printRow("Bean Class", getClassRef(ejb.getBeanClass(),session), out);
if(ejb.getBusinessLocalInterfaces().size() > 0)
printRow("Business Local Interfaces", getClassRefs(ejb.getBusinessLocalInterfaces(),session), out);
if(ejb.getBusinessRemoteInterfaces().size() > 0)
printRow("Business Remote Interfaces", getClassRefs(ejb.getBusinessRemoteInterfaces(),session), out);
if (ejb.getComponentType() == BeanType.BMP_ENTITY || ejb.getComponentType() == BeanType.CMP_ENTITY) {
printRow("Primary Key", getClassRef(ejb.getPrimaryKeyClass(),session), out);
}
String pepperImg = "
";
out.print("
");
out.print("
Actions:
");
out.print("");
// Browse JNDI with this ejb
//javax.servlet.http.HttpSession session = this.session;
//noinspection unchecked
Map objects = (Map) session.getAttribute("objects");
if (objects == null) {
objects = new HashMap();
session.setAttribute("objects", objects);
}
Context ctx;
if(contextID == null){
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
p.put("openejb.loader", "embed");
ctx = new InitialContext(p);
}else{
ctx = (Context)session.getAttribute(contextID);
}
Object obj = ctx.lookup(jndiName);
// String objID = ejb.getHomeInterface().getName() + "@" + obj.hashCode();
String objID = ""+obj.hashCode(); //TODO: Not the best of the ID's, more meaningful ID would be better. Right now hashcode would suffice
objects.put(objID, obj);
String invokerURL = "Invoke this EJB";
printRow(pepperImg, invokerURL, out);
Context enc = 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, HttpSession session) throws Exception {
String name = clazz.getName();
session.setAttribute(name,clazz);
return "" + name + "";
}
public String getClassRefs(List classes, HttpSession session) throws Exception{
String refs = "";
for(Class clazz: classes){
refs += getClassRef(clazz,session)+"
";
}
return refs;
}
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 + "";
}
}
%>