org.eclipse.actf.validation.rules
Class AbstractRule

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

public abstract class AbstractRule
extends AbstractCriterion
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
           
 
Fields inherited from class org.eclipse.actf.validation.rules.AbstractCriterion
attributes, parent, parts, ruleSet
 
Constructor Summary
AbstractRule()
           
 
Method Summary
 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 getComponentCategory()
          return the unique component category identifier in effect at the time this rule is evaluated.
protected  ICriterionFactory getCriterionFactory()
           
 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.
 String getRepairHint()
          returns the repair hint for this rule
 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 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 setRepairHint(String hint)
          set the repair hint for this rule.
 void setSeverity(int severity)
          set the severity level for a violation of this rule.
 String toString()
           
 
Methods inherited from class org.eclipse.actf.validation.rules.AbstractCriterion
addPart, equals, getAttribute, getParent, getParts, getRuleSet, hashCode, setAttribute, setParent, setParts, setRuleSet
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.actf.validation.rules.ICriterion
addPart, getAttribute, getParent, getParts, getRuleSet, initialize, setAttribute, setParent, setParts, setRuleSet
 

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

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 severity)
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

getId

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

Specified by:
getId in interface IRule
Returns:
String

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()

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

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:
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 ICriterion
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:
ICriterion.initialize(Object), IValidationContext, ValidationContextConstants

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

toString

public String toString()
Overrides:
toString in class Object

report

protected void report(IValidationContext context,
                      String msg)

getAliasValue

protected String getAliasValue(String name)

getCriterionFactory

protected ICriterionFactory getCriterionFactory()

getTextTrim

protected String getTextTrim(Element elem)