Clover coverage report - Drools - 2.0-rc2
Coverage timestamp: Wed May 11 2005 07:12:26 BST
file stats: LOC: 319   Methods: 13
NCLOC: 133   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RuleBaseLoader.java 33.3% 27.3% 23.1% 26.9%
coverage coverage
 1    package org.drools.io;
 2   
 3    /*
 4    * $Id: RuleBaseLoader.java,v 1.5 2005/02/04 02:13:38 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   
 43    import java.io.IOException;
 44    import java.io.InputStream;
 45    import java.io.Reader;
 46    import java.net.URL;
 47   
 48    import org.drools.IntegrationException;
 49    import org.drools.RuleBase;
 50    import org.drools.RuleBaseBuilder;
 51    import org.drools.conflict.DefaultConflictResolver;
 52    import org.drools.rule.RuleSet;
 53    import org.drools.spi.ConflictResolver;
 54    import org.drools.spi.RuleBaseContext;
 55    import org.xml.sax.SAXException;
 56   
 57    /**
 58    * Convenience methods for loading a <code>RuleBase</code>.
 59    *
 60    * <p>
 61    * The <code>RuleBaseLoader</code> provides convenience methods for loading
 62    * <code>RuleBase</code> s from streams. <code>RuleBaseLoader</code> is
 63    * thread-safe and as such may be used to build multiple <code>RuleBase</code> s
 64    * simultaneously by multiple threads.
 65    * </p>
 66    *
 67    * @see RuleSet
 68    * @see RuleBase
 69    * @see RuleSetReader
 70    * @see RuleBaseBuilder
 71    *
 72    * @author <a href="mailto:bob@werken.com">bob mcwhirter </a>
 73    * TODO: Would rather this wasn't a bunch of static methods.
 74    */
 75    public final class RuleBaseLoader
 76    {
 77    /**
 78    * Default constructor - marked private to prevent instantiation.
 79    */
 80  0 private RuleBaseLoader( )
 81    {
 82  0 throw new UnsupportedOperationException( );
 83    }
 84   
 85    /**
 86    * Loads a RuleBase from a URL using the default ConflictResolver
 87    *
 88    * This is a convenience method and calls public static RuleBase
 89    * loadFromUrl(URL url, ConflictResolver resolver) passing the
 90    * DefaultConflictResolver
 91    *
 92    * @param url
 93    * @return RuleBase
 94    */
 95  2 public static RuleBase loadFromUrl( URL url )
 96    throws SAXException,
 97    IOException,
 98    IntegrationException
 99    {
 100  2 return loadFromUrl( url, DefaultConflictResolver.getInstance( ) );
 101    }
 102   
 103    /**
 104    * Loads a RuleBase from a URL using the given ConflictResolver
 105    *
 106    * @param url
 107    * @param resolver
 108    * @return RuleBase
 109    */
 110  2 public static RuleBase loadFromUrl( URL url, ConflictResolver resolver )
 111    throws SAXException,
 112    IOException,
 113    IntegrationException
 114    {
 115  2 return loadFromUrl( new URL[]{url}, resolver );
 116    }
 117   
 118    /**
 119    * Loads a RuleBase using several URLs, using the DefaultConflictResolver.
 120    *
 121    * This is a convenience method and calls public static RuleBase
 122    * loadFromUrl(URL[] url, ConflictResolver resolver) passing the
 123    * DefaultConflictResolver
 124    *
 125    * @param urls
 126    * @return RuleBase
 127    */
 128  0 public static RuleBase loadFromUrl( URL[] urls )
 129    throws SAXException,
 130    IOException,
 131    IntegrationException
 132    {
 133  0 return loadFromUrl( urls, DefaultConflictResolver.getInstance( ) );
 134    }
 135   
 136    /**
 137    * Loads a RuleBase from several URLS, merging them and using the specified
 138    * ConflictResolver
 139    *
 140    * @param urls
 141    * @param resolver
 142    * @return RuleBase
 143    */
 144  2 public static RuleBase loadFromUrl( URL[] urls, ConflictResolver resolver )
 145    throws SAXException,
 146    IOException,
 147    IntegrationException
 148    {
 149  2 RuleBaseBuilder builder = new RuleBaseBuilder( );
 150  2 builder.setConflictResolver( resolver );
 151   
 152  2 for ( int i = 0; i < urls.length; ++i )
 153    {
 154  2 RuleSetReader reader = new RuleSetReader( );
 155  2 RuleSet ruleSet = reader.read( urls[i] );
 156  1 builder.addRuleSet( ruleSet );
 157    }
 158   
 159  1 return builder.build( );
 160    }
 161   
 162    /**
 163    * Loads a RuleBase from an InputStream using the default ConflictResolver
 164    *
 165    * This is a convenience method and calls public static RuleBase
 166    * loadFromInputStream(InputStream in, ConflictResolver resolver) passing
 167    * the DefaultConflictResolver
 168    *
 169    * @param in
 170    * @return ruleBase
 171    */
 172  0 public static RuleBase loadFromInputStream( InputStream in )
 173    throws SAXException,
 174    IOException,
 175    IntegrationException
 176    {
 177  0 return loadFromInputStream( in, DefaultConflictResolver.getInstance( ) );
 178    }
 179   
 180    /**
 181    * Loads a RuleBase from an InputStream using the default ConflictResolver
 182    *
 183    * @param in
 184    * @param resolver
 185    * @return ruleBase
 186    */
 187  0 public static RuleBase loadFromInputStream( InputStream in,
 188    ConflictResolver resolver )
 189    throws SAXException,
 190    IOException,
 191    IntegrationException
 192    {
 193  0 return loadFromInputStream( new InputStream[]{in}, resolver );
 194    }
 195   
 196    /**
 197    * Loads a RuleBase from an InputStream using the default ConflictResolver
 198    *
 199    * This is a convenience method and calls public static RuleBase
 200    * loadFromInputStream(InputStream[] ins, ConflictResolver resolver)
 201    * passing the DefaultConflictResolver
 202    *
 203    * @param ins
 204    * @return ruleBase
 205    */
 206  0 public static RuleBase loadFromInputStream( InputStream[] ins )
 207    throws SAXException,
 208    IOException,
 209    IntegrationException
 210    {
 211  0 return loadFromInputStream( ins, DefaultConflictResolver.getInstance( ) );
 212    }
 213   
 214    /**
 215    * Loads a RuleBase from an InputStream using the default ConflictResolver
 216    *
 217    * @param ins
 218    * @param resolver
 219    * @return ruleBase
 220    */
 221  0 public static RuleBase loadFromInputStream( InputStream[] ins,
 222    ConflictResolver resolver )
 223    throws SAXException,
 224    IOException,
 225    IntegrationException
 226    {
 227  0 RuleBaseBuilder builder = new RuleBaseBuilder( );
 228  0 builder.setConflictResolver( resolver );
 229  0 RuleBaseContext factoryContext = new RuleBaseContext( );
 230   
 231  0 for ( int i = 0; i < ins.length; ++i )
 232    {
 233  0 RuleSetReader reader = new RuleSetReader( factoryContext );
 234  0 RuleSet ruleSet = reader.read( ins[i] );
 235  0 builder.addRuleSet( ruleSet );
 236    }
 237   
 238  0 return builder.build( );
 239    }
 240   
 241    /**
 242    * Loads a RuleBase from a Reader using the default ConflictResolver
 243    *
 244    * This is a convenience method and calls public static RuleBase
 245    * loadFromReader(Reader in, ConflictResolver resolver) passing the
 246    * DefaultConflictResolver
 247    *
 248    * @param in
 249    * @return ruleBase
 250    */
 251  0 public static RuleBase loadFromReader( Reader in )
 252    throws SAXException,
 253    IOException,
 254    IntegrationException
 255    {
 256  0 return loadFromReader( in, DefaultConflictResolver.getInstance( ) );
 257    }
 258   
 259    /**
 260    * Loads a RuleBase from a Reader using the given ConflictResolver
 261    *
 262    * @param in
 263    * @param resolver
 264    * @return ruleBase
 265    */
 266  0 public static RuleBase loadFromReader( Reader in, ConflictResolver resolver )
 267    throws SAXException,
 268    IOException,
 269    IntegrationException
 270    {
 271  0 return loadFromReader( new Reader[]{in}, resolver );
 272    }
 273   
 274    /**
 275    * Loads a RuleBase from a Reader using the default ConflictResolver
 276    *
 277    * This is a convenience method and calls public static RuleBase
 278    * loadFromReader(Reader[] ins, ConflictResolver resolver) passing the
 279    * DefaultConflictResolver
 280    *
 281    * @param ins
 282    * @return ruleBase
 283    */
 284  0 public static RuleBase loadFromReader( Reader[] ins )
 285    throws SAXException,
 286    IOException,
 287    IntegrationException
 288    {
 289  0 return loadFromReader( ins, DefaultConflictResolver.getInstance( ) );
 290    }
 291   
 292    /**
 293    * Loads a RuleBase from a Reader using the given ConflictResolver
 294    *
 295    * @param ins
 296    * @param resolver
 297    * @return ruleBase
 298    */
 299  0 public static RuleBase loadFromReader( Reader[] ins,
 300    ConflictResolver resolver )
 301    throws SAXException,
 302    IOException,
 303    IntegrationException
 304    {
 305  0 RuleBaseContext factoryContext = new RuleBaseContext( );
 306   
 307  0 RuleBaseBuilder builder = new RuleBaseBuilder( factoryContext );
 308  0 builder.setConflictResolver( resolver );
 309   
 310  0 for ( int i = 0; i < ins.length; ++i )
 311    {
 312  0 RuleSetReader reader = new RuleSetReader( factoryContext );
 313  0 RuleSet ruleSet = reader.read( ins[i] );
 314  0 builder.addRuleSet( ruleSet );
 315    }
 316   
 317  0 return builder.build( );
 318    }
 319    }