class XONValidator implements ValueValidator {

    @Override
    public void validate(String hl7XON) throws XDSMetaDataException {
        Organization organization = Hl7v2Based.parse(hl7XON, Organization.class);
        metaDataAssert(organization != null, ORGANIZATION_NAME_MISSING, hl7XON);

        XON xon = organization.getHapiObject();
        metaDataAssert(isNotEmpty(xon.getXon1_OrganizationName().getValue()), ORGANIZATION_NAME_MISSING, hl7XON);

        HD hd = xon.getXon6_AssigningAuthority();
        if (HD_VALIDATOR.isEmpty(hd)) {
            String idNumber = xon.getXon10_OrganizationIdentifier().getValue();
            if (isNotEmpty(idNumber)) {
                OID_VALIDATOR.validate(idNumber);
            }
        } else {
            HD_VALIDATOR.validate(hd, hl7XON);
        }

        metaDataAssert(countMatches(hl7XON, "^") <= 9, ORGANIZATION_TOO_MANY_COMPONENTS);
        metaDataAssert(isEmpty(xon.getXon2_OrganizationNameTypeCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
        metaDataAssert(isEmpty(xon.getXon3_IDNumber().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
        metaDataAssert(isEmpty(xon.getXon4_CheckDigit().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
        metaDataAssert(isEmpty(xon.getXon5_CheckDigitScheme().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
        metaDataAssert(isEmpty(xon.getXon7_IdentifierTypeCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
        metaDataAssert(HD_VALIDATOR.isEmpty(xon.getXon8_AssigningFacility()), ORGANIZATION_TOO_MANY_COMPONENTS);
        metaDataAssert(isEmpty(xon.getXon9_NameRepresentationCode().getValue()), ORGANIZATION_TOO_MANY_COMPONENTS);
    }

}