站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss RULES 4.0.0.11754MR2 API 英文版文档

RulesRepository (Drools 4.0.0.11754MR2 API) - JBoss RULES 4.0.0.11754MR2 API 英文版文档


org.drools.repository
Class RulesRepository

java.lang.Object
  extended by org.drools.repository.RulesRepository

public class RulesRepository
extends Object

RulesRepository is the class that defines the bahavior for the JBoss Rules (drools) rule repository based upon the JCR specification (JSR-170).

An instance of this class is capable of storing rules used by the JBoss Rule engine. It also provides a versioning capability for rules. Rules can be imported from specified files. The RulesRepository is also capable of storing DSL content. Rules can be explicitly tied to a particular DSL node within the repository, and this reference can either follow the head version, or a specific version of the DSL node.

The RulesRepository also is capable of storing RulePackages, which aggregate one or more Rules into a set. RulePackages hold references to the nodes storing the content of the rules in the set within the repository. Each entry in a rulepackage can either refer to the head version of the given rule node, or a specific version.

Rules can be tagged. Tags are stored in a separate area of the repository, and can be added on demand. Rules can have 0 or more tags. Tags are intended to help provide a means for searching for specific types of rules quickly, even when they aren't all part of the same rulepackage.

Rules can be associated with 0 or 1 states. States are created in a seperate area of the repository. States are intended to help track the progress of a rule as it traverses its life- cycle. (e.g. draft, approved, deprecated, etc.)

The RulesRepository provides versioning of rules, rule packages, and DSLs. This versioning works in a strictly linear fashion, with one version having at most 1 predecessor version (or none, if it is the first version), and at most 1 successor version (or none, if it is the most recently checked-in version). The JCR specification supports a more complicated versioning system, and if there is sufficient demand, we can modify our versioning scheme to be better aligned with JCR's versioning abilities.

Author:
Ben Truitt, Fernando Meyer

Field Summary
static String DROOLS_URI
           
static String PACKAGE_SNAPSHOT_AREA
          The name of the rulepackage area of the repository
static String RULE_PACKAGE_AREA
          The name of the rulepackage area of the repository
static String RULES_REPOSITORY_NAME
          The name of the rules repository within the JCR repository
static String STATE_AREA
          The name of the state area of the repository
static String TAG_AREA
          The name of the tag area of the repository
 
Constructor Summary
RulesRepository(javax.jcr.Session session)
          This requires a JCR session be setup, and the repository be configured.
 
Method Summary
protected static javax.jcr.Node addNodeIfNew(javax.jcr.Node parent, String nodeName, String type)
          Will add a node named 'nodeName' of type 'type' to 'parent' if such a node does not already exist.
 boolean containsPackage(String name)
          This returns true if the repository contains the specified package name.
 String copyAsset(String uuidSource, String destinationPackage, String destinationName)
          This will copy an assets content to the new location.
 void copyPackageSnapshot(String packageName, String snapshotName, String newName)
          Copies a snapshot to the new location/label.
 PackageItem createPackage(String name, String description)
          Adds a package to the repository.
 void createPackageSnapshot(String packageName, String snapshotName)
          This will copy the package to the snapshot area.
 StateItem createState(String name)
          Create a status node of the given name.
 byte[] dumpRepositoryXml()
           
 byte[] exportRulesRepository()
          TODO: comment
 List findAssetsByCategory(String categoryTag)
          TODO: Comment
 List findAssetsByCategory(String categoryTag, boolean seekArchivedAsset)
          This will retrieve a list of RuleItem objects - that are allocated to the provided category.
 AssetItemIterator findAssetsByName(String name)
           
 AssetItemIterator findAssetsByName(String name, boolean seekArchived)
          This will search assets, looking for matches against the name.
 javax.jcr.Session getSession()
           
 StateItem getState(String name)
          Gets a StateItem for the specified state name.
 void importRulesRepository(byte[] byteArray)
           
 Iterator listPackages()
           
 String[] listPackageSnapshots(String packageName)
          Return a list of the snapshots available for the given package name.
 StateItem[] listStates()
           
 AssetItem loadAssetByUUID(String uuid)
          Loads a rule by its UUID (generally the fastest way to load something).
 CategoryItem loadCategory(String tagName)
          This will return a category for the given category path.
 PackageItem loadDefaultPackage()
          This will return or create the default package for rules that have no home yet.
 PackageItem loadPackage(String name)
          Loads a RulePackage for the specified package name.
 PackageItem loadPackageByUUID(String uuid)
          Similar to above.
 PackageItem loadPackageSnapshot(String packageName, String snapshotName)
           
 void logout()
          Explicitly logout of the underlying JCR repository.
 void moveRuleItemPackage(String newPackage, String uuid, String explanation)
          This moves a rule asset from one package to another, preserving history etc etc.
 void removePackageSnapshot(String packageName, String snapshotName)
          This will remove the specified snapshot.
 void restoreHistoricalAsset(AssetItem versionToRestore, AssetItem headVersion, String comment)
          This will restore the historical version, save, and check it in as a new version with the given comment.
 void save()
          Save any pending changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DROOLS_URI

public static final String DROOLS_URI
See Also:
Constant Field Values

RULE_PACKAGE_AREA

public static final String RULE_PACKAGE_AREA
The name of the rulepackage area of the repository

See Also:
Constant Field Values

PACKAGE_SNAPSHOT_AREA

public static final String PACKAGE_SNAPSHOT_AREA
The name of the rulepackage area of the repository

See Also:
Constant Field Values

TAG_AREA

public static final String TAG_AREA
The name of the tag area of the repository

See Also:
Constant Field Values

STATE_AREA

public static final String STATE_AREA
The name of the state area of the repository

See Also:
Constant Field Values

RULES_REPOSITORY_NAME

public static final String RULES_REPOSITORY_NAME
The name of the rules repository within the JCR repository

See Also:
Constant Field Values
Constructor Detail

RulesRepository

public RulesRepository(javax.jcr.Session session)
This requires a JCR session be setup, and the repository be configured.

Method Detail

addNodeIfNew

protected static javax.jcr.Node addNodeIfNew(javax.jcr.Node parent,
                                             String nodeName,
                                             String type)
                                      throws RulesRepositoryException
Will add a node named 'nodeName' of type 'type' to 'parent' if such a node does not already exist.

Parameters:
parent - the parent node to add the new node to
nodeName - the name of the new node
type - the type of the new node
Returns:
a reference to the Node object that is created by the addition, or, if the node already existed, a reference to the pre-existant node.
Throws:
RulesRepositoryException

logout

public void logout()
Explicitly logout of the underlying JCR repository.


copyAsset

public String copyAsset(String uuidSource,
                        String destinationPackage,
                        String destinationName)
This will copy an assets content to the new location.


loadPackage

public PackageItem loadPackage(String name)
                        throws RulesRepositoryException
Loads a RulePackage for the specified package name. Will throw an exception if the specified rule package does not exist.

Parameters:
name - the name of the package to load
Returns:
a RulePackageItem object
Throws:
RulesRepositoryException

containsPackage

public boolean containsPackage(String name)
This returns true if the repository contains the specified package name.


loadPackageSnapshot

public PackageItem loadPackageSnapshot(String packageName,
                                       String snapshotName)

createPackageSnapshot

public void createPackageSnapshot(String packageName,
                                  String snapshotName)
This will copy the package to the snapshot area. Creating a copy for deployment, etc.


removePackageSnapshot

public void removePackageSnapshot(String packageName,
                                  String snapshotName)
This will remove the specified snapshot.


copyPackageSnapshot

public void copyPackageSnapshot(String packageName,
                                String snapshotName,
                                String newName)
Copies a snapshot to the new location/label.

Parameters:
packageName - The name of the package.
snapshotName - The label of the source snapshot
newName - The new label. The old one is left intact.

loadDefaultPackage

public PackageItem loadDefaultPackage()
                               throws RulesRepositoryException
This will return or create the default package for rules that have no home yet.

Throws:
RulesRepositoryException

loadPackageByUUID

public PackageItem loadPackageByUUID(String uuid)
                              throws RulesRepositoryException
Similar to above. Loads a RulePackage for the specified uuid.

Parameters:
uuid - the uuid of the package to load
Returns:
a RulePackageItem object
Throws:
RulesRepositoryException

restoreHistoricalAsset

public void restoreHistoricalAsset(AssetItem versionToRestore,
                                   AssetItem headVersion,
                                   String comment)
This will restore the historical version, save, and check it in as a new version with the given comment.

Parameters:
versionToRestore -
headVersion -
comment -

loadAssetByUUID

public AssetItem loadAssetByUUID(String uuid)
Loads a rule by its UUID (generally the fastest way to load something).


createPackage

public PackageItem createPackage(String name,
                                 String description)
                          throws RulesRepositoryException
Adds a package to the repository.

Parameters:
name - what to name the node added
description - what description to use for the node
Returns:
a PackageItem, encapsulating the created node
Throws:
RulesRepositoryException

getState

public StateItem getState(String name)
                   throws RulesRepositoryException
Gets a StateItem for the specified state name. If a node for the specified state does not yet exist, one is first created.

Parameters:
name - the name of the state to get
Returns:
a StateItem object encapsulating the retreived node
Throws:
RulesRepositoryException

createState

public StateItem createState(String name)
Create a status node of the given name.


loadCategory

public CategoryItem loadCategory(String tagName)
                          throws RulesRepositoryException
This will return a category for the given category path.

Parameters:
tagName - the name of the tag to get. If the tag to get is within a heirarchy of tag nodes, specify the full path to the tag node of interest (e.g. if you want to get back 'child-tag', use "parent-tag/child-tag")
Returns:
a TagItem object encapsulating the node for the tag in the repository
Throws:
RulesRepositoryException

findAssetsByCategory

public List findAssetsByCategory(String categoryTag,
                                 boolean seekArchivedAsset)
                          throws RulesRepositoryException
This will retrieve a list of RuleItem objects - that are allocated to the provided category. Only the latest versions of each RuleItem will be returned (you will have to delve into the rules deepest darkest history yourself... mahahahaha).

Throws:
RulesRepositoryException

findAssetsByCategory

public List findAssetsByCategory(String categoryTag)
                          throws RulesRepositoryException
TODO: Comment

Throws:
RulesRepositoryException

exportRulesRepository

public byte[] exportRulesRepository()
                             throws IOException,
                                    javax.jcr.PathNotFoundException,
                                    javax.jcr.RepositoryException
TODO: comment

Returns:
Throws:
IOException
javax.jcr.PathNotFoundException
javax.jcr.RepositoryException

dumpRepositoryXml

public byte[] dumpRepositoryXml()
                         throws javax.jcr.PathNotFoundException,
                                IOException,
                                javax.jcr.RepositoryException
Throws:
javax.jcr.PathNotFoundException
IOException
javax.jcr.RepositoryException

importRulesRepository

public void importRulesRepository(byte[] byteArray)
Parameters:
byteArray -

listPackages

public Iterator listPackages()
Returns:
an Iterator which will provide RulePackageItem's. This will show ALL the packages, only returning latest versions, by default.

getSession

public javax.jcr.Session getSession()
Returns:
The JCR session that this repository is using.

save

public void save()
Save any pending changes.


moveRuleItemPackage

public void moveRuleItemPackage(String newPackage,
                                String uuid,
                                String explanation)
This moves a rule asset from one package to another, preserving history etc etc.

Parameters:
newPackage - The destination package.
uuid - The UUID of the rule
explanation - The reason (which will be added as the checkin message).

listPackageSnapshots

public String[] listPackageSnapshots(String packageName)
Return a list of the snapshots available for the given package name.


findAssetsByName

public AssetItemIterator findAssetsByName(String name,
                                          boolean seekArchived)
This will search assets, looking for matches against the name.


findAssetsByName

public AssetItemIterator findAssetsByName(String name)

listStates

public StateItem[] listStates()
Returns:
A list of statii in the system.


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