Clover coverage report - Code Coverage for hivemind release 1.0-rc-2
Coverage timestamp: Sat Sep 11 2004 09:09:48 EDT
file stats: LOC: 74   Methods: 2
NCLOC: 35   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
ClassFactoryImpl.java 100% 88.9% 100% 92.3%
coverage 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.HashSet;
 18   
 import java.util.Set;
 19   
 
 20   
 import javassist.CtClass;
 21   
 
 22   
 import org.apache.hivemind.ApplicationRuntimeException;
 23   
 import org.apache.hivemind.service.ClassFab;
 24   
 import org.apache.hivemind.service.ClassFactory;
 25   
 
 26   
 /**
 27   
  * Implementation of {@link org.apache.hivemind.service.ClassFactory}.
 28   
  *
 29   
  * @author Howard Lewis Ship
 30   
  */
 31   
 public class ClassFactoryImpl implements ClassFactory
 32   
 {
 33   
     /**
 34   
      * ClassPool shared by all modules (all CtClassSource instances).
 35   
      */
 36   
     private HiveMindClassPool _pool = new HiveMindClassPool();
 37   
     private CtClassSource _classSource = new CtClassSource(_pool);
 38   
 
 39   
     private Set _addedClassLoaders = new HashSet();
 40   
 
 41  1352
     public ClassFab newClass(String name, Class superClass, ClassLoader loader)
 42   
     {
 43  1352
         updateSourceForClassLoader(loader);
 44   
 
 45  1352
         try
 46   
         {
 47  1352
             CtClass ctNewClass = _classSource.newClass(name, superClass);
 48   
 
 49  1352
             return new ClassFabImpl(_classSource, ctNewClass);
 50   
         }
 51   
         catch (Exception ex)
 52   
         {
 53  0
             throw new ApplicationRuntimeException(
 54   
                 ServiceMessages.unableToCreateClass(name, superClass, ex),
 55   
                 ex);
 56   
         }
 57   
     }
 58   
 
 59   
     /**
 60   
      * Whenever a new class loader is encountered (which is, actually, 
 61   
      * fairly rare), update the pool (and, indirectly, the class source)
 62   
      * to search it as well.
 63   
      */
 64  1352
     private synchronized void updateSourceForClassLoader(ClassLoader loader)
 65   
     {
 66  1352
         if (_addedClassLoaders.contains(loader))
 67  1256
             return;
 68   
 
 69  96
         _pool.appendClassLoader(loader);
 70   
 
 71  96
         _addedClassLoaders.add(loader);
 72   
     }
 73   
 }
 74