Package org.drools.core.definitions.impl
Class KnowledgePackageImpl
- java.lang.Object
-
- org.drools.core.definitions.impl.KnowledgePackageImpl
-
- All Implemented Interfaces:
Externalizable,Serializable,InternalKnowledgePackage,org.kie.api.definition.KiePackage
public class KnowledgePackageImpl extends Object implements InternalKnowledgePackage, Externalizable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,org.kie.api.runtime.rule.AccumulateFunction>accumulateFunctionsprotected Map<String,Object>cloningResourcesprotected DialectRuntimeRegistrydialectRuntimeRegistryprotected Set<String>entryPointsIdsprotected Map<String,FactTemplate>factTemplatesprotected Map<String,Function>functionsprotected Map<String,Type>globalsprotected Map<String,ImportDeclaration>importsprotected StringnameName of the pkg.protected booleanneedStreamModeprotected ResourceTypePackageRegistryresourceTypePackagesprotected Map<String,RuleImpl>rulesSet of all rule-names in thisPackage.protected Set<String>staticImportsprotected Map<String,TypeDeclaration>typeDeclarationsprotected booleanvalidThis is to indicate the the package has no errors during the compilation/building phaseprotected Map<String,WindowDeclaration>windowDeclarations
-
Constructor Summary
Constructors Constructor Description KnowledgePackageImpl()KnowledgePackageImpl(String name)Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAccumulateFunction(String name, org.kie.api.runtime.rule.AccumulateFunction function)voidaddCloningResource(String key, Object resource)voidaddEntryPointId(String id)voidaddFactTemplate(FactTemplate factTemplate)voidaddFunction(Function function)voidaddGlobal(String identifier, Type type)voidaddImport(ImportDeclaration importDecl)voidaddProcess(org.kie.api.definition.process.Process process)Add a rule flow to this package.voidaddRule(RuleImpl rule)Add aRuleto thisPackage.voidaddStaticImport(String functionImport)voidaddTypeDeclaration(TypeDeclaration typeDecl)voidaddWindowDeclaration(WindowDeclaration window)voidcheckValidity()This will throw an exception if the package is not validvoidclear()KnowledgePackageImpldeepCloneIfAlreadyInUse(ClassLoader classLoader)booleanequals(Object object)Map<String,org.kie.api.runtime.rule.AccumulateFunction>getAccumulateFunctions()DialectRuntimeRegistrygetDialectRuntimeRegistry()Set<String>getEntryPointIds()StringgetErrorSummary()This will return the error summary (if any) if the package is invalid.TypeDeclarationgetExactTypeDeclaration(Class<?> clazz)FactTemplategetFactTemplate(String name)org.kie.api.definition.type.FactTypegetFactType(String typeName)Collection<org.kie.api.definition.type.FactType>getFactTypes()FunctiongetFunction(String name)Collection<String>getFunctionNames()Map<String,Function>getFunctions()Map<String,Type>getGlobals()Collection<org.kie.api.definition.rule.Global>getGlobalVariables()protected String[]getImplicitImports()Map<String,ImportDeclaration>getImports()StringgetName()Retrieve the name of thisPackage.ClassLoadergetPackageClassLoader()Collection<org.kie.api.definition.process.Process>getProcesses()Collection<org.kie.api.definition.rule.Query>getQueries()ResourceTypePackageRegistrygetResourceTypePackages()RuleImplgetRule(String name)Retrieve aRuleby name.Map<String,org.kie.api.definition.process.Process>getRuleFlows()Get the rule flows for this package.Collection<org.kie.api.definition.rule.Rule>getRules()List<RuleImpl>getRulesGeneratedFromResource(org.kie.api.io.Resource resource)RuleUnitDescriptionLoadergetRuleUnitDescriptionLoader()Set<String>getStaticImports()TypeDeclarationgetTypeDeclaration(Class<?> clazz)TypeDeclarationgetTypeDeclaration(String type)Map<String,TypeDeclaration>getTypeDeclarations()org.drools.util.TypeResolvergetTypeResolver()Map<String,WindowDeclaration>getWindowDeclarations()inthashCode()booleanisValid()voidmergeTraitRegistry(RuleBase knowledgeBase)booleanneedsStreamMode()voidreadExternal(ObjectInput stream)Handles the read serialization of the Package.booleanremoveFromResourceTypePackageGeneratedFromResource(org.kie.api.io.Resource resource)voidremoveFunction(String functionName)voidremoveFunctionImport(String functionImport)List<Function>removeFunctionsGeneratedFromResource(org.kie.api.io.Resource resource)voidremoveGlobal(String identifier)booleanremoveObjectsGeneratedFromResource(org.kie.api.io.Resource resource)List<org.kie.api.definition.process.Process>removeProcessesGeneratedFromResource(org.kie.api.io.Resource resource)voidremoveRule(RuleImpl rule)voidremoveRuleFlow(String id)Rule flows can be removed by ID.List<RuleImpl>removeRulesGeneratedFromResource(org.kie.api.io.Resource resource)voidremoveTypeDeclaration(String type)protected voidremoveTypeFromStore(TypeDeclaration type)List<TypeDeclaration>removeTypesGeneratedFromResource(org.kie.api.io.Resource resource)voidresetErrors()Once this is called, the package will be marked as invalidvoidsetClassLoader(ClassLoader classLoader)voidsetError(String summary)Once this is called, the package will be marked as invalidvoidsetNeedStreamMode()StringtoString()voidwireTypeDeclarations()voidwriteExternal(ObjectOutput stream)Handles the write serialization of the Package.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.drools.core.definitions.InternalKnowledgePackage
buildFieldAccessors, getFieldExtractor, getFieldType, getReader, getWiringResults, mergeStore, removeClass, setClassFieldAccessorCache, wireObjectType, wireStore
-
-
-
-
Field Detail
-
name
protected String name
Name of the pkg.
-
imports
protected Map<String,ImportDeclaration> imports
-
accumulateFunctions
protected Map<String,org.kie.api.runtime.rule.AccumulateFunction> accumulateFunctions
-
factTemplates
protected Map<String,FactTemplate> factTemplates
-
dialectRuntimeRegistry
protected DialectRuntimeRegistry dialectRuntimeRegistry
-
typeDeclarations
protected Map<String,TypeDeclaration> typeDeclarations
-
windowDeclarations
protected Map<String,WindowDeclaration> windowDeclarations
-
resourceTypePackages
protected ResourceTypePackageRegistry resourceTypePackages
-
valid
protected boolean valid
This is to indicate the the package has no errors during the compilation/building phase
-
needStreamMode
protected boolean needStreamMode
-
-
Constructor Detail
-
KnowledgePackageImpl
public KnowledgePackageImpl()
-
KnowledgePackageImpl
public KnowledgePackageImpl(String name)
Construct.- Parameters:
name- The name of thisPackage.
-
-
Method Detail
-
getResourceTypePackages
public ResourceTypePackageRegistry getResourceTypePackages()
- Specified by:
getResourceTypePackagesin interfaceInternalKnowledgePackage
-
getRules
public Collection<org.kie.api.definition.rule.Rule> getRules()
- Specified by:
getRulesin interfaceorg.kie.api.definition.KiePackage
-
getProcesses
public Collection<org.kie.api.definition.process.Process> getProcesses()
- Specified by:
getProcessesin interfaceorg.kie.api.definition.KiePackage
-
getFactTypes
public Collection<org.kie.api.definition.type.FactType> getFactTypes()
- Specified by:
getFactTypesin interfaceorg.kie.api.definition.KiePackage
-
getQueries
public Collection<org.kie.api.definition.rule.Query> getQueries()
- Specified by:
getQueriesin interfaceorg.kie.api.definition.KiePackage
-
getFunctionNames
public Collection<String> getFunctionNames()
- Specified by:
getFunctionNamesin interfaceorg.kie.api.definition.KiePackage
-
getGlobalVariables
public Collection<org.kie.api.definition.rule.Global> getGlobalVariables()
- Specified by:
getGlobalVariablesin interfaceorg.kie.api.definition.KiePackage
-
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:
writeExternalin interfaceExternalizable- 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:
readExternalin interfaceExternalizable- Parameters:
stream- , the stream to read data from in order to restore the object; should be an instance of DroolsObjectInputStream or InputStream- Throws:
IOExceptionClassNotFoundException
-
getName
public String getName()
Retrieve the name of thisPackage.- Specified by:
getNamein interfaceorg.kie.api.definition.KiePackage- Returns:
- The name of this
Package.
-
getPackageClassLoader
public ClassLoader getPackageClassLoader()
- Specified by:
getPackageClassLoaderin interfaceInternalKnowledgePackage
-
getDialectRuntimeRegistry
public DialectRuntimeRegistry getDialectRuntimeRegistry()
- Specified by:
getDialectRuntimeRegistryin interfaceInternalKnowledgePackage
-
addImport
public void addImport(ImportDeclaration importDecl)
- Specified by:
addImportin interfaceInternalKnowledgePackage
-
getImports
public Map<String,ImportDeclaration> getImports()
- Specified by:
getImportsin interfaceInternalKnowledgePackage
-
addTypeDeclaration
public void addTypeDeclaration(TypeDeclaration typeDecl)
- Specified by:
addTypeDeclarationin interfaceInternalKnowledgePackage
-
removeTypeDeclaration
public void removeTypeDeclaration(String type)
- Specified by:
removeTypeDeclarationin interfaceInternalKnowledgePackage
-
getTypeDeclarations
public Map<String,TypeDeclaration> getTypeDeclarations()
- Specified by:
getTypeDeclarationsin interfaceInternalKnowledgePackage
-
getTypeDeclaration
public TypeDeclaration getTypeDeclaration(Class<?> clazz)
- Specified by:
getTypeDeclarationin interfaceInternalKnowledgePackage
-
getExactTypeDeclaration
public TypeDeclaration getExactTypeDeclaration(Class<?> clazz)
-
getTypeDeclaration
public TypeDeclaration getTypeDeclaration(String type)
- Specified by:
getTypeDeclarationin interfaceInternalKnowledgePackage
-
addStaticImport
public void addStaticImport(String functionImport)
- Specified by:
addStaticImportin interfaceInternalKnowledgePackage
-
addFunction
public void addFunction(Function function)
- Specified by:
addFunctionin interfaceInternalKnowledgePackage
-
getFunctions
public Map<String,Function> getFunctions()
- Specified by:
getFunctionsin interfaceInternalKnowledgePackage
-
addAccumulateFunction
public void addAccumulateFunction(String name, org.kie.api.runtime.rule.AccumulateFunction function)
- Specified by:
addAccumulateFunctionin interfaceInternalKnowledgePackage
-
getAccumulateFunctions
public Map<String,org.kie.api.runtime.rule.AccumulateFunction> getAccumulateFunctions()
- Specified by:
getAccumulateFunctionsin interfaceInternalKnowledgePackage
-
removeFunctionImport
public void removeFunctionImport(String functionImport)
-
getStaticImports
public Set<String> getStaticImports()
- Specified by:
getStaticImportsin interfaceInternalKnowledgePackage
-
addGlobal
public void addGlobal(String identifier, Type type)
- Specified by:
addGlobalin interfaceInternalKnowledgePackage
-
removeGlobal
public void removeGlobal(String identifier)
- Specified by:
removeGlobalin interfaceInternalKnowledgePackage
-
getGlobals
public Map<String,Type> getGlobals()
- Specified by:
getGlobalsin interfaceInternalKnowledgePackage
-
removeFunction
public void removeFunction(String functionName)
- Specified by:
removeFunctionin interfaceInternalKnowledgePackage
-
getFactTemplate
public FactTemplate getFactTemplate(String name)
- Specified by:
getFactTemplatein interfaceInternalKnowledgePackage
-
addFactTemplate
public void addFactTemplate(FactTemplate factTemplate)
- Specified by:
addFactTemplatein interfaceInternalKnowledgePackage
-
addRule
public void addRule(RuleImpl rule)
Add aRuleto thisPackage.- Specified by:
addRulein interfaceInternalKnowledgePackage- Parameters:
rule- The rule to add.- Throws:
DuplicateRuleNameException- If theRuleattempting to be added has the same name as another previously addedRule.InvalidRuleException- If theRuleis not valid.
-
addProcess
public void addProcess(org.kie.api.definition.process.Process process)
Add a rule flow to this package.- Specified by:
addProcessin interfaceInternalKnowledgePackage
-
getRuleFlows
public Map<String,org.kie.api.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.- Specified by:
getRuleFlowsin interfaceInternalKnowledgePackage
-
removeRuleFlow
public void removeRuleFlow(String id)
Rule flows can be removed by ID.- Specified by:
removeRuleFlowin interfaceInternalKnowledgePackage
-
removeRule
public void removeRule(RuleImpl rule)
- Specified by:
removeRulein interfaceInternalKnowledgePackage
-
getRule
public RuleImpl getRule(String name)
Retrieve aRuleby name.- Specified by:
getRulein interfaceInternalKnowledgePackage- Parameters:
name- The name of theRuleto retrieve.- Returns:
- The named
Rule, ornullif not suchRulehas been added to thisPackage.
-
setError
public void setError(String summary)
Once this is called, the package will be marked as invalid- Specified by:
setErrorin interfaceInternalKnowledgePackage
-
resetErrors
public void resetErrors()
Once this is called, the package will be marked as invalid- Specified by:
resetErrorsin interfaceInternalKnowledgePackage
-
isValid
public boolean isValid()
- Specified by:
isValidin interfaceInternalKnowledgePackage- 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- Specified by:
checkValidityin interfaceInternalKnowledgePackage
-
getErrorSummary
public String getErrorSummary()
This will return the error summary (if any) if the package is invalid.
-
clear
public void clear()
- Specified by:
clearin interfaceInternalKnowledgePackage
-
getFactType
public org.kie.api.definition.type.FactType getFactType(String typeName)
- Specified by:
getFactTypein interfaceInternalKnowledgePackage
-
wireTypeDeclarations
public void wireTypeDeclarations()
- Specified by:
wireTypeDeclarationsin interfaceInternalKnowledgePackage
-
getEntryPointIds
public Set<String> getEntryPointIds()
- Specified by:
getEntryPointIdsin interfaceInternalKnowledgePackage
-
addEntryPointId
public void addEntryPointId(String id)
- Specified by:
addEntryPointIdin interfaceInternalKnowledgePackage
-
getTypeResolver
public org.drools.util.TypeResolver getTypeResolver()
- Specified by:
getTypeResolverin interfaceInternalKnowledgePackage
-
setClassLoader
public void setClassLoader(ClassLoader classLoader)
- Specified by:
setClassLoaderin interfaceInternalKnowledgePackage
-
getImplicitImports
protected String[] getImplicitImports()
-
getRuleUnitDescriptionLoader
public RuleUnitDescriptionLoader getRuleUnitDescriptionLoader()
- Specified by:
getRuleUnitDescriptionLoaderin interfaceInternalKnowledgePackage
-
addWindowDeclaration
public void addWindowDeclaration(WindowDeclaration window)
- Specified by:
addWindowDeclarationin interfaceInternalKnowledgePackage
-
getWindowDeclarations
public Map<String,WindowDeclaration> getWindowDeclarations()
- Specified by:
getWindowDeclarationsin interfaceInternalKnowledgePackage
-
removeObjectsGeneratedFromResource
public boolean removeObjectsGeneratedFromResource(org.kie.api.io.Resource resource)
- Specified by:
removeObjectsGeneratedFromResourcein interfaceInternalKnowledgePackage
-
removeFromResourceTypePackageGeneratedFromResource
public boolean removeFromResourceTypePackageGeneratedFromResource(org.kie.api.io.Resource resource)
- Specified by:
removeFromResourceTypePackageGeneratedFromResourcein interfaceInternalKnowledgePackage
-
removeTypesGeneratedFromResource
public List<TypeDeclaration> removeTypesGeneratedFromResource(org.kie.api.io.Resource resource)
- Specified by:
removeTypesGeneratedFromResourcein interfaceInternalKnowledgePackage
-
removeTypeFromStore
protected void removeTypeFromStore(TypeDeclaration type)
-
removeRulesGeneratedFromResource
public List<RuleImpl> removeRulesGeneratedFromResource(org.kie.api.io.Resource resource)
- Specified by:
removeRulesGeneratedFromResourcein interfaceInternalKnowledgePackage
-
getRulesGeneratedFromResource
public List<RuleImpl> getRulesGeneratedFromResource(org.kie.api.io.Resource resource)
- Specified by:
getRulesGeneratedFromResourcein interfaceInternalKnowledgePackage
-
removeFunctionsGeneratedFromResource
public List<Function> removeFunctionsGeneratedFromResource(org.kie.api.io.Resource resource)
- Specified by:
removeFunctionsGeneratedFromResourcein interfaceInternalKnowledgePackage
-
removeProcessesGeneratedFromResource
public List<org.kie.api.definition.process.Process> removeProcessesGeneratedFromResource(org.kie.api.io.Resource resource)
- Specified by:
removeProcessesGeneratedFromResourcein interfaceInternalKnowledgePackage
-
needsStreamMode
public boolean needsStreamMode()
-
setNeedStreamMode
public void setNeedStreamMode()
- Specified by:
setNeedStreamModein interfaceInternalKnowledgePackage
-
deepCloneIfAlreadyInUse
public KnowledgePackageImpl deepCloneIfAlreadyInUse(ClassLoader classLoader)
- Specified by:
deepCloneIfAlreadyInUsein interfaceInternalKnowledgePackage
-
mergeTraitRegistry
public void mergeTraitRegistry(RuleBase knowledgeBase)
- Specified by:
mergeTraitRegistryin interfaceInternalKnowledgePackage
-
addCloningResource
public void addCloningResource(String key, Object resource)
- Specified by:
addCloningResourcein interfaceInternalKnowledgePackage
-
-