Coverage Report - de.jollyday.util.ClassLoadingUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassLoadingUtil
100%
8/8
N/A
2
 
 1  
 /**
 2  
  * Copyright 2012 Sven Diedrichsen 
 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 
 12  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
 13  
  * express or implied. See the License for the specific language 
 14  
  * governing permissions and limitations under the License. 
 15  
  */
 16  
 package de.jollyday.util;
 17  
 
 18  
 import java.util.logging.Logger;
 19  
 
 20  
 /**
 21  
  * <p>
 22  
  * ClassLoadingUtil class.
 23  
  * </p>
 24  
  * 
 25  
  * @author José Pedro Pereira - Linkare TI
 26  
  * @version $Id: $
 27  
  */
 28  8051
 public class ClassLoadingUtil {
 29  
 
 30  1
         private static final Logger LOG = Logger.getLogger(ClassLoadingUtil.class.getName());
 31  
 
 32  
         /**
 33  
          * Loads the class by class name with the current threads context
 34  
          * classloader. If there occurs an exception the class will be loaded by
 35  
          * default classloader.
 36  
          * 
 37  
          * @param className
 38  
          *            a {@link java.lang.String} object.
 39  
          * @return a {@link java.lang.Class} object.
 40  
          * @throws java.lang.ClassNotFoundException
 41  
          *             if any.
 42  
          */
 43  
         public Class<?> loadClass(String className) throws ClassNotFoundException {
 44  
                 try {
 45  125
                         return Class.forName(className, true, getClassloader());
 46  1
                 } catch (Exception e) {
 47  2
                         LOG.warning("Could not load class with current threads context classloader. Using default. Reason: "
 48  1
                                         + e.getClass().getSimpleName() + ": " + e.getMessage());
 49  1
                         return Class.forName(className);
 50  
                 }
 51  
         }
 52  
 
 53  
         /**
 54  
          * Returns the current threads context classloader.
 55  
          * 
 56  
          * @see Thread#currentThread() 
 57  
          * @return the current threads context classloader
 58  
          */
 59  
         public ClassLoader getClassloader() {
 60  1631
                 return Thread.currentThread().getContextClassLoader();
 61  
         }
 62  
 }