User: starksm
Date: 02/02/17 09:35:22
Modified: src/main/org/jboss/system Info.java InfoMBean.java
ServiceLibraries.java
Log:
Add a displayInfoForClass method to Info that provides the ClassLoader,
ProtectionDomain and Package info for the named class.
Revision Changes Path
1.11 +63 -2 jboss/src/main/org/jboss/system/Info.java
Index: Info.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/Info.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Info.java 13 Feb 2002 04:26:40 -0000 1.10
+++ Info.java 17 Feb 2002 17:35:22 -0000 1.11
@@ -27,7 +27,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Hiram Chirino</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
*/
public class Info
implements InfoMBean, MBeanRegistration
@@ -179,6 +179,67 @@
return "<h2>Package:"+pkgName+" Not Found!</h2>";
StringBuffer info = new StringBuffer("<h2>Package: "+pkgName+"</h2>");
+ displayPackageInfo(pkg, info);
+ return info.toString();
+ }
+ /** Display the ClassLoader, ProtectionDomain and Package information for
+ the specified class.
+ @return a simple html report of this information
+ */
+ public String displayInfoForClass(String className)
+ {
+ ServiceLibraries libraries = ServiceLibraries.getLibraries();
+ Class clazz = libraries.findClass(className);
+ if( clazz == null )
+ return "<h2>Class:"+className+" Not Found!</h2>";
+ Package pkg = clazz.getPackage();
+ if( pkg == null )
+ return "<h2>Class:"+className+" has no Package info</h2>";
+
+ StringBuffer info = new StringBuffer("<h1>Class: "+pkg.getName()+"</h1>");
+ ClassLoader cl = clazz.getClassLoader();
+ info.append("<h2>ClassLoader: "+cl+"</h2>\n");
+ info.append("<h3>ProtectionDomain</h3>\n");
+ info.append("<pre>\n"+clazz.getProtectionDomain()+"</pre>\n");
+ info.append("<h2>Package: "+pkg.getName()+"</h2>");
+ displayPackageInfo(pkg, info);
+ return info.toString();
+ }
+
+ /** This does not work as expected because the thread context class loader
+ *is not used to determine which class loader the package list is obtained
+ *from.
+ */
+ public String displayAllPackageInfo()
+ {
+ ClassLoader entryCL = Thread.currentThread().getContextClassLoader();
+ ServiceLibraries libraries = ServiceLibraries.getLibraries();
+ ClassLoader[] classLoaders = libraries.getClassLoaders();
+ StringBuffer info = new StringBuffer();
+ for(int c = 0; c < classLoaders.length; c ++)
+ {
+ ClassLoader cl = classLoaders[c];
+ Thread.currentThread().setContextClassLoader(cl);
+ try
+ {
+ info.append("<h1>ClassLoader: "+cl+"</h1>\n");
+ Package[] pkgs = Package.getPackages();
+ for(int p = 0; p < pkgs.length; p ++)
+ {
+ Package pkg = pkgs[p];
+ info.append("<h2>Package: "+pkg.getName()+"</h2>\n");
+ displayPackageInfo(pkg, info);
+ }
+ }
+ catch(Throwable e)
+ {
+ }
+ }
+ Thread.currentThread().setContextClassLoader(entryCL);
+ return info.toString();
+ }
+ private void displayPackageInfo(Package pkg, StringBuffer info)
+ {
info.append("<pre>\n");
info.append("SpecificationTitle: "+pkg.getSpecificationTitle());
info.append("\nSpecificationVersion: "+pkg.getSpecificationVersion());
@@ -188,7 +249,6 @@
info.append("\nImplementationVendor: "+pkg.getImplementationVendor());
info.append("\nisSealed: "+pkg.isSealed());
info.append("</pre>\n");
- return info.toString();
}
/** Return a Map of System.getProperties() with a toString implementation
@@ -252,4 +312,5 @@
return rc.toString();
}
+
}
1.8 +8 -2 jboss/src/main/org/jboss/system/InfoMBean.java
Index: InfoMBean.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/InfoMBean.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- InfoMBean.java 15 Feb 2002 06:18:32 -0000 1.7
+++ InfoMBean.java 17 Feb 2002 17:35:22 -0000 1.8
@@ -20,7 +20,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Hiram Chirino</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
- * @version $Revision: 1.7 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Scott Stark</a>
+ * @version $Revision: 1.8 $
*/
public interface InfoMBean
{
@@ -52,7 +53,12 @@
* Display the java.lang.Package info for the pkgName
*/
String displayPackageInfo(String pkgName);
-
+ /** Display the ClassLoader, ProtectionDomain and Package information for
+ the specified class.
+ @return a simple html report of this information
+ */
+ String displayInfoForClass(String className);
+
/**
* Return a Map of System.getProperties() with a toString implementation
* that provides an html table of the key/value pairs
1.17 +45 -1 jboss/src/main/org/jboss/system/ServiceLibraries.java
Index: ServiceLibraries.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/system/ServiceLibraries.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- ServiceLibraries.java 13 Feb 2002 04:26:40 -0000 1.16
+++ ServiceLibraries.java 17 Feb 2002 17:35:22 -0000 1.17
@@ -26,7 +26,7 @@
* @see <related>
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ole Husgaard</a>
- * @version $Revision: 1.16 $ <p>
+ * @version $Revision: 1.17 $ <p>
*
* <p><b>20010830 marc fleury:</b>
* <ul>
@@ -408,6 +408,42 @@
throw new ClassNotFoundException(name);
}
+ /** Iterates through the current class loaders and tries to find the
+ given class name.
+ @return the Class object for name if found, null otherwise.
+ */
+ public Class findClass(String name)
+ {
+ Class clazz = null;
+ Set classLoaders2;
+ synchronized (this)
+ {
+ classLoaders2 = classLoaders;
+ }
+ /* We have to find the class as a resource as we don't want to invoke
+ loadClass(name) and cause the side-effect of loading new classes.
+ */
+ String classRsrcName = name.replace('.', '/') + ".class";
+ for(Iterator iter = classLoaders2.iterator(); iter.hasNext();)
+ {
+ UnifiedClassLoader cl = (UnifiedClassLoader)iter.next();
+ URL classURL = cl.getResource(classRsrcName);
+ if( classURL != null )
+ {
+ try
+ {
+ // Since the class was found we can load it which should be a noop
+ clazz = cl.loadClass(name);
+ }
+ catch(ClassNotFoundException e)
+ {
+ log.debug("Failed to load class: "+name, e);
+ }
+ }
+ }
+ return clazz;
+ }
+
/** Obtain a listing of the URL for all UnifiedClassLoaders associated with
*the ServiceLibraries
*/
@@ -435,6 +471,14 @@
URL[] urls = new URL[classpath.size()];
classpath.toArray(urls);
return urls;
+ }
+
+ public ClassLoader[] getClassLoaders()
+ {
+ Set tmpClassLoaders = classLoaders;
+ ClassLoader[] loaders = new ClassLoader[tmpClassLoaders.size()];
+ tmpClassLoaders.toArray(loaders);
+ return loaders;
}
/**
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development