/** * Calls {@link #initializeHandler()} to obtain a default instance of a * {@link ValidationExceptionHandler} before starting the validation. * * @see ca.uhn.hl7v2.validation.Validator#validate(ca.uhn.hl7v2.model.Message) */ public R validate(Message message) throws HL7Exception { return validate(message, initializeHandler()); }
/** * @see ca.uhn.hl7v2.validation.Validator#validate(ca.uhn.hl7v2.model.Message, * ca.uhn.hl7v2.validation.ValidationExceptionHandler) */ public R validate(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { if (message == null) { throw new NullPointerException("Message may not be null"); } if (handler == null) { throw new NullPointerException("ValidationExceptionHandler may not be null"); } handler.setValidationSubject(message); if (isValidatePrimitives()) testPrimitiveRules(message, handler); testMessageRules(message, handler); return handler.result(); }
private void testSubComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Primitive) { testPrimitive((Primitive) type, handler, l); } else if (type instanceof Varies) { testSubComponent(((Varies) type).getData(), handler, l); } }
private void testType(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] components = ((Composite) type).getComponents(); for (int comp = 0; comp < components.length; comp++) { Location location = new Location(l).withComponent(comp + 1); testComponent(components[comp], handler, location); } } else if (type instanceof Varies) { testType(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
private void testComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] component = ((Composite) type).getComponents(); for (int sub = 0; sub < component.length; sub++) { Location location = new Location(l).withSubcomponent(sub + 1); testSubComponent(component[sub], handler, location); } } else if (type instanceof Varies) { testComponent(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
/** * @see ca.uhn.hl7v2.validation.Validator#validate(java.lang.String, * boolean, java.lang.String, * ca.uhn.hl7v2.validation.ValidationExceptionHandler) */ public R validate(String message, boolean isXML, String version, ValidationExceptionHandler<R> handler) throws HL7Exception { if (message == null) { throw new NullPointerException("Message may not be null"); } if (handler == null) { throw new NullPointerException("ValidationExceptionHandler may not be null"); } handler.setValidationSubject(message); List<EncodingRule> rules = new ArrayList<EncodingRule>(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getEncodingRules(version, isXML ? "XML" : "ER7")); } LOG.debug("Validating message against {} encoding rules", rules.size()); for (EncodingRule rule : rules) { ValidationException[] ex = rule.apply(message); if (ex != null && ex.length > 0) { handler.onExceptions(ex); } } return handler.result(); }
private void testPrimitiveRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { LOG.debug("Validating message against primitive type rules"); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedSegmentIterator(message); iter.hasNext();) { Segment s = (Segment) iter.next(); for (int field = 1; field <= s.numFields(); field++) { Type[] t = s.getField(field); for (int rep = 0; rep < t.length; rep++) { Location location = new Location(); location .withSegmentName(s.getName()) .withField(field) .withFieldRepetition(rep); testType(t[rep], handler, location); } } } }
private void testType(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] components = ((Composite) type).getComponents(); for (int comp = 0; comp < components.length; comp++) { Location location = new Location(l).withComponent(comp + 1); testComponent(components[comp], handler, location); } } else if (type instanceof Varies) { testType(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
private void testComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Composite) { Type[] component = ((Composite) type).getComponents(); for (int sub = 0; sub < component.length; sub++) { Location location = new Location(l).withSubcomponent(sub + 1); testSubComponent(component[sub], handler, location); } } else if (type instanceof Varies) { testComponent(((Varies) type).getData(), handler, l); } else { testPrimitive((Primitive) type, handler, l); } }
/** * @see ca.uhn.hl7v2.validation.Validator#validate(java.lang.String, * boolean, java.lang.String, * ca.uhn.hl7v2.validation.ValidationExceptionHandler) */ public R validate(String message, boolean isXML, String version, ValidationExceptionHandler<R> handler) throws HL7Exception { if (message == null) { throw new NullPointerException("Message may not be null"); } if (handler == null) { throw new NullPointerException("ValidationExceptionHandler may not be null"); } handler.setValidationSubject(message); List<EncodingRule> rules = new ArrayList<EncodingRule>(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getEncodingRules(version, isXML ? "XML" : "ER7")); } LOG.debug("Validating message against {} encoding rules", rules.size()); for (EncodingRule rule : rules) { ValidationException[] ex = rule.apply(message); if (ex != null && ex.length > 0) { handler.onExceptions(ex); } } return handler.result(); }
private void testPrimitiveRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { LOG.debug("Validating message against primitive type rules"); for (Iterator<Structure> iter = ReadOnlyMessageIterator .createPopulatedSegmentIterator(message); iter.hasNext();) { Segment s = (Segment) iter.next(); for (int field = 1; field <= s.numFields(); field++) { Type[] t = s.getField(field); for (int rep = 0; rep < t.length; rep++) { Location location = new Location(); location .withSegmentName(s.getName()) .withField(field) .withFieldRepetition(rep); testType(t[rep], handler, location); } } } }
/** * @see ca.uhn.hl7v2.validation.Validator#validate(ca.uhn.hl7v2.model.Message, * ca.uhn.hl7v2.validation.ValidationExceptionHandler) */ public R validate(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { if (message == null) { throw new NullPointerException("Message may not be null"); } if (handler == null) { throw new NullPointerException("ValidationExceptionHandler may not be null"); } handler.setValidationSubject(message); if (isValidatePrimitives()) testPrimitiveRules(message, handler); testMessageRules(message, handler); return handler.result(); }
/** * Calls {@link #initializeHandler()} to obtain a default instance of a * {@link ValidationExceptionHandler} before starting the validation. * * @see ca.uhn.hl7v2.validation.Validator#validate(Message, * ValidationExceptionHandler) */ public R validate(String message, boolean isXML, String version) throws HL7Exception { return validate(message, isXML, version, initializeHandler()); }
private void testSubComponent(Type type, ValidationExceptionHandler<R> handler, Location l) { if (type instanceof Primitive) { testPrimitive((Primitive) type, handler, l); } else if (type instanceof Varies) { testSubComponent(((Varies) type).getData(), handler, l); } }
private void testMessageRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { Terser t = new Terser(message); String messageType = t.get("MSH-9-1"); String triggerEvent = t.get("MSH-9-2"); List<MessageRule> rules = new ArrayList<MessageRule>(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getMessageRules(message.getVersion(), messageType, triggerEvent)); } LOG.debug("Validating message against {} message rules", rules.size()); for (MessageRule rule : rules) { ValidationException[] ex = rule.apply(message); if (ex != null && ex.length > 0) { handler.onExceptions(ex); } } }
/** * Calls {@link #initializeHandler()} to obtain a default instance of a * {@link ValidationExceptionHandler} before starting the validation. * * @see ca.uhn.hl7v2.validation.Validator#validate(ca.uhn.hl7v2.model.Message) */ public R validate(Message message) throws HL7Exception { return validate(message, initializeHandler()); }
private void testMessageRules(Message message, ValidationExceptionHandler<R> handler) throws HL7Exception { Terser t = new Terser(message); String messageType = t.get("MSH-9-1"); String triggerEvent = t.get("MSH-9-2"); List<MessageRule> rules = new ArrayList<MessageRule>(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getMessageRules(message.getVersion(), messageType, triggerEvent)); } LOG.debug("Validating message against {} message rules", rules.size()); for (MessageRule rule : rules) { ValidationException[] ex = rule.apply(message); if (ex != null && ex.length > 0) { handler.onExceptions(ex); } } }
/** * Calls {@link #initializeHandler()} to obtain a default instance of a * {@link ValidationExceptionHandler} before starting the validation. * * @see ca.uhn.hl7v2.validation.Validator#validate(Message, * ValidationExceptionHandler) */ public R validate(String message, boolean isXML, String version) throws HL7Exception { return validate(message, isXML, version, initializeHandler()); }
private void testPrimitive(Primitive p, ValidationExceptionHandler<R> handler, Location l) { List<PrimitiveTypeRule> rules = new ArrayList<PrimitiveTypeRule>(); Message m = p.getMessage(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getPrimitiveRules(m.getVersion(), p.getName(), p)); } for (PrimitiveTypeRule rule : rules) { ValidationException[] exceptions = rule.apply(p.getValue()); for (ValidationException ve : exceptions) { ve.setLocation(l); } if (exceptions.length > 0) { handler.onExceptions(exceptions); } } }
private void testPrimitive(Primitive p, ValidationExceptionHandler<R> handler, Location l) { List<PrimitiveTypeRule> rules = new ArrayList<PrimitiveTypeRule>(); Message m = p.getMessage(); if (getValidationContext() != null) { rules.addAll(getValidationContext().getPrimitiveRules(m.getVersion(), p.getName(), p)); } for (PrimitiveTypeRule rule : rules) { ValidationException[] exceptions = rule.apply(p.getValue()); for (ValidationException ve : exceptions) { ve.setLocation(l); } if (exceptions.length > 0) { handler.onExceptions(exceptions); } } }