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.
  • Constructor Details

    • AbstractValidationRule

      public AbstractValidationRule()
  • Method Details

    • 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 the ValidationTest annotation.
      Specified by:
      execute in interface org.apache.commons.chain.Command
      Parameters:
      theContext - the context for the rule, which must be a RuleContext
      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 definition
      targetFile - the validation target file containing the problem
      lineNumber - the line number, or -1 if no line number applies
      columnNumber - 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 definition
      target - the validation target containing the problem
      lineNumber - the line number, or -1 if no line number applies
      columnNumber - the column number, or -1 if no column number applies
      message - 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 interface ValidationRule
      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 interface ValidationRule
      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()