org.drools.compiler
Class PackageBuilder

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

public class PackageBuilder
extends 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. Normally, a complete package is built using one of the applicable addPackageFromXXX methods. It is however possible to construct a package incrementally by adding individual component parts. When a package is built incrementally package level attributes are cached and applied to Rules subsequently added. Caution should be exercised when using the same PackageBuilder to construct packages from multiple sources as the cached package level attributes will still apply even if the resource added to PackageBuilder does not explicitly include package level attributes.


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.
static class PackageBuilder.SrcError
           
static class PackageBuilder.SrcErrorHandler
           
 
Field Summary
protected  DateFormats dateFormats
           
static RuleBuilder ruleBuilder
           
 
Constructor Summary
PackageBuilder()
          Use this when package is starting from scratch.
PackageBuilder(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(Package pkg, PackageBuilderConfiguration configuration)
           
PackageBuilder(RuleBase ruleBase)
           
PackageBuilder(RuleBase ruleBase, PackageBuilderConfiguration configuration)
           
 
Method Summary
 void addDsl(org.drools.io.Resource resource)
           
 void addKnowledgeResource(org.drools.io.Resource resource, org.drools.builder.ResourceType type, org.drools.builder.ResourceConfiguration configuration)
           
 void addPackage(Package newPkg)
           
 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 addPackageFromBrl(org.drools.io.Resource resource)
           
 void addPackageFromDrl(Reader reader)
          Load a rule package from DRL source.
 void addPackageFromDrl(Reader source, Reader dsl)
          Load a rule package from DRL source using the supplied DSL configuration.
 void addPackageFromDrl(org.drools.io.Resource resource)
           
 void addPackageFromDslr(org.drools.io.Resource resource)
           
 void addPackageFromXml(Reader reader)
          Load a rule package from XML source.
 void addPackageFromXml(org.drools.io.Resource resource)
           
 void addProcessFromXml(Reader processSource)
           
 void addProcessFromXml(org.drools.io.Resource resource)
           
 void addRuleFlow(Reader processSource)
          Add a ruleflow (.rfm) asset to this package.
 boolean buildTypeDeclarationInterfaces(Class cls, Set<TypeDeclaration> tdecls)
           
 void buildTypeDeclarations(Class<?> cls, Set<TypeDeclaration> tdecls)
           
 void compileAll()
           
 DateFormats getDateFormats()
           
 String getDefaultDialect()
           
 DefaultExpander getDslExpander()
          Returns an expander for DSLs (only if there is a DSL configured for this package).
 PackageBuilderErrors getErrors()
           
 Map<String,Class<?>> getGlobals()
           
 Package getPackage()
           
 PackageBuilderConfiguration getPackageBuilderConfiguration()
          Return the PackageBuilderConfiguration for this PackageBuilder session
 Map<String,PackageRegistry> getPackageRegistry()
           
 PackageRegistry getPackageRegistry(String name)
           
 Package[] getPackages()
           
 org.drools.util.CompositeClassLoader getRootClassLoader()
           
 TypeDeclaration getTypeDeclaration(Class<?> cls)
           
 boolean hasErrors()
          This will return true if there were errors in the package building and compiling phase
 boolean isEmpty(String string)
           
 void reloadAll()
           
protected  void resetErrors()
          Reset the error list.
static Collection<TypeDeclarationDescr> sortByHierarchy(List<TypeDeclarationDescr> typeDeclarations)
          Utility method to sort declared beans.
 void updateResults()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ruleBuilder

public static final RuleBuilder ruleBuilder

dateFormats

protected DateFormats dateFormats
Constructor Detail

PackageBuilder

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


PackageBuilder

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


PackageBuilder

public PackageBuilder(RuleBase ruleBase)

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(Package pkg,
                      PackageBuilderConfiguration configuration)

PackageBuilder

public PackageBuilder(RuleBase ruleBase,
                      PackageBuilderConfiguration configuration)
Method Detail

addPackageFromDrl

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

Parameters:
reader -
Throws:
DroolsParserException
IOException

addPackageFromDrl

public void addPackageFromDrl(org.drools.io.Resource resource)
                       throws DroolsParserException,
                              IOException
Throws:
DroolsParserException
IOException

addPackageFromXml

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

Parameters:
reader -
Throws:
DroolsParserException
IOException

addPackageFromXml

public void addPackageFromXml(org.drools.io.Resource resource)
                       throws DroolsParserException,
                              IOException
Throws:
DroolsParserException
IOException

addPackageFromDrl

public void addPackageFromDrl(Reader source,
                              Reader dsl)
                       throws DroolsParserException,
                              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
IOException

addPackageFromDslr

public void addPackageFromDslr(org.drools.io.Resource resource)
                        throws DroolsParserException,
                               IOException
Throws:
DroolsParserException
IOException

addPackageFromBrl

public void addPackageFromBrl(org.drools.io.Resource resource)
                       throws DroolsParserException
Throws:
DroolsParserException

addDsl

public void addDsl(org.drools.io.Resource resource)
            throws IOException
Throws:
IOException

addRuleFlow

public void addRuleFlow(Reader processSource)
Add a ruleflow (.rfm) asset to this package.


addProcessFromXml

public void addProcessFromXml(org.drools.io.Resource resource)

addProcessFromXml

public void addProcessFromXml(Reader processSource)

addKnowledgeResource

public void addKnowledgeResource(org.drools.io.Resource resource,
                                 org.drools.builder.ResourceType type,
                                 org.drools.builder.ResourceConfiguration configuration)

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.


isEmpty

public boolean isEmpty(String string)

updateResults

public void updateResults()

compileAll

public void compileAll()

reloadAll

public void reloadAll()

addPackage

public void addPackage(Package newPkg)

getTypeDeclaration

public TypeDeclaration getTypeDeclaration(Class<?> cls)

buildTypeDeclarations

public void buildTypeDeclarations(Class<?> cls,
                                  Set<TypeDeclaration> tdecls)

buildTypeDeclarationInterfaces

public boolean buildTypeDeclarationInterfaces(Class cls,
                                              Set<TypeDeclaration> tdecls)

getPackage

public 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.

getPackages

public Package[] getPackages()

getPackageBuilderConfiguration

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

Returns:
The PackageBuilderConfiguration

getPackageRegistry

public PackageRegistry getPackageRegistry(String name)

getPackageRegistry

public Map<String,PackageRegistry> getPackageRegistry()

getDateFormats

public DateFormats getDateFormats()

getDslExpander

public DefaultExpander getDslExpander()
Returns an expander for DSLs (only if there is a DSL configured for this package).


getGlobals

public Map<String,Class<?>> getGlobals()

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.


getDefaultDialect

public String getDefaultDialect()

getRootClassLoader

public org.drools.util.CompositeClassLoader getRootClassLoader()

sortByHierarchy

public static Collection<TypeDeclarationDescr> sortByHierarchy(List<TypeDeclarationDescr> typeDeclarations)
Utility method to sort declared beans. Linearizes the hierarchy, i.e.generates a sequence of declaration such that, if Sub is subclass of Sup, then the index of Sub will be > than the index of Sup in the resulting collection. This ensures that superclasses are processed before their subclasses

Parameters:
typeDeclarations -
Returns:


Copyright © 2001-2013 JBoss Inc.. All Rights Reserved.