Coverage Report - net.sourceforge.jeuclid.elements.support.ClassLoaderSupport
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassLoaderSupport
100%
8/8
N/A
1,25
ClassLoaderSupport$SingletonHolder
50%
2/4
N/A
1,25
 
 1  
 /*
 2  
  * Copyright 2002 - 2008 JEuclid, http://jeuclid.sf.net
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 /* $Id: ClassLoaderSupport.java,v 88b901bf20fb 2008/06/07 14:12:27 maxberger $ */
 18  
 
 19  
 package net.sourceforge.jeuclid.elements.support;
 20  
 
 21  
 /**
 22  
  * Support utilities for classloading.
 23  
  * 
 24  
  * @version $Revision: 88b901bf20fb $
 25  
  */
 26  
 public final class ClassLoaderSupport {
 27  
 
 28  3139
     private static final class SingletonHolder {
 29  209
         private static final ClassLoaderSupport INSTANCE = new ClassLoaderSupport();
 30  
 
 31  0
         private SingletonHolder() {
 32  0
         }
 33  
     }
 34  
 
 35  
     /**
 36  
      * Default Constructor.
 37  
      */
 38  209
     protected ClassLoaderSupport() {
 39  
         // Empty on purporse.
 40  209
     }
 41  
 
 42  
     /**
 43  
      * accessor for singleton instance.
 44  
      * 
 45  
      * @return an instance of this class.
 46  
      */
 47  
     public static ClassLoaderSupport getInstance() {
 48  3139
         return ClassLoaderSupport.SingletonHolder.INSTANCE;
 49  
     }
 50  
 
 51  
     /**
 52  
      * Try to load the given lass from the current context.
 53  
      * 
 54  
      * @param className
 55  
      *            name of the class to load
 56  
      * @return a Class object for the given class if possible.
 57  
      * @throws ClassNotFoundException
 58  
      *             if the class could not be found.
 59  
      * @see ClassLoader#loadClass(String)
 60  
      */
 61  
     public Class<?> loadClass(final String className)
 62  
             throws ClassNotFoundException {
 63  
         Class<?> retVal;
 64  
         try {
 65  3139
             retVal = Thread.currentThread().getContextClassLoader().loadClass(
 66  
                     className);
 67  4
         } catch (final ClassNotFoundException e) {
 68  4
             retVal = ClassLoaderSupport.class.getClassLoader().loadClass(
 69  
                     className);
 70  3135
         }
 71  3135
         return retVal;
 72  
     }
 73  
 
 74  
 }