Package ca.uhn.hl7v2.validation

Examples of ca.uhn.hl7v2.validation.ValidationException


    return failed(msg, Location.UNKNOWN);
  }

 
  protected ValidationException[] failed(String msg, Location location) {
    ValidationException ve = new ValidationException(msg, severity);
    ve.setError(getErrorCode());
    ve.setLocation(location);
    return new ValidationException[] { ve };
  }
View Full Code Here


  }

  protected ValidationException[] failed(Exception e, Location location) {
    if (e instanceof ValidationException)
      return new ValidationException[] { (ValidationException) e };
    ValidationException ve = new ValidationException(e.getMessage(), e, severity);
    ve.setError(getErrorCode());
    ve.setLocation(location);
    return new ValidationException[] { ve };
  }
View Full Code Here

        throw new Error("Failed to find " + nextName + " in structure. This is probably a HAPI bug.");
      }
    }

    if (choicesWithContent != null && choicesWithContent.size() > 1) {
      theExceptions.add(new ValidationException("Structure '" + theStructure.getName() + "' must have content only in one of the following choices: " + choicesWithContent.toString()));
    }

  }
View Full Code Here

      if (hasCorrectNamespace(doc, validationErrors)) {
        XMLUtils.validate(doc, getSchemaLocation(doc), new ErrorHandler(validationErrors));
      }
    } catch (Exception e) {
      log.error("Unable to validate message: {}", e.getMessage(), e);
      validationErrors.add(new ValidationException("Unable to validate message "
          + e.getMessage(), e));
    }

    return validationErrors.toArray(new ValidationException[validationErrors.size()]);
View Full Code Here

  private boolean hasCorrectNamespace(Document domDocumentToValidate,
      List<ValidationException> validationErrors) {
    String nsUri = domDocumentToValidate.getDocumentElement().getNamespaceURI();
    boolean ok = DEFAULT_NS.equals(nsUri);
    if (!ok) {
      ValidationException e = new ValidationException(
          "The default namespace of the XML document is incorrect - should be "
              + DEFAULT_NS + " but was " + nsUri);
      validationErrors.add(e);
      log.error(e.getMessage());
    }
    return ok;
  }
View Full Code Here

      super();
      this.validationErrors = validationErrors;
    }

    public boolean handleError(DOMError error) {
      validationErrors.add(new ValidationException(getSeverity(error) + error.getMessage()));
      return true;
    }
View Full Code Here

  public static final MessageRule WRONG_VERSION = new WrongVersionRule();
 
  public ValidationException[] apply(Message msg) {
    List<ValidationException> exceptions = new ArrayList<ValidationException>();

    ValidationException ve = new ValidationException("Invalid version: " + msg.getVersion());
    Location location = new Location();
    location.setSegmentName("MSH");
    location.setField(12);
    ve.setLocation(location);
    ve.setError(ErrorCode.UNSUPPORTED_VERSION_ID);
    exceptions.add(ve);

    return exceptions.toArray(new ValidationException[exceptions.size()]);
  }
View Full Code Here

        for (Structure rep : theMsg.getAll(name)) {
         
          if (!rep.isEmpty()) {
            if (!theMsg.getStructuresWhichChildAppliesTo(name).contains(messageStructure)) {
              String msgSimpleName = theMsg.getMessage().getClass().getSimpleName();
              theExceptions.add(new ValidationException("Message (superstructure " + msgSimpleName + ") of type " + messageStructure + " must not have content in " + name));
            }
            continue FORNAME;
          }
         
        }
View Full Code Here

    List<ValidationException> exceptions = new ArrayList<ValidationException>();

    for (Iterator<Structure> iter = ReadOnlyMessageIterator
        .createPopulatedStructureIterator(msg, GenericSegment.class); iter.hasNext();) {
      String segmentName = iter.next().getName();
      ValidationException ve = new ValidationException("Found unknown segment: " + segmentName);
      Location location = new Location();
      location.setSegmentName(segmentName);
      ve.setLocation(location);
      exceptions.add(ve);
    }
    return exceptions.toArray(new ValidationException[exceptions.size()]);
  }
View Full Code Here

                try {
                    ValidationException[] shortList = testAgainstProfile(msg, id);
                    log.debug("{} non-conformances", shortList.length);
                    problems.addAll(Arrays.asList(shortList));
                } catch (ProfileException e) {
                    problems.add(new ValidationException("Can't validate against profile: " + e.getMessage(), e));
                }
            }           
        } catch (HL7Exception e) {
            problems.add(new ValidationException("Can't validate against profile: " + e.getMessage(), e));
        }
       
        return problems.toArray(new ValidationException[problems.size()]);
    }
View Full Code Here

TOP

Related Classes of ca.uhn.hl7v2.validation.ValidationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.