org.eclipse.actf.validation.rules
Interface IRule

All Known Implementing Classes:
AbstractRule, AndRule, EqRule, FocusRule, InstanceofRule, MaxRule, MinRule, NeqRule, OrRule, RangeRule, ReflexiveCriterion, ReflexiveRule, RegexpRule, ScriptRule

public interface IRule

an interface to be implemented to add rules to the validation engine.

Author:
Mike Squillace

Method Summary
 void addRulePart(IRule rule)
          adds a rule to the list of rule parts or nested rules that are executed when this rule is evaluated.
 boolean apply(IValidationContext context, Object target)
          apply this rule to the given target using the given context.
 String getAttribute(String name)
          retreaves the attribute with the given name for this rule
 String getComponentCategory()
          return the unique component category identifier in effect at the time this rule is evaluated.
 String getId()
          get the unique id for this rule
 boolean getIgnoreIfNull()
          returns the actf:ignoreifnull attribute for this rule
 Iterator getIterator(Object collection)
          returns the iterator used for this rule should the rule involve any sort of collection or array.
 String getLongDescription()
          returns the long description received upon a violation of this rule
 String getMessage()
          returns the message resulting from violating this rule
 String getName()
          return the name of the rule.
 IRule getParent()
          return the parent rule of this rule.
 String getRepairHint()
          returns the repair hint for this rule
 List getRuleParts()
          returns the rule parts or nested rules for this rule
 IRuleSet getRuleSet()
          return the IRuleSet containing this IRule.
 int getSeverity()
          return the severity level for a violation of this rule.
 void initialize(Object content)
          initialize this rule with any content that might be necessary for its application to a target during the invocation of the apply method.
 boolean isEnabled()
          returns the enable attribute for this rule
 void setAttribute(String name, String value)
          set an arbitrary attribute for this rule
 void setComponentCategory(String categoryId)
          set the component category identifier for this rule.
 void setEnabled(boolean enable)
          set the enable attribute for this rule.
 void setId(String id)
          set the id for this rule.
 void setIgnoreIfNull(boolean ignoreIfNull)
          set the actf:ignoreifnull attribute for this rule.
 void setIteratorName(String clsName)
          set the class name of the iterator to be used for iterating through any sort of collection.
 void setLongDescription(String desc)
          set the long description or message to be received upon a violation of this rule.
 void setMessage(String msg)
          set the message to be received upon a violation of this rule.
 void setName(String name)
          set the name for this rule.
 void setParent(IRule parent)
          set the parent rule of this rule.
 void setRepairHint(String hint)
          set the repair hint for this rule.
 void setRuleParts(List ruleParts)
          set the rule parts or nested rules for this rule.
 void setRuleSet(IRuleSet iRuleSet)
          Set the containing IRuleSet for this rule.
 void setSeverity(int level)
          set the severity level for a violation of this rule.
 

Method Detail

getName

String getName()
return the name of the rule. This might also serve as a short description of the purpose of the rule or what it is testing.

Returns:
name of rule

setName

void setName(String name)
set the name for this rule. The name need not be unique but should be a short description of the rule or of what it is testing.

Parameters:
name -

getId

String getId()
get the unique id for this rule

Returns:

setId

void setId(String id)
set the id for this rule. The id for a rule should be unique within a given rulebase.

Parameters:
id -

isEnabled

boolean isEnabled()
returns the enable attribute for this rule

Returns:
whether this rule is enabled (true | false )

setEnabled

void setEnabled(boolean enable)
set the enable attribute for this rule. If enable is true then this rule is evaluated. If enable is false then this rule is skipped.

Parameters:
enable - - true | false

getMessage

String getMessage()
returns the message resulting from violating this rule

Returns:
message to be received when rule is violated

setMessage

void setMessage(String msg)
set the message to be received upon a violation of this rule. This message is typically short and can be supplemented by the long description.

Parameters:
msg - - message to be received upon a violation of this rule
See Also:
setLongDescription(String)

getLongDescription

String getLongDescription()
returns the long description received upon a violation of this rule

Returns:
long description or message received upon a violation of this rule

setLongDescription

void setLongDescription(String desc)
set the long description or message to be received upon a violation of this rule. The long description can supplement the shorter message for this rule.

Parameters:
desc - - long description to be received upon a violation of this rule
See Also:
setMessage(String)

getRepairHint

String getRepairHint()
returns the repair hint for this rule

Returns:
repair hint

setRepairHint

void setRepairHint(String hint)
set the repair hint for this rule. The repair hint provides information about how to fix violations of this rule.

Parameters:
hint -

getSeverity

int getSeverity()
return the severity level for a violation of this rule.

Returns:
severity level

setSeverity

void setSeverity(int level)
set the severity level for a violation of this rule. The level will typically be one of the levels specified in org.eclipse.actf.util.logging.Reporter.

Parameters:
level -
See Also:
IReporter

initialize

void initialize(Object content)
                throws Exception
initialize this rule with any content that might be necessary for its application to a target during the invocation of the apply method.

The specified content may take any form. It may be an XML element, a .properties file, a string, etc. This method may be invoked anytime prior to calling apply.

Parameters:
content - - initialization content for the rule
Throws:
Exception
See Also:
apply(IValidationContext, Object)

apply

boolean apply(IValidationContext context,
              Object target)
              throws Exception
apply this rule to the given target using the given context. The returned value indicates whether or not a violation of some kind has taken place.

Note that the context object can be used to retreave a great deal of information about the current validation process. In particular, it can be used to update the validation report being generated with the violations that result from an application of this rule to the given target.

Parameters:
context - context under which rule is being evaluated (supplied by engine)
target - object to which rule is to be applied
Returns:
whether or not the target violates the rule
Throws:
Exception
See Also:
initialize(Object), IValidationContext, ValidationContextConstants

getRuleParts

List getRuleParts()
returns the rule parts or nested rules for this rule

Returns:
list of rule parts

setRuleParts

void setRuleParts(List ruleParts)
set the rule parts or nested rules for this rule.

Parameters:
ruleParts - list of rule parts

addRulePart

void addRulePart(IRule rule)
adds a rule to the list of rule parts or nested rules that are executed when this rule is evaluated.

Parameters:
rule - validation rule

getParent

IRule getParent()
return the parent rule of this rule.

Returns:
instance of the parent rule

setParent

void setParent(IRule parent)
set the parent rule of this rule. Rules can be nested. There are some fields that are set only on the parent rule for all nested rule parts.

Parameters:
parent - rule

getRuleSet

IRuleSet getRuleSet()
return the IRuleSet containing this IRule.

Returns:
instance of the containing IRuleSet

setRuleSet

void setRuleSet(IRuleSet iRuleSet)
Set the containing IRuleSet for this rule. A IRule is contained by only one IRuleSet.

Parameters:
iRuleSet - parent rule

getComponentCategory

String getComponentCategory()
return the unique component category identifier in effect at the time this rule is evaluated. The category identifier is used in validation reports.

Returns:
category identifier of component

getIgnoreIfNull

boolean getIgnoreIfNull()
returns the actf:ignoreifnull attribute for this rule

Returns:
whether apply(Object) returns true or false when this rule is evaluated with a null object

getIterator

Iterator getIterator(Object collection)
returns the iterator used for this rule should the rule involve any sort of collection or array. Note that a ArrayIterator is provided for arrays and a DomNodeIterator is provided for iterating through the nodes of a W3C DOM level 2 NodeList.

Other iterators may be specified using the actf:iterator attribute.

Parameters:
collection - with which to initialize iterator
Returns:
iterator used for collections or null if no iterator is required

setComponentCategory

void setComponentCategory(String categoryId)
set the component category identifier for this rule. The parent rule, the first child of a first child of a element, will typically contain this value since all rules are evaluated for this component. This value is used when creating a report record and provides a unique identifier for this particular component.

Parameters:
categoryId -

setIgnoreIfNull

void setIgnoreIfNull(boolean ignoreIfNull)
set the actf:ignoreifnull attribute for this rule. If ignoreifnull is true then this rule is ignored if the target object to evaluate in the apply(Object) method is null. If ignoreifnull is false then apply(Object) will fail if the target object is null.

Parameters:
ignoreIfNull - - true | false
See Also:
#apply(Object)

setIteratorName

void setIteratorName(String clsName)
set the class name of the iterator to be used for iterating through any sort of collection. This attribute is set using the RuleConstants.ITERATOR attribute.

Parameters:
clsName - - class name of iterator to be used
See Also:
#getIterator(Object)Object), RuleConstants.ITERATOR

getAttribute

String getAttribute(String name)
retreaves the attribute with the given name for this rule

Parameters:
name - name of attribute
Returns:
attribute with given name or null

setAttribute

void setAttribute(String name,
                  String value)
set an arbitrary attribute for this rule

Parameters:
name - name of attribute
value - value of attribute