2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:33:43 PST
file stats: LOC: 110   Methods: 6
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CtClassSource.java - 87.5% 83.3% 86.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    private int _createdClassCount = 0;
 35   
 36    /**
 37    * Returns the number of classes (and interfaces) created by this source.
 38    *
 39    * @see #createClass(CtClass)
 40    * @return the count
 41    * @since 1.2
 42    */
 43  0 public int getCreatedClassCount()
 44    {
 45  0 return _createdClassCount;
 46    }
 47   
 48  145 public CtClassSource(HiveMindClassPool pool)
 49    {
 50  145 _pool = pool;
 51    }
 52   
 53  23045 public CtClass getCtClass(Class searchClass)
 54    {
 55  23045 ClassLoader loader = searchClass.getClassLoader();
 56   
 57    // Add the class loader for the searchClass to the class pool and
 58    // delegating class loader if needed.
 59   
 60  23045 _pool.appendClassLoader(loader);
 61   
 62  23045 String name = ClassFabUtils.getJavaClassName(searchClass);
 63   
 64  23045 try
 65    {
 66  23045 return _pool.get(name);
 67    }
 68    catch (NotFoundException ex)
 69    {
 70  0 throw new ApplicationRuntimeException(ServiceMessages.unableToLookupClass(name, ex), ex);
 71    }
 72    }
 73   
 74  2096 public CtClass newClass(String name, Class superClass)
 75    {
 76  2096 CtClass ctSuperClass = getCtClass(superClass);
 77   
 78  2096 return _pool.makeClass(name, ctSuperClass);
 79    }
 80   
 81    /**
 82    * Creates a new, empty interace, with the given name.
 83    *
 84    * @since 1.1
 85    */
 86   
 87  16 public CtClass newInterface(String name)
 88    {
 89  16 return _pool.makeInterface(name);
 90    }
 91   
 92  2104 public Class createClass(CtClass ctClass)
 93    {
 94    // String className = ctClass.getName();
 95   
 96  2104 try
 97    {
 98  2104 Class result = _pool.toClass(ctClass);
 99   
 100  2101 _createdClassCount++;
 101   
 102  2101 return result;
 103    }
 104    catch (Throwable ex)
 105    {
 106  3 throw new ApplicationRuntimeException(ServiceMessages.unableToWriteClass(ctClass, ex),
 107    ex);
 108    }
 109    }
 110    }