Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 138   Methods: 2
NCLOC: 61   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassObjectTypeFactory.java 83.3% 72.2% 50% 73.1%
coverage coverage
 1    package org.drools.semantics.base;
 2   
 3    /*
 4    * $Id: ClassObjectTypeFactory.java,v 1.7.2.4 2005/04/30 13:49:43 mproctor Exp $
 5    *
 6    * Copyright 2004 (C) The Werken Company. All Rights Reserved.
 7    *
 8    * Redistribution and use of this software and associated documentation
 9    * ("Software"), with or without modification, are permitted provided that the
 10    * following conditions are met:
 11    *
 12    * 1. Redistributions of source code must retain copyright statements and
 13    * notices. Redistributions must also contain a copy of this document.
 14    *
 15    * 2. Redistributions in binary form must reproduce the above copyright notice,
 16    * this list of conditions and the following disclaimer in the documentation
 17    * and/or other materials provided with the distribution.
 18    *
 19    * 3. The name "drools" must not be used to endorse or promote products derived
 20    * from this Software without prior written permission of The Werken Company.
 21    * For written permission, please contact bob@werken.com.
 22    *
 23    * 4. Products derived from this Software may not be called "drools" nor may
 24    * "drools" appear in their names without prior written permission of The Werken
 25    * Company. "drools" is a registered trademark of The Werken Company.
 26    *
 27    * 5. Due credit should be given to The Werken Company.
 28    * (http://drools.werken.com/).
 29    *
 30    * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
 31    * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 32    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 33    * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
 34    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 35    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 36    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 37    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 38    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 39    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 40    * POSSIBILITY OF SUCH DAMAGE.
 41    *
 42    */
 43   
 44    import java.util.HashSet;
 45    import java.util.Iterator;
 46    import java.util.Set;
 47   
 48    import org.drools.rule.Rule;
 49    import org.drools.smf.Configuration;
 50    import org.drools.smf.FactoryException;
 51    import org.drools.smf.ObjectTypeFactory;
 52    import org.drools.spi.ImportEntry;
 53    import org.drools.spi.Importer;
 54    import org.drools.spi.ObjectType;
 55    import org.drools.spi.RuleBaseContext;
 56   
 57    public class ClassObjectTypeFactory
 58    implements
 59    ObjectTypeFactory
 60    {
 61    private static final ClassObjectTypeFactory INSTANCE = new ClassObjectTypeFactory( );
 62   
 63  0 public static ClassObjectTypeFactory getInstance()
 64    {
 65  0 return INSTANCE;
 66    }
 67   
 68  162 public ObjectType newObjectType(Rule rule,
 69    RuleBaseContext context,
 70    Configuration config) throws FactoryException
 71    {
 72  162 String className = config.getText( ).trim( );
 73   
 74  162 if ( className == null || className.trim( ).equals( "" ) )
 75    {
 76  1 throw new FactoryException( "no class name specified" );
 77    }
 78   
 79  161 Class clazz = null;
 80  161 try
 81    {
 82  161 ClassLoader cl = (ClassLoader) context.get( "smf-classLoader" );
 83  161 if ( cl == null )
 84    {
 85  9 cl = Thread.currentThread( ).getContextClassLoader( );
 86  9 context.put( "smf-classLoader",
 87    cl );
 88    }
 89   
 90  161 if ( cl == null )
 91    {
 92  0 cl = getClass( ).getClassLoader( );
 93  0 context.put( "smf-classLoader",
 94    cl );
 95    }
 96   
 97  161 Importer importer = rule.getImporter( );
 98  161 clazz = importer.importClass( cl,
 99    className );
 100    }
 101    catch ( ClassNotFoundException e )
 102    {
 103  0 throw new FactoryException( e.getMessage( ) );
 104    }
 105    catch ( Error e )
 106    {
 107  0 throw new FactoryException( e.getMessage( ) );
 108    }
 109   
 110  161 return new ClassObjectType( clazz );
 111    }
 112    /*
 113    * private Class importClass(ClassLoader cl, String importText, String
 114    * className) { String qualifiedClass = null; Class clazz = null;
 115    *
 116    * String convertedImportText; if ( importText.startsWith( "from " ) ) {
 117    * convertedImportText = converPythonImport( importText ); } else {
 118    * convertedImportText = importText; }
 119    * // not python if ( convertedImportText.endsWith( "*" ) ) {
 120    * qualifiedClass = convertedImportText.substring( 0,
 121    * convertedImportText.indexOf( '*' ) ) + className; } else if (
 122    * convertedImportText.endsWith( "." + className ) ) { qualifiedClass =
 123    * convertedImportText; } else if ( convertedImportText.equals( className ) ) {
 124    * qualifiedClass = convertedImportText; }
 125    *
 126    *
 127    * if ( qualifiedClass != null ) { try { clazz = cl.loadClass(
 128    * qualifiedClass ); } catch ( ClassNotFoundException e ) { clazz = null; } }
 129    * return clazz; }
 130    *
 131    * private String converPythonImport(String packageText) { String fromString =
 132    * "from "; String importString = "import "; int fromIndex =
 133    * packageText.indexOf( fromString ); int importIndex = packageText.indexOf(
 134    * importString ); return packageText.substring( fromIndex +
 135    * fromString.length( ), importIndex ).trim( ) + "." +
 136    * packageText.substring( importIndex + importString.length( ) ).trim( ); }
 137    */
 138    }