Class EdiValidator
- java.lang.Object
-
- com.adaptris.adapter.edistream.validator.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.- Ensure that the data values are within the min/max range
- Ensure that the data value matches the expected data type
- Ensure that the segment repetition range is met
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.adaptris.adapter.edistream.parser.event.IParsingEventListener
IParsingEventListener.ParsedEvent
-
-
Constructor Summary
Constructors Constructor Description EdiValidator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkForValidationErrors()
Called to check if there are any validation errors and throws an exception if so.void
clearValidationErrors()
protected java.lang.String
getParsingPosition()
protected java.lang.String
getParsingPosition(java.lang.String elementName)
IParsingPositionSupplier
getParsingPositionHelper()
Message
getRootElement()
java.util.List<java.lang.String>
getValidationErrors()
void
handleBeginParsingEvent(IParsingEventListener.ParsedEvent event, EdiElement element)
void
handleElementRepetitionsCompleted(EdiElement rule, int repetitions)
void
handleEndParsingEvent(IParsingEventListener.ParsedEvent event, EdiElement element)
We validate segments once they have been fully parsedvoid
handlePopStackItem(EdiElement element)
void
handlePushStackItem(EdiElement element)
protected void
handleValidationFailure(java.lang.String message)
boolean
hasValidationErrors()
boolean
isMatchFieldsByID()
protected void
processSegmentCount(Segment segment)
Validates that the EDIFACT UNT segment count value matches the actual number of segment in the msg.void
reset()
void
setMatchFieldsByID(boolean matchFieldsByID)
void
setParsingPositionHelper(IParsingPositionSupplier parsingPositionHelper)
void
setRootElement(Message rootElement)
void
setValidationErrors(java.util.List<java.lang.String> validationErrors)
void
validate(Composite element)
void
validate(Composite ruleElement, Composite dataElement)
void
validate(EdiElement element)
void
validate(EdiElement ruleElement, EdiElement dataElement)
void
validate(Field element)
void
validate(Field ruleElement, Field dataElement)
void
validate(LoopSegment element)
void
validate(LoopSegment ruleElement, LoopSegment dataElement)
void
validate(Message element)
void
validate(Message ruleElement, Message dataElement)
void
validate(Segment element)
void
validate(Segment ruleElement, Segment dataElement)
protected void
validateChildren(EdiElement ruleElement, EdiElement dataElement)
Validates the data element against the rule element.protected void
validateChildrenByPosition(EdiElement ruleElement, EdiElement dataElement)
protected void
validateChildrenMatchWithIDs(EdiElement ruleElement, EdiElement dataElement)
protected boolean
validateDataAgainstStdCodes(Field field)
Validate the given field against the stored StdCodes.protected void
validateParent(EdiElement element)
protected void
validateParentElement(EdiElement ruleElement, EdiElement dataElement)
-
-
-
Method Detail
-
validate
public void validate(EdiElement element)
-
validate
public void validate(EdiElement ruleElement, EdiElement dataElement)
-
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(LoopSegment ruleElement, LoopSegment dataElement)
-
handleBeginParsingEvent
public void handleBeginParsingEvent(IParsingEventListener.ParsedEvent event, EdiElement element)
- Specified by:
handleBeginParsingEvent
in interfaceIParsingEventListener
-
handleEndParsingEvent
public void handleEndParsingEvent(IParsingEventListener.ParsedEvent event, EdiElement element) throws EdiValidationException
We validate segments once they have been fully parsed- Specified by:
handleEndParsingEvent
in interfaceIParsingEventListener
- Parameters:
event
-element
-- Throws:
EdiValidationException
-
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)
-
handlePopStackItem
public void handlePopStackItem(EdiElement element)
- Specified by:
handlePopStackItem
in interfaceIStackChangeListener
-
handlePushStackItem
public void handlePushStackItem(EdiElement element)
- Specified by:
handlePushStackItem
in interfaceIStackChangeListener
-
handleElementRepetitionsCompleted
public void handleElementRepetitionsCompleted(EdiElement rule, int repetitions)
- Specified by:
handleElementRepetitionsCompleted
in interfaceIStackChangeListener
-
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()
-
setParsingPositionHelper
public void setParsingPositionHelper(IParsingPositionSupplier parsingPositionHelper)
-
getParsingPositionHelper
public IParsingPositionSupplier getParsingPositionHelper()
-
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)
-
-