Clover coverage report - Code Coverage for hivemind release 1.0
Coverage timestamp: Wed Sep 22 2004 08:05:25 EDT
file stats: LOC: 86   Methods: 3
NCLOC: 42   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
ClassFactoryClassLoader.java 100% 100% 100% 100%
coverage
 1   
 //  Copyright 2004 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.service.impl;
 16   
 
 17   
 import java.util.ArrayList;
 18   
 import java.util.List;
 19   
 
 20   
 /**
 21   
  * ClassLoader used to properly instantiate newly created classes.
 22   
  *
 23   
  * @author Howard Lewis Ship / Essl Christian
 24   
  * @see org.apache.hivemind.service.impl.CtClassSource
 25   
  */
 26   
 class ClassFactoryClassLoader extends ClassLoader
 27   
 {
 28   
     private List _loaders = new ArrayList();
 29   
 
 30   
     /**
 31   
      * Invoked to create a new class instance from fabricated bytecode.
 32   
      */
 33  1363
     public Class loadClass(String name, byte[] bytecodes)
 34   
     {
 35  1363
         Class result = defineClass(name, bytecodes, 0, bytecodes.length);
 36   
 
 37  1361
         resolveClass(result);
 38   
 
 39  1361
         return result;
 40   
     }
 41   
 
 42   
     /**
 43   
      * Adds a delegate class loader to the list of delegate class loaders.
 44   
      */
 45  114
     public synchronized void addDelegateLoader(ClassLoader loader)
 46   
     {
 47  114
         _loaders.add(loader);
 48   
     }
 49   
 
 50   
     /**
 51   
      * Searches each of the delegate class loaders for the given class.
 52   
      */
 53  7
     protected synchronized Class findClass(String name) throws ClassNotFoundException
 54   
     {
 55  7
         ClassNotFoundException cnfex = null;
 56   
 
 57  7
         try
 58   
         {
 59  7
             return super.findClass(name);
 60   
         }
 61   
         catch (ClassNotFoundException ex)
 62   
         {
 63  7
             cnfex = ex;
 64   
         }
 65   
 
 66  7
         int count = _loaders.size();
 67  7
         for (int i = 0; i < count; i++)
 68   
         {
 69  7
             ClassLoader l = (ClassLoader) _loaders.get(i);
 70   
 
 71  7
             try
 72   
             {
 73  7
                 return l.loadClass(name);
 74   
             }
 75   
             catch (ClassNotFoundException ex)
 76   
             {
 77   
             }
 78   
         }
 79   
 
 80   
         // Not found .. through the first exception
 81   
 
 82  7
         throw cnfex;
 83   
     }
 84   
 
 85   
 }
 86