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