Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 130   Methods: 4
NCLOC: 74   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConditionHandler.java 75% 95.8% 100% 93.8%
coverage coverage
 1    package org.drools.io;
 2   
 3    /*
 4    * $Id: ConditionHandler.java,v 1.5.2.1 2005/04/07 17:32:15 mproctor Exp $
 5    *
 6    * Copyright 2001-2003 (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 trademark of The Werken Company.
 26    *
 27    * 5. Due credit should be given to The Werken Company. (http://werken.com/)
 28    *
 29    * THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS ``AS IS''
 30    * AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 31    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 32    * ARE DISCLAIMED. IN NO EVENT SHALL THE WERKEN COMPANY OR ITS CONTRIBUTORS BE
 33    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 34    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 35    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 36    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 37    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 38    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 39    * POSSIBILITY OF SUCH DAMAGE.
 40    *
 41    */
 42    import java.io.BufferedWriter;
 43    import java.io.FileWriter;
 44    import java.io.PrintWriter;
 45    import java.util.HashSet;
 46   
 47    import org.drools.rule.Declaration;
 48    import org.drools.rule.Rule;
 49    import org.drools.smf.ConditionFactory;
 50    import org.drools.smf.Configuration;
 51    import org.drools.smf.FactoryException;
 52    import org.drools.smf.SemanticModule;
 53    import org.drools.spi.Condition;
 54    import org.xml.sax.Attributes;
 55    import org.xml.sax.SAXException;
 56    import org.xml.sax.SAXParseException;
 57   
 58    /**
 59    * @author mproctor
 60    *
 61    * TODO To change the template for this generated type comment go to Window -
 62    * Preferences - Java - Code Style - Code Templates
 63    */
 64    class ConditionHandler extends BaseAbstractHandler
 65    implements
 66    Handler
 67    {
 68  66 ConditionHandler(RuleSetReader ruleSetReader)
 69    {
 70  66 this.ruleSetReader = ruleSetReader;
 71   
 72  66 if ( (this.validParents == null) && (validPeers == null) )
 73    {
 74  66 this.ruleSetReader = ruleSetReader;
 75  66 this.validParents = new HashSet( );
 76  66 this.validParents.add( Rule.class );
 77   
 78  66 this.validPeers = new HashSet( );
 79  66 this.validPeers.add( Declaration.class );
 80  66 this.validPeers.add( Condition.class );
 81  66 this.validPeers.add( null );
 82   
 83  66 this.allowNesting = false;
 84    }
 85    }
 86   
 87  104 public Object start(String uri,
 88    String localName,
 89    Attributes attrs) throws SAXException
 90    {
 91  104 ruleSetReader.startConfiguration( localName,
 92    attrs );
 93  104 return null;
 94    }
 95   
 96  104 public Object end(String uri,
 97    String localName) throws SAXException
 98    {
 99  104 Configuration config = this.ruleSetReader.endConfiguration( );
 100  104 SemanticModule module = this.ruleSetReader.lookupSemanticModule( uri,
 101    localName );
 102   
 103  104 ConditionFactory factory = module.getConditionFactory( localName );
 104  104 Condition[] conditions;
 105  104 try
 106    {
 107  104 Rule rule = (Rule) this.ruleSetReader.getParent( Rule.class );
 108  104 conditions = factory.newCondition( rule,
 109    this.ruleSetReader.getFactoryContext( ),
 110    config );
 111   
 112  104 for (int i = 0; i < conditions.length; i++)
 113    {
 114  104 rule.addCondition( conditions[i] );
 115    }
 116    }
 117    catch ( FactoryException e )
 118    {
 119  0 throw new SAXParseException( "error constructing condition",
 120    this.ruleSetReader.getLocator( ),
 121    e );
 122    }
 123  104 return conditions[conditions.length-1];
 124    }
 125   
 126  208 public Class generateNodeFor()
 127    {
 128  208 return Condition.class;
 129    }
 130    }