Clover coverage report - Code Coverage for hivemind release 1.1-beta-3
Coverage timestamp: Mon Aug 22 2005 21:38:15 EDT
file stats: LOC: 92   Methods: 5
NCLOC: 47   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CtClassSource.java - 92.3% 100% 94.4%
coverage coverage
 1    // Copyright 2004, 2005 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 javassist.CtClass;
 18    import javassist.NotFoundException;
 19   
 20    import org.apache.hivemind.ApplicationRuntimeException;
 21    import org.apache.hivemind.service.ClassFabUtils;
 22   
 23    /**
 24    * Wrapper around Javassist's {@link javassist.ClassPool} and our own
 25    * {@link org.apache.hivemind.service.impl.ClassFactoryClassLoader} that manages the creation of new
 26    * instance of {@link javassist.CtClass} and converts finished CtClass's into instantiable Classes.
 27    *
 28    * @author Howard Lewis Ship
 29    */
 30    public class CtClassSource
 31    {
 32    private HiveMindClassPool _pool;
 33   
 34  145 public CtClassSource(HiveMindClassPool pool)
 35    {
 36  145 _pool = pool;
 37    }
 38   
 39  23036 public CtClass getCtClass(Class searchClass)
 40    {
 41  23036 ClassLoader loader = searchClass.getClassLoader();
 42   
 43    // Add the class loader for the searchClass to the class pool and
 44    // delegating class loader if needed.
 45   
 46  23036 _pool.appendClassLoader(loader);
 47   
 48  23036 String name = ClassFabUtils.getJavaClassName(searchClass);
 49   
 50  23036 try
 51    {
 52  23036 return _pool.get(name);
 53    }
 54    catch (NotFoundException ex)
 55    {
 56  0 throw new ApplicationRuntimeException(ServiceMessages.unableToLookupClass(name, ex), ex);
 57    }
 58    }
 59   
 60  2094 public CtClass newClass(String name, Class superClass)
 61    {
 62  2094 CtClass ctSuperClass = getCtClass(superClass);
 63   
 64  2094 return _pool.makeClass(name, ctSuperClass);
 65    }
 66   
 67    /**
 68    * Creates a new, empty interace, with the given name.
 69    *
 70    * @since 1.1
 71    */
 72   
 73  16 public CtClass newInterface(String name)
 74    {
 75  16 return _pool.makeInterface(name);
 76    }
 77   
 78  2102 public Class createClass(CtClass ctClass)
 79    {
 80    // String className = ctClass.getName();
 81   
 82  2102 try
 83    {
 84  2102 return _pool.toClass(ctClass);
 85    }
 86    catch (Throwable ex)
 87    {
 88  3 throw new ApplicationRuntimeException(ServiceMessages.unableToWriteClass(ctClass, ex),
 89    ex);
 90    }
 91    }
 92    }