View Javadoc
1   /*
2    * Copyright 2009 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *     
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.commons.ihe.xds.core.validate;
17  
18  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidationMessage.*;
19  import static org.openehealth.ipf.commons.ihe.xds.core.validate.ValidatorAssertions.*;
20  
21  import org.openehealth.ipf.commons.ihe.xds.core.ebxml.EbXMLRegistryObject;
22  
23  /**
24   * Validates an external identifier.
25   * @author Jens Riemschneider
26   */
27  public class ExternalIdentifierValidation implements RegistryObjectValidator {
28      private final String scheme;
29      private final ValueValidator validator;
30  
31      /**
32       * Constructs a validation.
33       * @param scheme
34       *          the scheme of the external identifier to validate.
35       * @param validator
36       *          the validator to call for the value of the external identifier.
37       */
38      public ExternalIdentifierValidation(String scheme, ValueValidator validator) {
39          this.scheme = scheme;
40          this.validator = validator;
41      }
42  
43      @Override
44      public void validate(EbXMLRegistryObject obj) throws XDSMetaDataException {
45          String value = obj.getExternalIdentifierValue(scheme);
46          metaDataAssert(value != null, MISSING_EXTERNAL_IDENTIFIER, scheme);
47          
48          validator.validate(value);
49      }
50  }