1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.codec.protocol.mina;
21
22
23 import org.apache.directory.api.ldap.codec.api.LdapApiService;
24 import org.osgi.framework.BundleActivator;
25 import org.osgi.framework.BundleContext;
26 import org.osgi.framework.ServiceReference;
27 import org.osgi.framework.ServiceRegistration;
28 import org.osgi.util.tracker.ServiceTracker;
29 import org.osgi.util.tracker.ServiceTrackerCustomizer;
30
31
32
33
34
35
36
37 public class LdapProtocolCodecActivator implements BundleActivator
38 {
39
40 private ServiceTracker<LdapApiService, LdapApiService> serviceTracker;
41
42 class LdapApiServiceTracker implements ServiceTrackerCustomizer<LdapApiService, LdapApiService>
43 {
44 private BundleContext bundleContext;
45 private ServiceRegistration<?> registration;
46
47
48 LdapApiServiceTracker( BundleContext context )
49 {
50 this.bundleContext = context;
51 }
52
53
54 @Override
55 public LdapApiService addingService( ServiceReference<LdapApiService> reference )
56 {
57 LdapApiService ldapApiService = bundleContext.getService( reference );
58 LdapProtocolCodecFactory factory = new LdapProtocolCodecFactory( ldapApiService );
59 registration = bundleContext.registerService( LdapProtocolCodecFactory.class.getName(), factory, null );
60 ldapApiService.registerProtocolCodecFactory( factory );
61 return ldapApiService;
62 }
63
64
65 @Override
66 public void modifiedService( ServiceReference<LdapApiService> reference, LdapApiService service )
67 {
68 }
69
70
71 @Override
72 public void removedService( ServiceReference<LdapApiService> reference, LdapApiService service )
73 {
74 registration.unregister();
75 }
76 }
77
78
79
80
81
82 public LdapProtocolCodecActivator()
83 {
84 }
85
86
87
88
89
90 @Override
91 public void start( BundleContext bundleContext ) throws Exception
92 {
93 LdapApiServiceTracker ldapApiServiceTracker = new LdapApiServiceTracker( bundleContext );
94 serviceTracker = new ServiceTracker<>( bundleContext, LdapApiService.class,
95 ldapApiServiceTracker );
96 serviceTracker.open();
97 }
98
99
100
101
102
103 @Override
104 public void stop( BundleContext bundleContext ) throws Exception
105 {
106 serviceTracker.close();
107 }
108 }