public String listXML() {
StringBuffer buffer = new StringBuffer(4096);
Set ejbModules = null;
Context context = null;
ClassLoader currentLoader = Thread.currentThread().getContextClassLoader();
openJndiTag(buffer);
try
{
// Get all deployed web applications so that we can list their
// java: namespaces which are ClassLoader local
Iterator it = (Iterator) server.getAttribute(AbstractWebDeployerMBean.OBJECT_NAME, "DeployedApplications");
while (it.hasNext() == true)
{
WebApplication webApplication = (WebApplication) it.next();
openWebModuleTag(buffer, webApplication.getCanonicalName());
Thread.currentThread().setContextClassLoader(webApplication.getMetaData().getENCLoader());
try
{
context = new InitialContext();
context = (Context) context.lookup("java:comp");
listXML(context, buffer);
}
catch (NamingException e)
{
buffer.append("Failed on lookup, " + e.toString(true));
formatException(buffer, e);
continue;
}
finally
{
closeWebModuleTag(buffer);
}
}
}
catch (Throwable e)
{
log.debug("Unable to list web applications ENC", e);
}
/* Get all deployed applications so that we can list their
java: namespaces which are ClassLoader local
*/
try
{
ejbModules = server.queryNames(EjbModule.EJB_MODULE_QUERY_NAME, null);
}
catch (Exception e)
{
log.error("getDeployedApplications failed", e);
appendErrorTag(buffer,
"Failed to getDeployedApplications " + e.toString());
closeJndiTag(buffer);
return buffer.toString();
}
HashSet ejb2Ids = new HashSet();
// List each application JNDI namespace
for (Iterator i = ejbModules.iterator(); i.hasNext();)
{
ObjectName app = (ObjectName) i.next();
openEjbModuleTag(buffer, app.getKeyProperty("url"));
Collection containers = null;
try
{
containers = (Collection) server.getAttribute(app, "Containers");
}
catch (Throwable t)
{
log.error("getContainers failed", t);
appendPreExceptionTag(buffer, "Failed to get ejbs in module", t);
}
for (Iterator iter = containers.iterator(); iter.hasNext();)
{
Container con = (Container) iter.next();
Object on = con.getJmxName();
ejb2Ids.add(on);
/* Set the thread class loader to that of the container as
the class loader is used by the java: context object
factory to partition the container namespaces.
*/
Thread.currentThread().setContextClassLoader(con.getClassLoader());
String bean = con.getBeanMetaData().getEjbName();
openContextTag(buffer);
appendBeanTag(buffer, bean);
Context context1 = ENCFactory.getEncById().get(on);
if (context1 == null)
{
appendErrorTag(buffer,
"Failed to find ENC of EJB: " + on);
context1 = null;
}
if (context1 != null)
{
try
{
listXML(context1, buffer);
}
catch (Throwable t)
{
appendErrorTag(buffer,
"Failed on list contents, " + t.toString());
}
} // if ( context != null )
closeContextTag(buffer);
}
closeEjbModuleTag(buffer);
}
//buffer.append("< h1 > Other components with java:comp namespace< /h1 >\n");
for (Object key : ENCFactory.getEncById().keySet())
{
// skip EJB 2.1 keys
if (ejb2Ids.contains(key)) continue;
context = ENCFactory.getEncById().get(key);
buffer.append("< other-encs >");
openContextTag(buffer);
appendBeanTag(buffer, key.toString());
listXML(context, buffer);
closeContextTag(buffer);
buffer.append("< /other-encs >");
}
// List the java: namespace
Thread.currentThread().setContextClassLoader(currentLoader);
try
{
context = new InitialContext();
context = (Context) context.lookup("java:");
}
catch (NamingException e)
{
log.error("Failed to get InitialContext for (java:)", e);
appendErrorTag(buffer,
"Failed to get InitialContext for (java:), " +
e.toString(true));
}
if (context != null)
{
openContextTag(buffer);
appendJavaNameTag(buffer);
try
{
listXML(context, buffer);
}
catch (Throwable t)
{
log.error("Failed to list contents of (java:)", t);
appendErrorTag(buffer,
"Failed to list contents of (java:), " +
t.toString());
}
closeContextTag(buffer);
} // if ( context != null )
// List the global JNDI namespace
try
{
context = new InitialContext();
}
catch (NamingException e)
{
log.error("Failed to get InitialContext", e);
appendErrorTag(buffer,
"Failed to get InitialContext, " + e.toString(true));
}
if (context != null)
{
openContextTag(buffer);
appendGlobalNameTag(buffer);
try
{
listXML(context, buffer);
}
catch (Throwable t)
{
log.error("Failed to list global contents ", t);
appendErrorTag(buffer,
"Failed to list global contents, " + t.toString());
}
closeContextTag(buffer);
} // if ( context != null )
// List the HA-JNDI namespace if the HAJNDI service is available
String url = null;
try
{
url = getHAUrl();
if (url != null)
{
java.util.Hashtable env = new java.util.Hashtable();
env.put(Context.PROVIDER_URL, url);
context = new InitialContext(env);
}
}
catch (NamingException e)
{
log.error("Failed to get InitialContext", e);
appendErrorTag(buffer,
"Failed to get InitialContext, " + e.toString(true));
}
if (url != null && context != null)
{
openContextTag(buffer);
appendHANameTag(buffer);
try
{
listXML(context, buffer);
}
catch (Throwable t)
{
log.error("Failed to list HA-JNDI contents ", t);
appendErrorTag(buffer,
"Failed to list HA-JNDI contents, " + t.toString());
}
closeContextTag(buffer);
} // if ( url != null && context != null )
closeJndiTag(buffer);
return buffer.toString();
}
List deployed application java:comp namespaces, the java:
namespace as well as the global InitialContext JNDI namespace in a
XML Format. |