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.extras;
21
22
23 import java.util.ArrayList;
24
25 import org.apache.directory.api.ldap.codec.StockCodecFactoryUtil;
26 import org.apache.directory.api.ldap.codec.api.LdapApiService;
27 import org.osgi.framework.BundleActivator;
28 import org.osgi.framework.BundleContext;
29 import org.osgi.framework.ServiceReference;
30 import org.osgi.util.tracker.ServiceTracker;
31 import org.osgi.util.tracker.ServiceTrackerCustomizer;
32
33
34
35
36
37
38
39
40 public class ExtrasBundleActivator implements BundleActivator
41 {
42
43 private ServiceTracker<LdapApiService, LdapApiService> serviceTracker;
44
45 class LdapApiServiceTracker implements ServiceTrackerCustomizer<LdapApiService, LdapApiService>
46 {
47
48 private BundleContext context;
49
50
51 LdapApiServiceTracker( BundleContext context )
52 {
53 this.context = context;
54 }
55
56
57 @Override
58 public LdapApiService addingService( ServiceReference<LdapApiService> reference )
59 {
60 LdapApiService ldapApiService = context.getService( reference );
61 StockCodecFactoryUtil.loadStockControls( ldapApiService );
62 ExtrasCodecFactoryUtil.loadExtrasControls( ldapApiService );
63 ExtrasCodecFactoryUtil.loadExtrasExtendedOperations( ldapApiService );
64 ExtrasCodecFactoryUtil.loadExtrasIntermediateResponses( ldapApiService );
65 return ldapApiService;
66 }
67
68
69 @Override
70 public void modifiedService( ServiceReference<LdapApiService> reference, LdapApiService ldapApiService )
71 {
72 }
73
74
75 @Override
76 public void removedService( ServiceReference<LdapApiService> reference, LdapApiService ldapApiService )
77 {
78
79 for ( String oid : new ArrayList<>( ldapApiService.getRequestControlFactories().keySet() ) )
80 {
81 ldapApiService.unregisterRequestControl( oid );
82 }
83
84 for ( String oid : new ArrayList<>( ldapApiService.getResponseControlFactories().keySet() ) )
85 {
86 ldapApiService.unregisterResponseControl( oid );
87 }
88
89 for ( String oid : new ArrayList<>( ldapApiService.getExtendedRequestFactories().keySet() ) )
90 {
91 ldapApiService.unregisterExtendedRequest( oid );
92 }
93
94 for ( String oid : new ArrayList<>( ldapApiService.getExtendedResponseFactories().keySet() ) )
95 {
96 ldapApiService.unregisterExtendedResponse( oid );
97 }
98
99 for ( String oid : new ArrayList<>( ldapApiService.getIntermediateResponseFactories().keySet() ) )
100 {
101 ldapApiService.unregisterIntermediateResponse( oid );
102 }
103 }
104 }
105
106
107
108
109
110 @Override
111 public void start( BundleContext context ) throws Exception
112 {
113 LdapApiServiceTracker ldapApiServiceTracker = new LdapApiServiceTracker( context );
114 serviceTracker = new ServiceTracker<>(
115 context, LdapApiService.class, ldapApiServiceTracker );
116 serviceTracker.open();
117 }
118
119
120
121
122
123 @Override
124 public void stop( BundleContext context ) throws Exception
125 {
126 serviceTracker.close();
127 }
128 }