org.drools.compiler
Class PackageBuilder

java.lang.Object
  extended by org.drools.compiler.PackageBuilder
All Implemented Interfaces:
DeepCloneable<PackageBuilder>

public class PackageBuilder
extends Object
implements DeepCloneable<PackageBuilder>

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 addPackageFromDecisionTable(org.drools.io.Resource resource, org.drools.builder.ResourceConfiguration configuration)
           
 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(Reader reader, org.drools.io.Resource sourceResource)
          Load a rule package from DRL source and associate all loaded artifacts with the given resource.
 void addPackageFromDrl(org.drools.io.Resource resource)
           
 void addPackageFromDslr(org.drools.io.Resource resource)
           
 void addPackageFromPMML(org.drools.io.Resource resource, org.drools.builder.ResourceType type, org.drools.builder.ResourceConfiguration configuration)
           
 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.
protected  TypeFieldDescr buildInheritedFieldDescrFromDefinition(org.drools.definition.type.FactField fld)
           
 boolean buildTypeDeclarationInterfaces(Class cls, Set<TypeDeclaration> tdecls)
           
 void buildTypeDeclarations(Class<?> cls, Set<TypeDeclaration> tdecls)
           
 void compileAll()
           
 PackageBuilder deepClone()
           
 TypeDeclaration getAndRegisterTypeDeclaration(Class<?> cls, String packageName)
           
 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
 List<PackageDescr> getPackageDescrs(String packageName)
           
 Collection<String> getPackageNames()
           
 Map<String,PackageRegistry> getPackageRegistry()
           
 PackageRegistry getPackageRegistry(String name)
           
 Package[] getPackages()
           
 org.drools.builder.KnowledgeBuilderResults getProblems(org.drools.builder.ResultSeverity... problemTypes)
           
 CompositeClassLoader getRootClassLoader()
           
 TypeDeclaration getTypeDeclaration(Class<?> cls)
           
 List<DroolsWarning> getWarningList()
           
 boolean hasErrors()
          This will return true if there were errors in the package building and compiling phase
 boolean hasInfo()
           
 boolean hasProblems(org.drools.builder.ResultSeverity... problemTypes)
           
 boolean hasWarnings()
           
 boolean isEmpty(String string)
           
 void registerBuildResource(org.drools.io.Resource resource)
           
 void registerBuildResources(List<org.drools.io.Resource> resources)
           
 void reloadAll()
           
protected  void resetErrors()
          Reset the error list.
protected  void resetProblems()
           
protected  void resetWarnings()
           
 Collection<AbstractClassTypeDeclarationDescr> sortByHierarchy(List<AbstractClassTypeDeclarationDescr> typeDeclarations)
          Utility method to sort declared beans.
 void undo()
           
 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

deepClone

public PackageBuilder deepClone()
Specified by:
deepClone in interface DeepCloneable<PackageBuilder>

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(Reader reader,
                              org.drools.io.Resource sourceResource)
                       throws DroolsParserException,
                              IOException
Load a rule package from DRL source and associate all loaded artifacts with the given resource.

Parameters:
reader -
sourceResource - the source resource for the read artifacts
Throws:
DroolsParserException
IOException

addPackageFromDecisionTable

public void addPackageFromDecisionTable(org.drools.io.Resource resource,
                                        org.drools.builder.ResourceConfiguration configuration)
                                 throws DroolsParserException,
                                        IOException
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)

addPackageFromPMML

public void addPackageFromPMML(org.drools.io.Resource resource,
                               org.drools.builder.ResourceType type,
                               org.drools.builder.ResourceConfiguration configuration)
                        throws Exception
Throws:
Exception

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)

getAndRegisterTypeDeclaration

public TypeDeclaration getAndRegisterTypeDeclaration(Class<?> cls,
                                                     String packageName)

getTypeDeclaration

public TypeDeclaration getTypeDeclaration(Class<?> cls)

buildTypeDeclarations

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

buildTypeDeclarationInterfaces

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

buildInheritedFieldDescrFromDefinition

protected TypeFieldDescr buildInheritedFieldDescrFromDefinition(org.drools.definition.type.FactField fld)

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()

getPackageNames

public Collection<String> getPackageNames()

getPackageDescrs

public List<PackageDescr> getPackageDescrs(String packageName)

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


getProblems

public org.drools.builder.KnowledgeBuilderResults getProblems(org.drools.builder.ResultSeverity... problemTypes)

hasProblems

public boolean hasProblems(org.drools.builder.ResultSeverity... problemTypes)

hasWarnings

public boolean hasWarnings()

hasInfo

public boolean hasInfo()

getWarningList

public List<DroolsWarning> getWarningList()

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.


resetWarnings

protected void resetWarnings()

resetProblems

protected void resetProblems()

getDefaultDialect

public String getDefaultDialect()

getRootClassLoader

public CompositeClassLoader getRootClassLoader()

sortByHierarchy

public Collection<AbstractClassTypeDeclarationDescr> sortByHierarchy(List<AbstractClassTypeDeclarationDescr> 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:

registerBuildResource

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

registerBuildResources

public void registerBuildResources(List<org.drools.io.Resource> resources)

undo

public void undo()


Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.