View Javadoc
1   /*
2    * Copyright 2018 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.spring.map.config;
17  
18  import org.openehealth.ipf.commons.core.config.Configurer;
19  import org.openehealth.ipf.commons.core.config.OrderedConfigurer;
20  import org.openehealth.ipf.commons.core.config.Registry;
21  import org.openehealth.ipf.commons.spring.map.MappingResourceHolder;
22  import org.openehealth.ipf.commons.spring.map.SpringBidiMappingService;
23  import org.slf4j.Logger;
24  import org.slf4j.LoggerFactory;
25  
26  import java.util.Collection;
27  
28  /**
29   * {@link Configurer} used to add all {@link CustomMappings} 
30   * bean occurrences from the spring application context
31   * to the provided {@link SpringBidiMappingService}.
32   * 
33   * @author Boris Stanojevic
34   */
35  public class CustomMappingsConfigurer<R extends Registry> extends OrderedConfigurer<MappingResourceHolder, R> {
36  
37      private SpringBidiMappingService mappingService;
38      
39      private static final Logger LOG = LoggerFactory.getLogger(CustomMappingsConfigurer.class);
40      
41      /**
42       * lookup for the specific {@link CustomMappings} objects inside
43       * the given beanFactory
44       * 
45       * @see OrderedConfigurer
46       */
47      @Override
48      public Collection<MappingResourceHolder> lookup(Registry registry) {
49          return registry.beans(MappingResourceHolder.class).values();
50      }
51  
52      /**
53       * configuration logic  
54       */
55      @Override
56      public void configure(MappingResourceHolder configuration) throws Exception {
57          if (configuration.getMappingResources() != null) {
58              mappingService.setMappingResources(configuration.getMappingResources());
59              LOG.debug("Mapping scripts added {}", configuration);
60          }
61      }
62      
63      public SpringBidiMappingService getMappingService() {
64          return mappingService;
65      }
66  
67      public void setMappingService(SpringBidiMappingService mappingService) {
68          this.mappingService = mappingService;
69      }
70  
71  }