/** * @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(); }
/** * @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 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); } } }
private <R> void handleException(ValidationExceptionHandler<R> handler, R result) throws HL7Exception { if (handler.hasFailed()) { HL7Exception e = new HL7Exception("Validation has failed"); e.setDetail(result); if (result instanceof Message) e.setResponseMessage((Message)result); throw e; } }
/** * @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 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); } } }
private <R> void handleException(ValidationExceptionHandler<R> handler, R result) throws HL7Exception { if (handler.hasFailed()) { HL7Exception e = new HL7Exception("Validation has failed"); e.setDetail(result); if (result instanceof Message) e.setResponseMessage((Message)result); throw e; } }
/** * @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 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); } } }