View Javadoc
1   /*
2    * Copyright 2016 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  
17  package org.openehealth.ipf.commons.ihe.fhir.translation;
18  
19  import org.openehealth.ipf.commons.map.MappingService;
20  
21  import java.util.Optional;
22  
23  /**
24   * Default URI Mapper implementation that requires a {@link MappingService}
25   * for URI-to-OID translation
26   *
27   * @author Christian Ohr
28   * @since 3.1
29   */
30  public class DefaultUriMapper extends AbstractUriMapper {
31  
32      private final MappingService mappingService;
33      private String uriToOidMappingKey;
34      private String uriToNamespaceMappingKey;
35  
36      public DefaultUriMapper(MappingService mappingService) {
37          this.mappingService = mappingService;
38      }
39  
40      public DefaultUriMapper(MappingService mappingService, String uriToOidMappingKey, String uriToNamespaceMappingKey) {
41          this.mappingService = mappingService;
42          this.uriToOidMappingKey = uriToOidMappingKey;
43          this.uriToNamespaceMappingKey = uriToNamespaceMappingKey;
44      }
45  
46      @Override
47      protected Optional<String> mapUriToOid(String uri) {
48          return Optional.ofNullable((String) mappingService.get(uriToOidMappingKey, uri));
49      }
50  
51      @Override
52      protected Optional<String> mapOidToUri(String oid) {
53          return Optional.ofNullable((String) mappingService.getKey(uriToOidMappingKey, oid));
54      }
55  
56      @Override
57      protected Optional<String> mapUriToNamespace(String uri) {
58          return Optional.ofNullable((String) mappingService.get(uriToNamespaceMappingKey, uri));
59      }
60  
61      @Override
62      protected Optional<String> mapNamespaceToUri(String namespace) {
63          return Optional.ofNullable((String) mappingService.getKey(uriToNamespaceMappingKey, namespace));
64      }
65  }