|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A folder in which rules are contained. All rules are contained
within a folder much like files are contained within directories.
The root rule folder is needed to begin working with rules.
Use the method getRootFolder
on class RuleMgmtHelper
to get the root rule folder.
From the root rule folder you can add, delete, and retrieve
folders and rules using methods on this interface.
The following example shows how to add a new folder "com" in the root.
IRuleFolder root = RuleMgmtHelper.getRootFolder(); IRuleFolder newFolder = root.createSubFolder("com");The method
createSubFolder
can also be used to create a
sequence of rule folders by passing a path to the method. The path
is relative to the rule folder on which the method is called. An example
path is "com/acme/lifeInsurance". Note that the path
should not start with a slash (/).
The following example creates the folder "com/acme/lifeInsurance".
IRuleFolder lifeFolder = root.createSubFolder("com/acme/lifeInsurance");If you are not sure if the folder exists, an overloaded version of method
getSubFolder
can be used to create a folder or to return the
folder if it already exists. The method takes a folder path as a parameter.
The path is relative to the rule folder on which the method is called.
The following example creates the folder "com/acme/lifeInsurance" if it
does not exist and returns the new folder to the caller or simply returns
the folder if it already existed. Note that the boolean true
indicates that the folder should be created if it does not already exist.
IRuleFolder lifeFolder = root.getSubFolder("com/acme/lifeInsurance", true);The method
getSubFolders
is used to get a collection of the
IRuleFolder
s contained directly within this folder. This method
will not return folders contained within the subfolders. The following
example gets all subfolders and prints their names to standard out.
IRuleFolder lifeFolder = root.getSubFolder("com/acme/lifeInsurance"); Collection folders = lifeFolder.getSubFolders(); Iterator iterator = folders.iterator(); while (iterator.hasNext()) { IRuleFolder folder = (IRuleFolder)iterator.next(); System.out.println(folder.getName()); }A folder can be moved into a different folder. Suppose you wish to change your folder structure such that "com/acme/lifeInsurance" should now be called "com/acme/insurance/lifeInsurance". Essentially, we want to move "lifeInsurance" into "com/acme/insurance". The following example accomplishes this.
IRuleFolder lifeFolder = root.getSubFolder("com/acme/lifeInsurance"); IRuleFolder insuranceFolder = root.getSubFolder("com/acme/insurance"); lifeFolder.move(insuranceFolder);
Rules can be retrieved by reference or by copy. The differences are described in detail in the com.ibm.websphere.brb.mgmt package-level documentation.
Let's look at a few examples. The following code shows how to get all rules from the com/ibm/websphere/brb folder. The method can return references to the persistent rule or local copies of the rule. In this case references are being returned.
IRuleFolder brbFolder = root.getRuleFolder("com/ibm/websphere/brb"); Collection rules = brbFolder.getRules(IRule.TYPE_REFERENCE);The following example creates a new Rule into the com/ibm/websphere/brb folder using a reference to the Rule.
IRuleFolder brbFolder = root.getRuleFolder("com/ibm/websphere/brb"); IRule rule = brbFolder.createRule(IRule.TYPE_REFERENCE, "GreaterThanRule"); rule.setDescription("Performs a greater than operation"); ... set the rest of the attributes ...The following example creates a new rule into the com/ibm/webspherebrb folder using a local copy of the Rule.
IRuleFolder brbFolder = root.getRuleFolder("com/ibm/websphere/brb"); IRuleCopy ruleCopy = (IRuleCopy) brbFolder.createRule(IRule.TYPE_COPY, "GreaterThanRule"); ruleCopy.setDescription("Performs a greater than operation"); ... set the rest of the attributes ... // Tell the local copy of the rule to update the persistent rule ruleCopy.updatePersistentRule();Working with a local copy of a rule introduces the possibility that the copy becomes out of date with the persistent rule. This is particularly troubling when changes are being made to the copy and the persistent rule is to be updated with these changes. The overloaded method
IRuleCopy.updatePersistentRule(IRuleCopy,int)
is intended
to handle this situation.
The createRule
methods which take an IRule
as
a parameter are used to copy or "clone" rules based on already existing rules.
The following example demonstrates this:
Collection coll = brbFolder.findRulesByName("GreaterThanRule", IRule.TYPE_REFERENCE); IRule existingRule = coll.iterator().next(); // assumes only one rule exists with this name IRule newRule = brbFolder.createRule(IRule.TYPE_COPY, existingRule); // The existing rule will expire when the new rule starts Date dateForNewRule = new Date(2001, 1, 1); existingRule.setEndDate(dateForNewRule); newRule.setStartDate(dateForNewRule); // Any other changes to the new rule ... // Update the copy of the rule, this will create the new rule on the server newRule.updatePersistentRule();In this example, the new rule is created as a local copy. When receiving a local copy, the persistent rule is not created on the server until the method
updatePersistentRule
is called.
Note that you could just as well create the rule and receive a reference.
In this case, the rule is created on the server at the time the create is
called.
RuleMgmtHelper
,
IRule
,
IRuleCopy
,
com.ibm.websphere.brb.mgmtMethod Summary | |
IRule |
createRule(int ruleReturnType,
IRule sourceRule)
Creates a rule into this folder initialized with the contents of the given rule. |
IRule |
createRule(int ruleReturnType,
IRule sourceRule,
java.lang.String primaryKey)
Creates a rule into this folder initialized with the contents of the given rule and set to the given primary key. |
IRule |
createRule(int ruleReturnType,
java.lang.String name)
Creates a rule into this folder with the given name. |
IRule |
createRule(int ruleReturnType,
java.lang.String name,
java.lang.String primaryKey)
Creates a rule into this folder with the given name and primary key. |
IRuleFolder |
createSubFolder(java.lang.String path)
Creates a folder or hierarchy of folders as a child of this folder. |
void |
delete()
Deletes this folder and all of its children. |
void |
deleteAllRules()
Delete all rules contained in this folder. |
void |
deleteAllSubFolders()
Delete all subfolders contained in this folder. |
IRule |
findRuleByPrimaryKey(java.lang.String primaryKey,
boolean includeSubFolders,
int returnType)
Find a rule in this folder with the given primary key. |
java.util.Collection |
findRules(boolean includeSubFolders,
int returnType)
Gets all rules contained within this folder. |
java.util.Collection |
findRules(QueryNode queryNode,
boolean includeSubFolders,
int returnType)
Look in this folder for rules that match the given query. |
java.util.Collection |
findRulesByName(java.lang.String ruleName,
boolean includeSubFolders,
int returnType)
Look in this folder for a rule with the given name. |
java.lang.String |
getFullName()
Get the fully qualified name of this folder. |
java.lang.String |
getName()
Returns the name of this folder. |
IRuleFolder |
getParent()
This method returns the parent folder for this folder. |
IRuleFolder |
getRoot()
Returns the root IRuleFolder for this rule namespace. |
IRuleFolder |
getSubFolder(java.lang.String path)
Gets the folder for the given relative path. |
IRuleFolder |
getSubFolder(java.lang.String path,
boolean createFolder)
Gets the folder for the given relative path. |
java.util.Collection |
getSubFolders()
Gets all folders directly contained within this folder. |
void |
move(IRuleFolder toFolder)
Move this folder into a new folder. |
void |
rename(java.lang.String newName)
Renames this folder. |
Method Detail |
public IRule createRule(int ruleReturnType, IRule sourceRule) throws BusinessRuleBeansException, java.rmi.RemoteException
IRuleCopy
is returned.
The persistent rule is not created on the server until method
updatePersistentRule
is called on the
IRuleCopy
. When returning a reference, the persistent rule is created on
the server immediately.ruleReturnType
- indicates whether to return a local copy (IRule.TYPE_COPY) or a reference (IRule.TYPE_REFERENCE)sourceRule
- the rule whose values are copied to get the new ruleBRBeansIllegalArgumentException
- if the ruleReturnType
is not valid or the sourceRule
is nullpublic IRule createRule(int ruleReturnType, IRule sourceRule, java.lang.String primaryKey) throws BusinessRuleBeansException, java.rmi.RemoteException
IRuleCopy
is returned.
The persistent rule is not created on the server until method
updatePersistentRule
is called on the
IRuleCopy
. When returning a reference, the persistent rule is created on
the server immediately.ruleReturnType
- indicates whether to return a local copy (IRule.TYPE_COPY) or a reference (IRule.TYPE_REFERENCE)sourceRule
- the rule whose values are copied to get the new ruleprimaryKey
- the primary key of the new ruleBRBeansIllegalArgumentException
- if the ruleReturnType
is not valid or the sourceRule
or primaryKey
is nullpublic IRule createRule(int ruleReturnType, java.lang.String name) throws BusinessRuleBeansException, java.rmi.RemoteException
IRuleCopy
is returned.
The persistent rule is not created on the server until method
updatePersistentRule
is called on the
IRuleCopy
.
When returning a reference, the persistent rule is created on
the server immediately.ruleReturnType
- indicates whether to return a local copy (IRule.TYPE_COPY) or a reference (IRule.TYPE_REFERENCE)name
- the name of the RuleBRBeansIllegalArgumentException
- if the ruleReturnType
is not validpublic IRule createRule(int ruleReturnType, java.lang.String name, java.lang.String primaryKey) throws BusinessRuleBeansException, java.rmi.RemoteException
IRuleCopy
is returned.
The persistent rule is not created on the server until method
updatePersistentRule
is called on the
IRuleCopy
.
When returning a reference, the persistent rule is created on
the server immediately.ruleReturnType
- indicates whether to return a copy (IRule.TYPE_COPY) or a reference (IRule.TYPE_REFERENCE)name
- the name of the ruleprimaryKey
- the primary key to give this ruleBRBeansIllegalArgumentException
- if the ruleReturnType
is not valid or the primaryKey
is nullpublic IRuleFolder createSubFolder(java.lang.String path) throws BusinessRuleBeansException, java.rmi.RemoteException
path
- the path of the new folderBusinessRUleBeansException
- if the folder or path already existspublic void delete() throws BusinessRuleBeansException, java.rmi.RemoteException
BusinessRUleBeansException
- if this folder is the root folderpublic void deleteAllRules() throws BusinessRuleBeansException, java.rmi.RemoteException
public void deleteAllSubFolders() throws BusinessRuleBeansException, java.rmi.RemoteException
public IRule findRuleByPrimaryKey(java.lang.String primaryKey, boolean includeSubFolders, int returnType) throws BusinessRuleBeansException, java.rmi.RemoteException
getRoot
). Null is returned
if the rule is not found.
Parameter includeSubFolders
determines whether to search
subfolders. Pass true
to search subfolders.
This method can return either a reference to the rule (IRule.TYPE_REFERENCE) or a local copy of the rule (IRule.TYPE_COPY).
primaryKey
- the primaryKey of the ruleincludeSubFolders
- indicates whether to include subfolders as wellreturnType
- indicates whether to return a reference to the persistent rule or a local copy of the rulepublic java.util.Collection findRules(QueryNode queryNode, boolean includeSubFolders, int returnType) throws BusinessRuleBeansException, java.rmi.RemoteException
includeSubFolders
determines whether to search
subfolders. Pass true
to search subfolders.
This method can return references to the rules
(IRule.TYPE_REFERENCE) or local copies of the rule
(IRule.TYPE_COPY). Pass this value to parameter returnType
For example, find all rules named "isEligible".
RuleNameNode nameNode = new RuleNameNode("isEligible", AbstractStringNode.EQUALS); Collection rules = root.findRules(nameNode, true, IRule.TYPE_REFERENCE);The following finds rules named "isEligible" with a classification of "SeniorCitizen".
RuleNameNode nameNode = new RuleNameNode("isEligible", AbstractStringNode.EQUALS); ClassificationNode cNode = new ClassificationNode("SeniorCitizen", AbstractStringNode.EQUALS); AndNode andNode = new AndNode(nameNode, cNode); Collection rules = root.findRules(andNode, true, IRule.TYPE_REFERENCE);
queryNode
- represents the type of query to performincludeSubFolders
- indicates whether to include subfolders as wellreturnType
- indicates whether to return a reference to the persistent rule or a local copy of the rulepublic java.util.Collection findRules(boolean includeSubFolders, int returnType) throws BusinessRuleBeansException, java.rmi.RemoteException
includeSubFolders
determines whether to search
subfolders. Pass true
to search subfolders.
This method can return either references to the rules (IRule.TYPE_REFERENCE) or local copies of the rules (IRule.TYPE_COPY).
includeSubFolders
- indicates whether to include subfolders as wellreturnType
- indicates whether to return references to the persistent rules or local copies of the rulespublic java.util.Collection findRulesByName(java.lang.String ruleName, boolean includeSubFolders, int returnType) throws BusinessRuleBeansException, java.rmi.RemoteException
Collection
because there
could be multiple rules with this same name. An empty collection
is returned if no rule is found with this name. The parameter
ruleName
can specify a relative path followed
by the name of the rule or may simply specify a name of the
rule. If a relative path is specified, then the includeSubFolders
parameter must be false. This is because a particular subfolder is
already being specified by the relative path. If parameter
includeSubFolders
is not false and a relative path is
specified, then a BRBeansIllegalArgumentException is thrown.
This method can return references to the rules (IRule.TYPE_REFERENCE)
or local copies of the rule (IRule.TYPE_COPY). Pass this value to
parameter returnType
For example, the following will return the rule named
"isEligibleForDiscount" in folder lifeFolder
.
IRuleFolder lifeFolder = root.getSubFolder("com/acme/lifeInsurance"); Collection rules = lifeFolder.findRules("isEligibleForDiscount", IRule.TYPE_REFERENCE);The following finds a rule specifying a fully qualified name:
Collection rules = root.findRules("com/acme/lifeInsurance/isEligibleForDiscount", IRule.TYPE_REFERENCE);
ruleName
- the name of the rule for which to searchincludeSubFolders
- indicates whether to include subfolders as well. true cannot
be specified if a relative path is specified for the ruleName
parameter.returnType
- indicates whether to return a reference to the persistent rule or a local copy of the rulepublic java.lang.String getFullName() throws BusinessRuleBeansException, java.rmi.RemoteException
public java.lang.String getName() throws BusinessRuleBeansException, java.rmi.RemoteException
getFullName
to get
a fully qualified name.public IRuleFolder getParent() throws BusinessRuleBeansException, java.rmi.RemoteException
public IRuleFolder getRoot() throws BusinessRuleBeansException, java.rmi.RemoteException
public IRuleFolder getSubFolder(java.lang.String path) throws BusinessRuleBeansException, java.rmi.RemoteException
path
- the relative path of the folder to retrieveBRBeansIllegalArgumentException
- if the path
is invalid. A valid path
name must not be null or the empty string and must not start with a '/' character.public IRuleFolder getSubFolder(java.lang.String path, boolean createFolder) throws BusinessRuleBeansException, java.rmi.RemoteException
createFolder
determines whether to create the
folders if they do not exist. Passing true
will
cause the folders to be created. If false
is
passed and the folder does not exist, null is returned.path
- the relative path of the folder to retrievecreateFolder
- indicates whether to create the folder if it doesn't existBRBeansIllegalArgumentException
- if the path
is invalid. A valid path
name must not be null or the empty string and must not start with a '/' character.public java.util.Collection getSubFolders() throws BusinessRuleBeansException, java.rmi.RemoteException
public void move(IRuleFolder toFolder) throws BusinessRuleBeansException, java.rmi.RemoteException
toFolder
- the folder into which to move this folderpublic void rename(java.lang.String newName) throws BusinessRuleBeansException, java.rmi.RemoteException
newName
- the new name of this folder
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |