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 private ServiceTracker<LdapApiService, LdapApiService> serviceTracker;
40
41 class LdapApiServiceTracker implements ServiceTrackerCustomizer<LdapApiService, LdapApiService>
42 {
43 private BundleContext bundleContext;
44 private ServiceRegistration<?> registration;
45
46
47 LdapApiServiceTracker( BundleContext context )
48 {
49 this.bundleContext = context;
50 }
51
52
53 @Override
54 public LdapApiService addingService( ServiceReference<LdapApiService> reference )
55 {
56 LdapApiService ldapApiService = bundleContext.getService( reference );
57 LdapProtocolCodecFactory factory = new LdapProtocolCodecFactory( ldapApiService );
58 registration = bundleContext.registerService( LdapProtocolCodecFactory.class.getName(), factory, null );
59 ldapApiService.registerProtocolCodecFactory( factory );
60 return ldapApiService;
61 }
62
63
64 @Override
65 public void modifiedService( ServiceReference<LdapApiService> reference, LdapApiService service )
66 {
67
68 }
69
70
71 @Override
72 public void removedService( ServiceReference<LdapApiService> reference, LdapApiService service )
73 {
74
75
76 registration.unregister();
77 }
78 }
79
80
81
82
83
84 public LdapProtocolCodecActivator()
85 {
86
87 }
88
89
90
91
92
93 @Override
94 public void start( BundleContext bundleContext ) throws Exception
95 {
96 LdapApiServiceTracker ldapApiServiceTracker = new LdapApiServiceTracker( bundleContext );
97 serviceTracker = new ServiceTracker<>( bundleContext, LdapApiService.class,
98 ldapApiServiceTracker );
99 serviceTracker.open();
100 }
101
102
103
104
105
106 @Override
107 public void stop( BundleContext bundleContext ) throws Exception
108 {
109 serviceTracker.close();
110 }
111 }