org.eclipse.actf.validation.rules
Class AbstractRule

java.lang.Object
  extended by org.eclipse.actf.validation.rules.AbstractRule
All Implemented Interfaces:
IRule
Direct Known Subclasses:
AndRule, EqRule, FocusRule, InstanceofRule, MaxRule, MinRule, NeqRule, OrRule, RangeRule, ReflexiveCriterion, ReflexiveRule, RegexpRule, ScriptRule

public abstract class AbstractRule
extends Object
implements IRule

base implementation of a validation rule in ACTF. Clients should extend this class rather than implementing IRule.

Author:
Mike Squillace

Field Summary
protected static Map SEVERITY_MAP
           
 
Constructor Summary
AbstractRule()
           
 
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)
          insures that either the target is not null or that, if the target is null, null targets can be ignored
protected  String findComponentCategory()
           
protected  String findMessage()
           
protected  String findRuleId()
           
protected  String getAliasValue(String name)
           
 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
protected  IRuleFactory getRuleFactory()
           
 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.
protected  String getTextTrim(Element elem)
           
 boolean isEnabled()
          returns the enable attribute for this rule
protected  boolean isIgnoringNullTarget(Object target)
           
protected  void processActfAttributes(Element elem)
           
protected  void report(IValidationContext context, String msg)
           
 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.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.actf.validation.rules.IRule
initialize
 

Field Detail

SEVERITY_MAP

protected static final Map SEVERITY_MAP
Constructor Detail

AbstractRule

public AbstractRule()
Method Detail

getName

public 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.

Specified by:
getName in interface IRule
Returns:
name of rule

setName

public 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.

Specified by:
setName in interface IRule

getId

public String getId()
get the unique id for this rule

Specified by:
getId in interface IRule
Returns:

setId

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

Specified by:
setId in interface IRule

findRuleId

protected String findRuleId()

getSeverity

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

Specified by:
getSeverity in interface IRule
Returns:
severity level

setSeverity

public 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.

Specified by:
setSeverity in interface IRule
See Also:
IReporter

findMessage

protected String findMessage()

getMessage

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

Specified by:
getMessage in interface IRule
Returns:
message to be received when rule is violated

setMessage

public 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.

Specified by:
setMessage in interface IRule
Parameters:
msg - - message to be received upon a violation of this rule
See Also:
IRule.setLongDescription(String)

getIgnoreIfNull

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

Specified by:
getIgnoreIfNull in interface IRule
Returns:
whether apply(Object) returns true or false when this rule is evaluated with a null object

setIgnoreIfNull

public 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.

Specified by:
setIgnoreIfNull in interface IRule
Parameters:
ignoreifnull - - true | false
See Also:
#apply(Object)

isIgnoringNullTarget

protected boolean isIgnoringNullTarget(Object target)

isEnabled

public boolean isEnabled()
returns the enable attribute for this rule

Specified by:
isEnabled in interface IRule
Returns:
whether this rule is enabled (true | false )

setEnabled

public 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.

Specified by:
setEnabled in interface IRule
Parameters:
enable - - true | false

getIterator

public 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.

Specified by:
getIterator in interface IRule
Parameters:
collection - with which to initialize iterator
Returns:
iterator used for collections or null if no iterator is required

setIteratorName

public 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.

Specified by:
setIteratorName in interface IRule
Parameters:
clsName - - class name of iterator to be used
See Also:
#getIterator(Object)Object), RuleConstants.ITERATOR

getLongDescription

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

Specified by:
getLongDescription in interface IRule
Returns:
long description or message received upon a violation of this rule

setLongDescription

public 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.

Specified by:
setLongDescription in interface IRule
Parameters:
desc - - long description to be received upon a violation of this rule
See Also:
IRule.setMessage(String)

getRepairHint

public String getRepairHint()
returns the repair hint for this rule

Specified by:
getRepairHint in interface IRule
Returns:
repair hint

setRepairHint

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

Specified by:
setRepairHint in interface IRule

processActfAttributes

protected void processActfAttributes(Element elem)

apply

public boolean apply(IValidationContext context,
                     Object target)
              throws Exception
insures that either the target is not null or that, if the target is null, null targets can be ignored

Specified by:
apply in interface IRule
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:
IRule.initialize(Object), IValidationContext, ValidationContextConstants

getRuleParts

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

Specified by:
getRuleParts in interface IRule
Returns:
list of rule parts

setRuleParts

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

Specified by:
setRuleParts in interface IRule
Parameters:
ruleParts - list of rule parts

addRulePart

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

Specified by:
addRulePart in interface IRule
Parameters:
rule - validation rule

findComponentCategory

protected String findComponentCategory()

getComponentCategory

public 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.

Specified by:
getComponentCategory in interface IRule
Returns:
category identifier of component

setComponentCategory

public 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.

Specified by:
setComponentCategory in interface IRule

getParent

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

Specified by:
getParent in interface IRule
Returns:
instance of the parent rule

setParent

public void setParent(IRule parent)
Description copied from interface: IRule
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.

Specified by:
setParent in interface IRule
Parameters:
parent - rule

getRuleSet

public IRuleSet getRuleSet()
return the IRuleSet containing this IRule.

Specified by:
getRuleSet in interface IRule
Returns:
instance of the containing IRuleSet

setRuleSet

public void setRuleSet(IRuleSet iRuleSet)
Description copied from interface: IRule
Set the containing IRuleSet for this rule. A IRule is contained by only one IRuleSet.

Specified by:
setRuleSet in interface IRule
Parameters:
iRuleSet - parent rule

toString

public String toString()
Overrides:
toString in class Object

report

protected void report(IValidationContext context,
                      String msg)

getAliasValue

protected String getAliasValue(String name)

getRuleFactory

protected IRuleFactory getRuleFactory()

getTextTrim

protected String getTextTrim(Element elem)

getAttribute

public String getAttribute(String name)
Description copied from interface: IRule
retreaves the attribute with the given name for this rule

Specified by:
getAttribute in interface IRule
Parameters:
name - name of attribute
Returns:
attribute with given name or null

setAttribute

public void setAttribute(String name,
                         String value)
Description copied from interface: IRule
set an arbitrary attribute for this rule

Specified by:
setAttribute in interface IRule
Parameters:
name - name of attribute
value - value of attribute