Class EdiValidator

  • All Implemented Interfaces:
    IStackChangeListener, IParsingEventListener

    public class EdiValidator
    extends java.lang.Object
    implements IParsingEventListener, IStackChangeListener
    Responsible for validating the EDI data once it has been converted to an internal object form.
    1. Ensure that the data values are within the min/max range
    2. Ensure that the data value matches the expected data type
    3. Ensure that the segment repetition range is met
    Missing mandatory segment are handling by the parsing process and result in an exception.
    • Constructor Detail

      • EdiValidator

        public EdiValidator()
    • Method Detail

      • validate

        public void validate​(EdiElement element)
      • validate

        public void validate​(Message element)
      • validate

        public void validate​(LoopSegment element)
      • validate

        public void validate​(Segment element)
      • validate

        public void validate​(Composite element)
      • validate

        public void validate​(Field element)
      • validateDataAgainstStdCodes

        protected boolean validateDataAgainstStdCodes​(Field field)
        Validate the given field against the stored StdCodes.
        Parameters:
        field - - field to validate
        Returns:
        true if the field contains a valid data value
      • validateParent

        protected void validateParent​(EdiElement element)
      • validateParentElement

        protected void validateParentElement​(EdiElement ruleElement,
                                             EdiElement dataElement)
      • validateChildren

        protected void validateChildren​(EdiElement ruleElement,
                                        EdiElement dataElement)
        Validates the data element against the rule element. Note that this function is controlled by the flag: isMatchFieldsByID(). This is needed to control how the children of the given objects are matched together for validation. For EDI2XML processing the edi file is parsed and the resulting data object representation does not have any ID/name values only data. In XML2EDI processing the data object representation has id and data values. Having IDs makes matching objects far easier, however in the absence of IDs we must rely on the simple positional approach.
        Parameters:
        ruleElement -
        dataElement -
      • validateChildrenByPosition

        protected void validateChildrenByPosition​(EdiElement ruleElement,
                                                  EdiElement dataElement)
      • validateChildrenMatchWithIDs

        protected void validateChildrenMatchWithIDs​(EdiElement ruleElement,
                                                    EdiElement dataElement)
      • validate

        public void validate​(Message ruleElement,
                             Message dataElement)
      • validate

        public void validate​(Segment ruleElement,
                             Segment dataElement)
      • validate

        public void validate​(Field ruleElement,
                             Field dataElement)
      • checkForValidationErrors

        public void checkForValidationErrors()
                                      throws EdiValidationException
        Called to check if there are any validation errors and throws an exception if so.
        Throws:
        EdiValidationException - if there are any validation errors logged
      • getRootElement

        public Message getRootElement()
      • setRootElement

        public void setRootElement​(Message rootElement)
      • handleValidationFailure

        protected void handleValidationFailure​(java.lang.String message)
      • getValidationErrors

        public java.util.List<java.lang.String> getValidationErrors()
      • setValidationErrors

        public void setValidationErrors​(java.util.List<java.lang.String> validationErrors)
      • clearValidationErrors

        public void clearValidationErrors()
      • hasValidationErrors

        public boolean hasValidationErrors()
      • processSegmentCount

        protected void processSegmentCount​(Segment segment)
        Validates that the EDIFACT UNT segment count value matches the actual number of segment in the msg. Note this method expects the segments to be processed in the same order in which they occur in the msg. The segment count only counts the segments: UNH-UNT inclusive
        Parameters:
        segment - - the current segment being processed.
      • reset

        public void reset()
      • getParsingPosition

        protected java.lang.String getParsingPosition()
      • getParsingPosition

        protected java.lang.String getParsingPosition​(java.lang.String elementName)
      • isMatchFieldsByID

        public boolean isMatchFieldsByID()
      • setMatchFieldsByID

        public void setMatchFieldsByID​(boolean matchFieldsByID)