org.drools.rule
Class Package

java.lang.Object
  extended by org.drools.rule.Package
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable

public class Package
extends java.lang.Object
implements java.io.Externalizable

Collection of related Rules.

Version:
$Id: Package.java,v 1.1 2005/07/26 01:06:31 mproctor Exp $
Author:
bob mcwhirter
See Also:
Rule, Serialized Form

Constructor Summary
Package()
          Default constructor - for Externalizable.
Package(java.lang.String name)
          Construct.
Package(java.lang.String name, java.lang.ClassLoader parentClassLoader)
          Construct.
 
Method Summary
 void addFactTemplate(FactTemplate factTemplate)
           
 void addFunction(java.lang.String functionName)
           
 void addGlobal(java.lang.String identifier, java.lang.Class clazz)
           
 void addImport(java.lang.String importEntry)
           
 void addRule(Rule rule)
          Add a Rule to this Package.
 void addRuleFlow(Process process)
          Add a rule flow to this package.
 void addStaticImport(java.lang.String functionImport)
           
 void checkValidity()
          This will throw an exception if the package is not valid
 void clear()
           
 boolean equals(java.lang.Object object)
           
 java.lang.String getErrorSummary()
          This will return the error summary (if any) if the package is invalid.
 FactTemplate getFactTemplate(java.lang.String name)
           
 java.util.List getFunctions()
           
 java.util.Map getGlobals()
           
 java.util.Set getImports()
           
 java.lang.String getName()
          Retrieve the name of this Package.
 PackageCompilationData getPackageCompilationData()
           
 Rule getRule(java.lang.String name)
          Retrieve a Rule by name.
 java.util.Map getRuleFlows()
          Get the rule flows for this package.
 Rule[] getRules()
          Retrieve all Rules in this Package.
 java.util.Set getStaticImports()
           
 int hashCode()
           
 boolean isValid()
           
 void readExternal(java.io.ObjectInput stream)
          Handles the read serialization of the Package.
 PackageCompilationData removeFunction(java.lang.String functionName)
           
 void removeFunctionImport(java.lang.String functionImport)
           
 void removeGlobal(java.lang.String identifier)
           
 void removeImport(java.lang.String importEntry)
           
 PackageCompilationData removeRule(Rule rule)
           
 void removeRuleFlow(java.lang.String id)
          Rule flows can be removed by ID.
 void setError(java.lang.String summary)
          Once this is called, the package will be marked as invalid
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput stream)
          Handles the write serialization of the Package.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Package

public Package()
Default constructor - for Externalizable. This should never be used by a user, as it will result in an invalid state for the instance.


Package

public Package(java.lang.String name)
Construct.

Parameters:
name - The name of this Package.

Package

public Package(java.lang.String name,
               java.lang.ClassLoader parentClassLoader)
Construct.

Parameters:
name - The name of this Package.
Method Detail

writeExternal

public void writeExternal(java.io.ObjectOutput stream)
                   throws java.io.IOException
Handles the write serialization of the Package. Patterns in Rules may reference generated data which cannot be serialized by default methods. The Package uses PackageCompilationData to hold a reference to the generated bytecode. The generated bytecode must be restored before any Rules.

Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput stream)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Handles the read serialization of the Package. Patterns in Rules may reference generated data which cannot be serialized by default methods. The Package uses PackageCompilationData to hold a reference to the generated bytecode; which must be restored before any Rules. A custom ObjectInputStream, able to resolve classes against the bytecode in the PackageCompilationData, is used to restore the Rules.

Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

getName

public java.lang.String getName()
Retrieve the name of this Package.

Returns:
The name of this Package.

addImport

public void addImport(java.lang.String importEntry)

removeImport

public void removeImport(java.lang.String importEntry)

getImports

public java.util.Set getImports()

addStaticImport

public void addStaticImport(java.lang.String functionImport)

addFunction

public void addFunction(java.lang.String functionName)

getFunctions

public java.util.List getFunctions()

removeFunctionImport

public void removeFunctionImport(java.lang.String functionImport)

getStaticImports

public java.util.Set getStaticImports()

addGlobal

public void addGlobal(java.lang.String identifier,
                      java.lang.Class clazz)

removeGlobal

public void removeGlobal(java.lang.String identifier)

getGlobals

public java.util.Map getGlobals()

removeFunction

public PackageCompilationData removeFunction(java.lang.String functionName)

getFactTemplate

public FactTemplate getFactTemplate(java.lang.String name)

addFactTemplate

public void addFactTemplate(FactTemplate factTemplate)

addRule

public void addRule(Rule rule)
Add a Rule to this Package.

Parameters:
rule - The rule to add.
Throws:
DuplicateRuleNameException - If the Rule attempting to be added has the same name as another previously added Rule.
InvalidRuleException - If the Rule is not valid.

addRuleFlow

public void addRuleFlow(Process process)
Add a rule flow to this package.


getRuleFlows

public java.util.Map getRuleFlows()
Get the rule flows for this package. The key is the ruleflow id. It will be Collections.EMPTY_MAP if none have been added.


removeRuleFlow

public void removeRuleFlow(java.lang.String id)
Rule flows can be removed by ID.


removeRule

public PackageCompilationData removeRule(Rule rule)

getRule

public Rule getRule(java.lang.String name)
Retrieve a Rule by name.

Parameters:
name - The name of the Rule to retrieve.
Returns:
The named Rule, or null if not such Rule has been added to this Package.

getRules

public Rule[] getRules()
Retrieve all Rules in this Package.

Returns:
An array of all Rules in this Package.

getPackageCompilationData

public PackageCompilationData getPackageCompilationData()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setError

public void setError(java.lang.String summary)
Once this is called, the package will be marked as invalid


isValid

public boolean isValid()
Returns:
true (default) if there are no build/structural problems.

checkValidity

public void checkValidity()
This will throw an exception if the package is not valid


getErrorSummary

public java.lang.String getErrorSummary()
This will return the error summary (if any) if the package is invalid.


equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

clear

public void clear()