Clover coverage report - Code Coverage for hivemind release 1.0-beta-1
Coverage timestamp: Sat Jul 3 2004 09:41:37 EDT
file stats: LOC: 81   Methods: 2
NCLOC: 44   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% 90.9% 100% 93.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.HashMap;
 18   
 import java.util.Map;
 19   
 
 20   
 import javassist.ClassPath;
 21   
 import javassist.ClassPool;
 22   
 import javassist.CtClass;
 23   
 import javassist.LoaderClassPath;
 24   
 import javassist.NotFoundException;
 25   
 
 26   
 import org.apache.hivemind.ApplicationRuntimeException;
 27   
 import org.apache.hivemind.HiveMind;
 28   
 import org.apache.hivemind.internal.Module;
 29   
 import org.apache.hivemind.service.ClassFab;
 30   
 import org.apache.hivemind.service.ClassFabUtils;
 31   
 import org.apache.hivemind.service.ClassFactory;
 32   
 
 33   
 /**
 34   
  * Implementation of {@link org.apache.hivemind.service.ClassFactory}.
 35   
  *
 36   
  * @author Howard Lewis Ship
 37   
  */
 38   
 public class ClassFactoryImpl implements ClassFactory
 39   
 {
 40   
     /**
 41   
      * Map of CtClassSource, keyed on module id.
 42   
      */
 43   
     private Map _ctClassSourceMap = new HashMap();
 44   
 
 45  306
     public ClassFab newClass(String name, Class superClass, Module module)
 46   
     {
 47  306
         CtClassSource source = findCtClassSource(module);
 48   
 
 49  306
         try
 50   
         {
 51  306
             CtClass ctNewClass = source.newClass(name, superClass);
 52   
 
 53  306
             return new ClassFabImpl(source, ctNewClass);
 54   
         }
 55   
         catch (Exception ex)
 56   
         {
 57  0
             throw new ApplicationRuntimeException(
 58   
                 ServiceMessages.unableToCreateClass(name, superClass, ex),
 59   
                 ex);
 60   
         }
 61   
 
 62   
     }
 63   
 
 64  306
     private synchronized CtClassSource findCtClassSource(Module module)
 65   
     {
 66  306
         String id = module.getModuleId();
 67   
 
 68  306
         CtClassSource result = (CtClassSource) _ctClassSourceMap.get(id);
 69   
 
 70  306
         if (result == null)
 71   
         {
 72  115
             result = new CtClassSource(module.getClassResolver().getClassLoader());
 73   
 
 74  115
             _ctClassSourceMap.put(id, result);
 75   
         }
 76   
 
 77  306
         return result;
 78   
     }
 79   
 
 80   
 }
 81