01: /**
02: *
03: */package clime.messadmin.providers.userdata;
04:
05: import java.net.URL;
06: import java.net.URLClassLoader;
07:
08: import javax.servlet.ServletContext;
09:
10: import clime.messadmin.i18n.I18NSupport;
11: import clime.messadmin.model.Server;
12: import clime.messadmin.providers.spi.ApplicationDataProvider;
13:
14: /**
15: * Displays the URLClassLoader for the current webapp.
16: * @author Cédrik LIME
17: */
18: public class ClassLoaderDisplayer implements ApplicationDataProvider {
19: private static final String BUNDLE_NAME = ClassLoaderDisplayer.class
20: .getName();
21:
22: /**
23: *
24: */
25: public ClassLoaderDisplayer() {
26: super ();
27: }
28:
29: /**
30: * {@inheritDoc}
31: */
32: public int getPriority() {
33: return 50;
34: }
35:
36: /**
37: * {@inheritDoc}
38: */
39: public String getApplicationDataTitle(ServletContext context) {
40: return I18NSupport.getLocalizedMessage(BUNDLE_NAME, null,
41: "title");//$NON-NLS-1$
42: }
43:
44: /**
45: * {@inheritDoc}
46: */
47: public String getXHTMLApplicationData(ServletContext context) {
48: ClassLoader cl = Server.getInstance().getApplication(context)
49: .getApplicationInfo().getClassLoader();
50: StringBuffer buffer = new StringBuffer(256);
51: buffer.append("<dl>");
52: while (cl != null) {
53: dump(cl, buffer);
54: cl = cl.getParent();
55: }
56: buffer.append("</dl>");
57: return buffer.toString();
58: }
59:
60: protected void dump(ClassLoader cl, StringBuffer out) {
61: out.append("<dt>");
62: out.append(cl.getClass().getName() + "@"
63: + Integer.toHexString(cl.hashCode()));
64: out.append("</dt>");
65: if (cl instanceof URLClassLoader) {
66: URLClassLoader urlcl = (URLClassLoader) cl;
67: URL[] urls = urlcl.getURLs();
68: out.append("<dd>");
69: out.append("<ol>");
70: for (int i = 0; i < urls.length; ++i) {
71: URL url = urls[i];
72: out.append("<li>").append(url).append("</li>\n");
73: }
74: out.append("</ol>\n");
75: out.append("</dd>\n");
76: }
77: }
78: }
|