org.drools.rule
Class Package

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

public class Package
extends Object
implements Externalizable

Collection of related Rules.

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

Constructor Summary
Package()
          Default constructor - for Externalizable.
Package(String name)
          Construct.
 
Method Summary
 void addEntryPointId(String id)
           
 void addFactTemplate(FactTemplate factTemplate)
           
 void addFunction(Function function)
           
 void addGlobal(String identifier, Class<?> clazz)
           
 void addImport(ImportDeclaration importDecl)
           
 void addProcess(org.drools.definition.process.Process process)
          Add a rule flow to this package.
 void addRule(Rule rule)
          Add a Rule to this Package.
 void addStaticImport(String functionImport)
           
 void addTypeDeclaration(TypeDeclaration typeDecl)
           
 void checkValidity()
          This will throw an exception if the package is not valid
 void clear()
           
 boolean equals(Object object)
           
 ClassFieldAccessorStore getClassFieldAccessorStore()
           
 DialectRuntimeRegistry getDialectRuntimeRegistry()
           
 Set<String> getEntryPointIds()
           
 String getErrorSummary()
          This will return the error summary (if any) if the package is invalid.
 FactTemplate getFactTemplate(String name)
           
 org.drools.definition.type.FactType getFactType(String typeName)
           
 Map<String,Function> getFunctions()
           
 Map<String,String> getGlobals()
           
 Map<String,ImportDeclaration> getImports()
           
 String getName()
          Retrieve the name of this Package.
 Rule getRule(String name)
          Retrieve a Rule by name.
 Map<String,org.drools.definition.process.Process> getRuleFlows()
          Get the rule flows for this package.
 Rule[] getRules()
          Retrieve all Rules in this Package.
 Set getStaticImports()
           
 TypeDeclaration getTypeDeclaration(String type)
           
 Map<String,TypeDeclaration> getTypeDeclarations()
           
 TypeResolver getTypeResolver()
           
 int hashCode()
           
 boolean isEvent(Class clazz)
          Returns true if clazz is imported as an Event class in this package
 boolean isValid()
           
 void readExternal(ObjectInput stream)
          Handles the read serialization of the Package.
 void removeFunction(String functionName)
           
 void removeFunctionImport(String functionImport)
           
 void removeGlobal(String identifier)
           
 void removeImport(String importEntry)
           
 void removeRule(Rule rule)
           
 void removeRuleFlow(String id)
          Rule flows can be removed by ID.
 void removeTypeDeclaration(String type)
           
 void setClassFieldAccessorCache(ClassFieldAccessorCache classFieldAccessorCache)
           
 void setError(String summary)
          Once this is called, the package will be marked as invalid
 void setTypeResolver(TypeResolver typeResolver)
           
 String toString()
           
 void writeExternal(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(String name)
Construct.

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

writeExternal

public void writeExternal(ObjectOutput stream)
                   throws 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 Externalizable
Parameters:
stream - out the stream to write the object to; should be an instance of DroolsObjectOutputStream or OutputStream
Throws:
IOException

readExternal

public void readExternal(ObjectInput stream)
                  throws IOException,
                         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 Externalizable
Parameters:
stream, - the stream to read data from in order to restore the object; should be an instance of DroolsObjectInputStream or InputStream
Throws:
IOException
ClassNotFoundException

getName

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

Returns:
The name of this Package.

getDialectRuntimeRegistry

public DialectRuntimeRegistry getDialectRuntimeRegistry()

addImport

public void addImport(ImportDeclaration importDecl)

removeImport

public void removeImport(String importEntry)

getImports

public Map<String,ImportDeclaration> getImports()

addTypeDeclaration

public void addTypeDeclaration(TypeDeclaration typeDecl)

removeTypeDeclaration

public void removeTypeDeclaration(String type)

getTypeDeclarations

public Map<String,TypeDeclaration> getTypeDeclarations()

getTypeDeclaration

public TypeDeclaration getTypeDeclaration(String type)

addStaticImport

public void addStaticImport(String functionImport)

addFunction

public void addFunction(Function function)

getFunctions

public Map<String,Function> getFunctions()

removeFunctionImport

public void removeFunctionImport(String functionImport)

getStaticImports

public Set getStaticImports()

addGlobal

public void addGlobal(String identifier,
                      Class<?> clazz)

removeGlobal

public void removeGlobal(String identifier)

getGlobals

public Map<String,String> getGlobals()

removeFunction

public void removeFunction(String functionName)

getFactTemplate

public FactTemplate getFactTemplate(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.

addProcess

public void addProcess(org.drools.definition.process.Process process)
Add a rule flow to this package.


getRuleFlows

public Map<String,org.drools.definition.process.Process> 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(String id)
Rule flows can be removed by ID.


removeRule

public void removeRule(Rule rule)

getRule

public Rule getRule(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.

toString

public String toString()
Overrides:
toString in class Object

setError

public void setError(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 String getErrorSummary()
This will return the error summary (if any) if the package is invalid.


equals

public boolean equals(Object object)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

isEvent

public boolean isEvent(Class clazz)
Returns true if clazz is imported as an Event class in this package

Parameters:
clazz -
Returns:
true if clazz is imported as an Event class in this package

clear

public void clear()

getFactType

public org.drools.definition.type.FactType getFactType(String typeName)

getClassFieldAccessorStore

public ClassFieldAccessorStore getClassFieldAccessorStore()

setClassFieldAccessorCache

public void setClassFieldAccessorCache(ClassFieldAccessorCache classFieldAccessorCache)

getEntryPointIds

public Set<String> getEntryPointIds()

addEntryPointId

public void addEntryPointId(String id)

getTypeResolver

public TypeResolver getTypeResolver()

setTypeResolver

public void setTypeResolver(TypeResolver typeResolver)


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