org.drools.compiler
Class PackageBuilder

java.lang.Object
  extended by org.drools.compiler.PackageBuilder

public class PackageBuilder
extends java.lang.Object

This is the main compiler class for parsing and compiling rules and assembling or merging them into a binary Package instance. This can be done by merging into existing binary packages, or totally from source. If you are using the Java dialect the JavaDialectConfiguration will attempt to validate that the specified compiler is in the classpath, using ClassLoader.loasClass(String). If you intented to just Janino sa the compiler you must either overload the compiler property before instantiating this class or the PackageBuilder, or make sure Eclipse is in the classpath, as Eclipse is the default.


Nested Class Summary
static class PackageBuilder.ErrorHandler
          This is the super of the error handlers.
static class PackageBuilder.FunctionErrorHandler
           
static class PackageBuilder.MissingPackageNameException
           
static class PackageBuilder.PackageMergeException
           
static class PackageBuilder.RuleErrorHandler
           
static class PackageBuilder.RuleInvokerErrorHandler
          There isn't much point in reporting invoker errors, as they are no help.
 
Constructor Summary
PackageBuilder()
          Use this when package is starting from scratch.
PackageBuilder(java.lang.Package pkg)
          This will allow you to merge rules into this pre existing package.
PackageBuilder(PackageBuilderConfiguration configuration)
          Pass a specific configuration for the PackageBuilder PackageBuilderConfiguration is not thread safe and it also contains state.
PackageBuilder(java.lang.Package pkg, PackageBuilderConfiguration configuration)
          This allows you to pass in a pre existing package, and a configuration (for instance to set the classloader).
 
Method Summary
 void addPackage(PackageDescr packageDescr)
          This adds a package from a Descr/AST This will also trigger a compile, if there are any generated classes to compile of course.
 void addPackageFromDrl(java.io.Reader reader)
          Load a rule package from DRL source.
 void addPackageFromDrl(java.io.Reader source, java.io.Reader dsl)
          Load a rule package from DRL source using the supplied DSL configuration.
 void addPackageFromXml(java.io.Reader reader)
          Load a rule package from XML source.
 void addRuleFlow(java.io.Reader processSource)
          Add a ruleflow (.rt) asset to this package.
 ClassFieldExtractorCache getClassFieldExtractorCache()
          Return the ClassFieldExtractorCache, this should only be used internally, and is subject to change
 Dialect getDefaultDialect()
           
 DialectRegistry getDialectRegistry()
           
 PackageBuilderErrors getErrors()
           
 java.lang.Package getPackage()
           
 PackageBuilderConfiguration getPackageBuilderConfiguration()
          Return the PackageBuilderConfiguration for this PackageBuilder session
 TypeResolver getTypeResolver()
           
 boolean hasErrors()
          This will return true if there were errors in the package building and compiling phase
protected  void resetErrors()
          Reset the error list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackageBuilder

public PackageBuilder()
Use this when package is starting from scratch.


PackageBuilder

public PackageBuilder(java.lang.Package pkg)
This will allow you to merge rules into this pre existing package.


PackageBuilder

public PackageBuilder(PackageBuilderConfiguration configuration)
Pass a specific configuration for the PackageBuilder PackageBuilderConfiguration is not thread safe and it also contains state. Once it is created and used in one or more PackageBuilders it should be considered immutable. Do not modify its properties while it is being used by a PackageBuilder.

Parameters:
configuration -

PackageBuilder

public PackageBuilder(java.lang.Package pkg,
                      PackageBuilderConfiguration configuration)
This allows you to pass in a pre existing package, and a configuration (for instance to set the classloader).

Parameters:
pkg - A pre existing package (can be null if none exists)
configuration - Optional configuration for this builder.
Method Detail

addPackageFromDrl

public void addPackageFromDrl(java.io.Reader reader)
                       throws DroolsParserException,
                              java.io.IOException
Load a rule package from DRL source.

Parameters:
reader -
Throws:
DroolsParserException
java.io.IOException

addPackageFromXml

public void addPackageFromXml(java.io.Reader reader)
                       throws DroolsParserException,
                              java.io.IOException
Load a rule package from XML source.

Parameters:
reader -
Throws:
DroolsParserException
java.io.IOException

addPackageFromDrl

public void addPackageFromDrl(java.io.Reader source,
                              java.io.Reader dsl)
                       throws DroolsParserException,
                              java.io.IOException
Load a rule package from DRL source using the supplied DSL configuration.

Parameters:
source - The source of the rules.
dsl - The source of the domain specific language configuration.
Throws:
DroolsParserException
java.io.IOException

addRuleFlow

public void addRuleFlow(java.io.Reader processSource)
Add a ruleflow (.rt) asset to this package.


addPackage

public void addPackage(PackageDescr packageDescr)
This adds a package from a Descr/AST This will also trigger a compile, if there are any generated classes to compile of course.


getTypeResolver

public TypeResolver getTypeResolver()
Returns:
a Type resolver, lazily. If one does not exist yet, it will be initialised.

getPackage

public java.lang.Package getPackage()
Returns:
The compiled package. The package may contain errors, which you can report on by calling getErrors or printErrors. If you try to add an invalid package (or rule) to a RuleBase, you will get a runtime exception. Compiled packages are serializable.

getPackageBuilderConfiguration

public PackageBuilderConfiguration getPackageBuilderConfiguration()
Return the PackageBuilderConfiguration for this PackageBuilder session

Returns:
The PackageBuilderConfiguration

getDialectRegistry

public DialectRegistry getDialectRegistry()

getDefaultDialect

public Dialect getDefaultDialect()

getClassFieldExtractorCache

public ClassFieldExtractorCache getClassFieldExtractorCache()
Return the ClassFieldExtractorCache, this should only be used internally, and is subject to change

Returns:
the ClsasFieldExtractorCache

hasErrors

public boolean hasErrors()
This will return true if there were errors in the package building and compiling phase


getErrors

public PackageBuilderErrors getErrors()
Returns:
A list of Error objects that resulted from building and compiling the package.

resetErrors

protected void resetErrors()
Reset the error list. This is useful when incrementally building packages. Care should be used when building this, if you clear this when there were errors on items that a rule depends on (eg functions), then you will get spurious errors which will not be that helpful.