View Javadoc
1   /*
2    * Copyright 2016 Function1. All Rights Reserved.
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 tools.gsf.config.inject;
17  
18  import org.slf4j.Logger;
19  import org.slf4j.LoggerFactory;
20  
21  import COM.FutureTense.Interfaces.ICS;
22  import tools.gsf.time.Stopwatch;
23  
24  /**
25   * @author Tony Field
26   * @since 2016-07-21
27   */
28  public class AnnotationInjector implements Injector {
29  
30  	private static final Logger LOG = LoggerFactory.getLogger(AnnotationInjector.class);
31  	
32  	private final Stopwatch stopwatch;
33      private final Injector[] injectors;
34  
35      public AnnotationInjector(Stopwatch stopwatch, Injector... injectors) {
36          this.stopwatch = stopwatch;
37          this.injectors = injectors;
38      }
39  
40      @Override
41      public void inject(Object dependent) {
42          stopwatch.start();
43          for (Injector injector : injectors) {
44          	if (LOG.isDebugEnabled()) {
45          		LOG.debug("AnnotationInjector will now attempt injection into " + dependent + " using injector " + injector.getClass().getSimpleName());
46          	}        	
47              injector.inject(dependent);
48              stopwatch.split("AnnotationInjector: {} injection done", injector.getClass().getSimpleName());
49          }
50          stopwatch.elapsed("AnnotationInjector: injection complete");
51      }
52  }