Package gov.nasa.pds.tools.validate.rule
Class AbstractValidationRule
- java.lang.Object
-
- gov.nasa.pds.tools.validate.rule.AbstractValidationRule
-
- All Implemented Interfaces:
ValidationRule
,org.apache.commons.chain.Command
- Direct Known Subclasses:
AbstractFindTargets
,BundleContentsNamingRule
,BundleReferentialIntegrityRule
,CollectionInBundleRule
,CollectionReferentialIntegrityRule
,ContextProductReferenceValidationRule
,DataDefinitionAndContentValidationRule
,FileAndDirectoryNamingRule
,FileReferenceValidationRule
,FindUnreferencedFiles
,FindUnreferencedIdentifiers
,LabelInFolderRule
,LabelValidationRule
,LocalIdentifierReferencesRule
,MarkSubdirectoriesReferenced
,RecordValidationResults
,RegisterLabelIdentifiers
,RegisterTargetReferences
,RegisterTargets
,SetReportHeader
,SubdirectoryNamingRule
,SubDirectoryRule
,UTF8ByteStreamRule
,VolumeValidationRule
public abstract class AbstractValidationRule extends Object implements ValidationRule
The base class for validation rules. To implement validation rules, write the validation tests as public void methods and annotate them with theValidationTest
annotation. The tests will be invoked in they appear within the class.
-
-
Constructor Summary
Constructors Constructor Description AbstractValidationRule()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
execute(org.apache.commons.chain.Context theContext)
Invokes the validation tests in the rule in their declared order.String
getCaption()
Gets a caption describing the rule.protected RuleContext
getChildContext(URL child)
Gets a rule context for validating a file or directory inside the current target.protected RuleContext
getContext()
Gets the rule context.protected AdditionalTarget
getExtraTarget()
protected ProblemListener
getListener()
Gets the problem listener for this validation rule.protected String
getParentTarget()
Gets the parent target location for this rule.protected TargetRegistrar
getRegistrar()
Gets the target registrar for this validation rule.protected URL
getTarget()
Gets the target of this rule.abstract boolean
isApplicable(String location)
Tests whether a rule is applicable to a target location.protected boolean
isDebugLogLevel()
protected boolean
isInfoLogLevel()
protected void
reportError(ProblemDefinition defn, URL targetUrl, int lineNumber, int columnNumber)
Reports an error to the validation listener.protected void
reportError(ProblemDefinition defn, URL target, int lineNumber, int columnNumber, String message)
Reports an error to the validation listener with a custom message.void
setCaption(String caption)
Sets the caption for this chain.protected void
verifyLidPrefix(String lid, String parentLid, String status, URL url)
Verifies that the lid contains the parent bundle/collection lid.
-
-
-
Method Detail
-
execute
public boolean execute(org.apache.commons.chain.Context theContext) throws Exception
Invokes the validation tests in the rule in their declared order. Validation tests are denoted by public methods annotated with theValidationTest
annotation.- Specified by:
execute
in interfaceorg.apache.commons.chain.Command
- Parameters:
theContext
- the context for the rule, which must be aRuleContext
- Throws:
Exception
-
getContext
protected RuleContext getContext()
Gets the rule context.- Returns:
- the context
-
getChildContext
protected RuleContext getChildContext(URL child) throws MalformedURLException, URISyntaxException
Gets a rule context for validating a file or directory inside the current target.- Parameters:
child
- the child target- Returns:
- a new rule context for validating the child
- Throws:
URISyntaxException
MalformedURLException
-
getTarget
protected URL getTarget()
Gets the target of this rule.- Returns:
- the validation target
-
getExtraTarget
protected AdditionalTarget getExtraTarget()
-
getParentTarget
protected String getParentTarget()
Gets the parent target location for this rule.- Returns:
- the parent target location, or null if no parent
-
getListener
protected ProblemListener getListener()
Gets the problem listener for this validation rule.- Returns:
- the problem listener
-
getRegistrar
protected TargetRegistrar getRegistrar()
Gets the target registrar for this validation rule.- Returns:
- the target registrar
-
reportError
protected void reportError(ProblemDefinition defn, URL targetUrl, int lineNumber, int columnNumber)
Reports an error to the validation listener.- Parameters:
defn
- the problem definitiontargetFile
- the validation target file containing the problemlineNumber
- the line number, or -1 if no line number appliescolumnNumber
- the column number, or -1 if no column number applies
-
reportError
protected void reportError(ProblemDefinition defn, URL target, int lineNumber, int columnNumber, String message)
Reports an error to the validation listener with a custom message.- Parameters:
defn
- the problem definitiontarget
- the validation target containing the problemlineNumber
- the line number, or -1 if no line number appliescolumnNumber
- the column number, or -1 if no column number appliesmessage
- the error message to report
-
isApplicable
public abstract boolean isApplicable(String location)
Tests whether a rule is applicable to a target location.- Specified by:
isApplicable
in interfaceValidationRule
- Parameters:
location
- the target location- Returns:
- true, if the rule is applicable to the target, false otherwise
-
getCaption
public final String getCaption()
Description copied from interface:ValidationRule
Gets a caption describing the rule.- Specified by:
getCaption
in interfaceValidationRule
- Returns:
- a string caption
-
setCaption
public final void setCaption(String caption)
Sets the caption for this chain.- Parameters:
caption
- the new caption string
-
verifyLidPrefix
protected void verifyLidPrefix(String lid, String parentLid, String status, URL url)
Verifies that the lid contains the parent bundle/collection lid. Applies to Bundle and Collection referential integrity (L5.PRP.VA.36)- Parameters:
lid
-parentLid
-status
-url
-- See Also:
BundleReferentialIntegrityRule
,CollectionReferentialIntegrityRule
-
isInfoLogLevel
protected boolean isInfoLogLevel()
-
isDebugLogLevel
protected boolean isDebugLogLevel()
-
-