Clover coverage report - Cactus 1.4.1 for J2EE API 13
Coverage timestamp: Sat Aug 31 2002 22:02:23 BST
file stats: LOC: 102   Methods: 5
NCLOC: 42   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassLoaderUtils.java 50% 66.7% 60% 63.6%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus.util;
 3   
 import java.util.ResourceBundle;
 4   
 import java.util.PropertyResourceBundle;
 5   
 import java.util.MissingResourceException;
 6   
 import java.util.Locale;
 7   
 
 8   
 /** 
 9   
  * Utiliy methods related to class loading in a webapp environment. 
 10   
  * 
 11   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 12   
  * 
 13   
  * @version $Id: ClassLoaderUtils.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $ 
 14   
  */
 15   
 public class ClassLoaderUtils {
 16   
   /** 
 17   
        * Try loading a class first by using the context class loader or by using 
 18   
        * the classloader of the referrer class if the context classloader failed 
 19   
        * to load the class. 
 20   
        * 
 21   
        * @param theClassName the name of the test class 
 22   
        * @param theReferrer the class will be loaded using the classloader which 
 23   
        *        has loaded this referrer class 
 24   
        * @return the class object the test class to call 
 25   
        * @exception ClassNotFoundException if the class cannot be loaded through 
 26   
        *            either classloader 
 27   
        */
 28  330
   public static Class loadClass(String theClassName, 
 29   
       Class theReferrer) throws ClassNotFoundException {
 30  330
     Class clazz = null;
 31  330
     try {
 32  330
       clazz = ClassLoaderUtils.loadClassFromWebappClassLoader(theClassName, theReferrer);
 33   
     } catch (Exception internalException) {
 34  0
       clazz = ClassLoaderUtils.loadClassFromContextClassLoader(theClassName);
 35   
     } 
 36  330
     return clazz;
 37   
   } 
 38   
 
 39   
   /** 
 40   
        * Try loading class using the Context class loader. 
 41   
        * 
 42   
        * @param theClassName the class to load 
 43   
        * @return the <code>Class</code> object for the class to load 
 44   
        * @exception ClassNotFoundException if the class cannot be loaded through 
 45   
        *            this class loader 
 46   
        */
 47  0
   public static Class loadClassFromContextClassLoader(String theClassName) throws 
 48   
       ClassNotFoundException {
 49  0
     return Class.forName(theClassName, true, Thread.currentThread().getContextClassLoader());
 50   
   } 
 51   
 
 52   
   /** 
 53   
        * Try loading class using the Webapp class loader. 
 54   
        * 
 55   
        * @param theClassName the class to load 
 56   
        * @param theReferrer the class will be loaded using the classloader which 
 57   
        *        has loaded this referrer class 
 58   
        * @return the <code>Class</code> object for the class to load 
 59   
        * @exception ClassNotFoundException if the class cannot be loaded through 
 60   
        *            this class loader 
 61   
        */
 62  330
   public static Class loadClassFromWebappClassLoader(String theClassName, 
 63   
       Class theReferrer) throws ClassNotFoundException {
 64  330
     return Class.forName(theClassName, true, theReferrer.getClassLoader());
 65   
   } 
 66   
 
 67   
   /** 
 68   
        * Try loading a resource bundle from either the context class loader or 
 69   
        * the 
 70   
        * 
 71   
        * @param theName the resource bundle name 
 72   
        * @param theReferrer the resource bundle will be loaded using the 
 73   
        *        classloader which has loaded this referrer class 
 74   
        * @return the loaded resource bundle 
 75   
        */
 76  10
   public static ResourceBundle loadPropertyResourceBundle(String theName, Class theReferrer) {
 77  10
     ResourceBundle bundle;
 78  10
     try {
 79  10
       if (theReferrer.getClassLoader() == null) {
 80  0
         bundle = PropertyResourceBundle.getBundle(theName, Locale.getDefault());
 81   
       } else {
 82  10
         bundle = PropertyResourceBundle.getBundle(theName, Locale.getDefault(), 
 83   
             theReferrer.getClassLoader());
 84   
       } 
 85   
     } catch (MissingResourceException e) {
 86  0
       bundle = PropertyResourceBundle.getBundle(theName, Locale.getDefault(), 
 87   
           Thread.currentThread().getContextClassLoader());
 88   
     } 
 89  10
     return bundle;
 90   
   } 
 91   
 
 92   
   /** 
 93   
    * Utiliy methods related to class loading in a webapp environment. 
 94   
    * 
 95   
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 96   
    * 
 97   
    * @version $Id: ClassLoaderUtils.html,v 1.1 2003/04/14 12:27:33 sinisa Exp $ 
 98   
    */
 99  0
   public ClassLoaderUtils() {
 100  0
     super();
 101   
   } 
 102   
 }