View Javadoc

1   /* This file is part of COPAL (COntext Provisioning for All).
2    *
3    * COPAL is a part of SM4All (Smart hoMes for All) project.
4    *
5    * COPAL is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * COPAL is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with COPAL. If not, see <http://www.gnu.org/licenses/>.
17   */
18  package at.ac.tuwien.infosys.sm4all.copal.api.helpers;
19  
20  import org.osgi.framework.ServiceReference;
21  import org.osgi.util.tracker.ServiceTrackerCustomizer;
22  
23  /**
24   * This class implements {@link ServiceTrackerCustomizer} interface and converts
25   * the calls to {@link ServiceTrackerCustomizer}'s method into calls to
26   * {@link DependencyTrackerCustomizer}'s respective methods.
27   * 
28   * @author sanjin
29   */
30  public class DependencyTracker implements ServiceTrackerCustomizer {
31  
32      private final String dependencyName;
33      private final DependencyTrackerCustomizer customizer;
34  
35      /**
36       * Creates instance of {@link ServiceTrackerCustomizer} for dependency with
37       * given name and calls methods on given {@link DependencyTrackerCustomizer}
38       * .
39       * 
40       * @param dependencyName the name of the dependency to be tracked.
41       * @param customizer the {@link DependencyTrackerCustomizer} which methods
42       *        should be called.
43       */
44      public DependencyTracker(final String dependencyName,
45              final DependencyTrackerCustomizer customizer) {
46          this.dependencyName = dependencyName;
47          this.customizer = customizer;
48      }
49  
50      @Override
51      public Object addingService(final ServiceReference reference) {
52          return this.customizer.addingService(this.dependencyName, reference);
53      }
54  
55      @Override
56      public void modifiedService(final ServiceReference reference,
57              final Object service) {
58          this.customizer.modifiedService(this.dependencyName, reference, service);
59      }
60  
61      @Override
62      public void removedService(final ServiceReference reference,
63              final Object service) {
64          this.customizer.removedService(this.dependencyName, reference, service);
65      }
66  }