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,ArrayContentValidationRule,BundleContentsNamingRule,BundleReferentialIntegrityRule,CollectionInBundleRule,CollectionReferentialIntegrityRule,ContextProductReferenceValidationRule,FileAndDirectoryNamingRule,FileReferenceValidationRule,FindUnreferencedFiles,FindUnreferencedIdentifiers,LabelInFolderRule,LabelValidationRule,LocalIdentifierReferencesRule,MarkSubdirectoriesReferenced,RecordValidationResults,RegisterLabelIdentifiers,RegisterTargetReferences,RegisterTargets,SetReportHeader,SubdirectoryNamingRule,SubDirectoryRule,TableDataContentValidationRule,TableFieldDefinitionRule,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 the
ValidationTest annotation. The tests will
be invoked in they appear within the class.-
Field Summary
Fields inherited from interface org.apache.commons.chain.Command
CONTINUE_PROCESSING, PROCESSING_COMPLETE -
Constructor Summary
Constructors Constructor Description AbstractValidationRule() -
Method Summary
Modifier and Type Method Description booleanexecute(org.apache.commons.chain.Context theContext)Invokes the validation tests in the rule in their declared order.StringgetCaption()Gets a caption describing the rule.protected RuleContextgetChildContext(URL child)Gets a rule context for validating a file or directory inside the current target.protected RuleContextgetContext()Gets the rule context.protected AdditionalTargetgetExtraTarget()protected ProblemListenergetListener()Gets the problem listener for this validation rule.protected StringgetParentTarget()Gets the parent target location for this rule.protected TargetRegistrargetRegistrar()Gets the target registrar for this validation rule.protected URLgetTarget()Gets the target of this rule.abstract booleanisApplicable(String location)Tests whether a rule is applicable to a target location.protected booleanisDebugLogLevel()protected booleanisInfoLogLevel()protected voidreportError(ProblemDefinition defn, URL targetUrl, int lineNumber, int columnNumber)Reports an error to the validation listener.protected voidreportError(ProblemDefinition defn, URL target, int lineNumber, int columnNumber, String message)Reports an error to the validation listener with a custom message.voidsetCaption(String caption)Sets the caption for this chain.protected voidverifyLidPrefix(String lid, String parentLid, String status, URL url)Verifies that the lid contains the parent bundle/collection lid.
-
Constructor Details
-
AbstractValidationRule
public AbstractValidationRule()
-
-
Method Details
-
execute
Invokes the validation tests in the rule in their declared order. Validation tests are denoted by public methods annotated with theValidationTestannotation.- Specified by:
executein interfaceorg.apache.commons.chain.Command- Parameters:
theContext- the context for the rule, which must be aRuleContext- Throws:
Exception
-
getContext
Gets the rule context.- Returns:
- the context
-
getChildContext
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:
URISyntaxExceptionMalformedURLException
-
getTarget
Gets the target of this rule.- Returns:
- the validation target
-
getExtraTarget
-
getParentTarget
Gets the parent target location for this rule.- Returns:
- the parent target location, or null if no parent
-
getListener
Gets the problem listener for this validation rule.- Returns:
- the problem listener
-
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
Tests whether a rule is applicable to a target location.- Specified by:
isApplicablein interfaceValidationRule- Parameters:
location- the target location- Returns:
- true, if the rule is applicable to the target, false otherwise
-
getCaption
Description copied from interface:ValidationRuleGets a caption describing the rule.- Specified by:
getCaptionin interfaceValidationRule- Returns:
- a string caption
-
setCaption
Sets the caption for this chain.- Parameters:
caption- the new caption string
-
verifyLidPrefix
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()
-