org.drools.io
Class RuleBaseLoader

java.lang.Object
  extended by org.drools.io.RuleBaseLoader

public final class RuleBaseLoader
extends java.lang.Object

Convenience methods for loading a RuleBase, as well as lower level calls for building up a rule base from RuleSets. Note that the loadXXX static helper methods work directly off DRL, building/compiling behind the scenes. The addXXX methods generally work with pre compiled rules binaries (DDJ's as they are known).

The RuleBaseLoader provides convenience methods for loading RuleBase s from streams. RuleBaseLoader is thread-safe and as such may be used to build multiple RuleBase s simultaneously by multiple threads.

See Also:
RuleSet, RuleBase, RuleSetReader, RuleBaseBuilder, SerializableRuleBaseProxy

Constructor Summary
RuleBaseLoader()
          Default constructor
RuleBaseLoader(ConflictResolver resolver)
          Default constructor
 
Method Summary
 void addFromByteArray(byte[] bytes)
          Creates a JarInputStream and defines each .class in custom classLoader The RuleSet is serialised out using the custom classLoader Loads a ruleset from the DDJ bytes.
 void addFromByteArray(byte[][] bytes)
          This will add multiple rulesets.
 void addFromRuleSet(RuleSet ruleSet)
           
 void addFromRuleSet(RuleSet[] ruleSets)
           
 void addFromRuleSetLoader(RuleSetLoader ruleSetLoader)
          Adds to the rulebase from a RuleSetLoader instance.
 void addFromRuleSetLoader(RuleSetLoader[] ruleSetLoaders)
          Loads a RuleBase using several URLs, using the DefaultConflictResolver.
 void addFromUrl(java.net.URL url)
          Loads a RuleBase from a URL using the given ConflictResolver The URL must be to a DDJ compiled resource, or a conf file pointing to the DDJ compiled rules.
 void addFromUrl(java.net.URL[] urls)
          Loads a RuleBase from several URLS, merging them and using the specified ConflictResolver.
 RuleBase buildRuleBase()
          This will return a rulebase based on the added rulesets.
static RuleBase loadFromInputStream(java.io.InputStream in)
          Loads a RuleBase from an InputStream using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromInputStream(InputStream in, ConflictResolver resolver) passing the DefaultConflictResolver
static RuleBase loadFromInputStream(java.io.InputStream[] ins)
          Loads a RuleBase from an InputStream using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromInputStream(InputStream[] ins, ConflictResolver resolver) passing the DefaultConflictResolver
static RuleBase loadFromInputStream(java.io.InputStream[] ins, ConflictResolver resolver)
          Loads a RuleBase from an InputStream using the default ConflictResolver
static RuleBase loadFromInputStream(java.io.InputStream in, ConflictResolver resolver)
          Loads a RuleBase from an InputStream using the default ConflictResolver
static RuleBase loadFromReader(java.io.Reader in)
          Loads a RuleBase from a Reader using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromReader(Reader in, ConflictResolver resolver) passing the DefaultConflictResolver
static RuleBase loadFromReader(java.io.Reader[] ins)
          Loads a RuleBase from a Reader using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromReader(Reader[] ins, ConflictResolver resolver) passing the DefaultConflictResolver
static RuleBase loadFromReader(java.io.Reader[] ins, ConflictResolver resolver)
          Loads a RuleBase from a Reader using the given ConflictResolver
static RuleBase loadFromReader(java.io.Reader in, ConflictResolver resolver)
          Loads a RuleBase from a Reader using the given ConflictResolver
static RuleBase loadFromUrl(java.net.URL url)
          Loads a RuleBase from a URL using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromUrl(URL url, ConflictResolver resolver) passing the DefaultConflictResolver
static RuleBase loadFromUrl(java.net.URL[] urls)
          Loads a RuleBase using several URLs, using the DefaultConflictResolver.
static RuleBase loadFromUrl(java.net.URL[] urls, ConflictResolver resolver)
          Loads a RuleBase from several URLS, merging them and using the specified ConflictResolver
static RuleBase loadFromUrl(java.net.URL url, ConflictResolver resolver)
          Loads a RuleBase from a URL using the given ConflictResolver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleBaseLoader

public RuleBaseLoader()
Default constructor


RuleBaseLoader

public RuleBaseLoader(ConflictResolver resolver)
Default constructor

Method Detail

addFromRuleSetLoader

public void addFromRuleSetLoader(RuleSetLoader[] ruleSetLoaders)
                          throws org.xml.sax.SAXException,
                                 java.io.IOException,
                                 IntegrationException
Loads a RuleBase using several URLs, using the DefaultConflictResolver. This is a convenience method and calls public static RuleBase loadFromUrl(URL[] url, ConflictResolver resolver) passing the DefaultConflictResolver

Parameters:
urls -
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

addFromRuleSetLoader

public void addFromRuleSetLoader(RuleSetLoader ruleSetLoader)
                          throws org.xml.sax.SAXException,
                                 java.io.IOException,
                                 IntegrationException
Adds to the rulebase from a RuleSetLoader instance. The binaries from the ruleset loader will be kept for serialization purposes.

Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

addFromUrl

public void addFromUrl(java.net.URL[] urls)
                throws org.xml.sax.SAXException,
                       java.io.IOException,
                       IntegrationException
Loads a RuleBase from several URLS, merging them and using the specified ConflictResolver. URLS should be either to compiled DDJ rules, or a configuration file which indicates where to find the DDJs.

Parameters:
urls -
resolver -
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

addFromUrl

public void addFromUrl(java.net.URL url)
                throws org.xml.sax.SAXException,
                       java.io.IOException,
                       IntegrationException
Loads a RuleBase from a URL using the given ConflictResolver The URL must be to a DDJ compiled resource, or a conf file pointing to the DDJ compiled rules. If you do not use pre compiled rulesets, use one of the static helper methods instead.

Parameters:
url -
resolver -
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

addFromByteArray

public void addFromByteArray(byte[][] bytes)
                      throws IntegrationException,
                             java.io.IOException,
                             org.xml.sax.SAXException
This will add multiple rulesets. Bytes should be for DDJ compiled rules

Parameters:
bytes -
Throws:
IntegrationException
java.io.IOException
org.xml.sax.SAXException

addFromByteArray

public void addFromByteArray(byte[] bytes)
                      throws java.io.IOException,
                             IntegrationException,
                             org.xml.sax.SAXException
Creates a JarInputStream and defines each .class in custom classLoader The RuleSet is serialised out using the custom classLoader Loads a ruleset from the DDJ bytes.

Parameters:
bytes -
Throws:
java.io.IOException
IntegrationException
org.xml.sax.SAXException

addFromRuleSet

public void addFromRuleSet(RuleSet ruleSet)
                    throws org.xml.sax.SAXException,
                           java.io.IOException,
                           IntegrationException
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

addFromRuleSet

public void addFromRuleSet(RuleSet[] ruleSets)
                    throws org.xml.sax.SAXException,
                           java.io.IOException,
                           IntegrationException
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

buildRuleBase

public RuleBase buildRuleBase()
This will return a rulebase based on the added rulesets. The rulebase should be serializable by default.

Returns:

loadFromUrl

public static RuleBase loadFromUrl(java.net.URL url)
                            throws org.xml.sax.SAXException,
                                   java.io.IOException,
                                   IntegrationException
Loads a RuleBase from a URL using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromUrl(URL url, ConflictResolver resolver) passing the DefaultConflictResolver

Parameters:
url - A URL to the DRL to compile and load.
Returns:
RuleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromUrl

public static RuleBase loadFromUrl(java.net.URL url,
                                   ConflictResolver resolver)
                            throws org.xml.sax.SAXException,
                                   java.io.IOException,
                                   IntegrationException
Loads a RuleBase from a URL using the given ConflictResolver

Parameters:
url -
resolver -
Returns:
RuleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromUrl

public static RuleBase loadFromUrl(java.net.URL[] urls)
                            throws org.xml.sax.SAXException,
                                   java.io.IOException,
                                   IntegrationException
Loads a RuleBase using several URLs, using the DefaultConflictResolver. This is a convenience method and calls public static RuleBase loadFromUrl(URL[] url, ConflictResolver resolver) passing the DefaultConflictResolver

Parameters:
urls -
Returns:
RuleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromUrl

public static RuleBase loadFromUrl(java.net.URL[] urls,
                                   ConflictResolver resolver)
                            throws org.xml.sax.SAXException,
                                   java.io.IOException,
                                   IntegrationException
Loads a RuleBase from several URLS, merging them and using the specified ConflictResolver

Parameters:
urls -
resolver -
Returns:
RuleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromInputStream

public static RuleBase loadFromInputStream(java.io.InputStream in)
                                    throws org.xml.sax.SAXException,
                                           java.io.IOException,
                                           IntegrationException
Loads a RuleBase from an InputStream using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromInputStream(InputStream in, ConflictResolver resolver) passing the DefaultConflictResolver

Parameters:
in -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromInputStream

public static RuleBase loadFromInputStream(java.io.InputStream in,
                                           ConflictResolver resolver)
                                    throws org.xml.sax.SAXException,
                                           java.io.IOException,
                                           IntegrationException
Loads a RuleBase from an InputStream using the default ConflictResolver

Parameters:
in -
resolver -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromInputStream

public static RuleBase loadFromInputStream(java.io.InputStream[] ins)
                                    throws org.xml.sax.SAXException,
                                           java.io.IOException,
                                           IntegrationException
Loads a RuleBase from an InputStream using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromInputStream(InputStream[] ins, ConflictResolver resolver) passing the DefaultConflictResolver

Parameters:
ins -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromInputStream

public static RuleBase loadFromInputStream(java.io.InputStream[] ins,
                                           ConflictResolver resolver)
                                    throws org.xml.sax.SAXException,
                                           java.io.IOException,
                                           IntegrationException
Loads a RuleBase from an InputStream using the default ConflictResolver

Parameters:
ins -
resolver -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromReader

public static RuleBase loadFromReader(java.io.Reader in)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException,
                                      IntegrationException
Loads a RuleBase from a Reader using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromReader(Reader in, ConflictResolver resolver) passing the DefaultConflictResolver

Parameters:
in -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromReader

public static RuleBase loadFromReader(java.io.Reader in,
                                      ConflictResolver resolver)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException,
                                      IntegrationException
Loads a RuleBase from a Reader using the given ConflictResolver

Parameters:
in -
resolver -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromReader

public static RuleBase loadFromReader(java.io.Reader[] ins)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException,
                                      IntegrationException
Loads a RuleBase from a Reader using the default ConflictResolver This is a convenience method and calls public static RuleBase loadFromReader(Reader[] ins, ConflictResolver resolver) passing the DefaultConflictResolver

Parameters:
ins -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException

loadFromReader

public static RuleBase loadFromReader(java.io.Reader[] ins,
                                      ConflictResolver resolver)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException,
                                      IntegrationException
Loads a RuleBase from a Reader using the given ConflictResolver

Parameters:
ins -
resolver -
Returns:
ruleBase
Throws:
org.xml.sax.SAXException
java.io.IOException
IntegrationException