001/*
002 *   Licensed to the Apache Software Foundation (ASF) under one
003 *   or more contributor license agreements.  See the NOTICE file
004 *   distributed with this work for additional information
005 *   regarding copyright ownership.  The ASF licenses this file
006 *   to you under the Apache License, Version 2.0 (the
007 *   "License"); you may not use this file except in compliance
008 *   with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *   Unless required by applicable law or agreed to in writing,
013 *   software distributed under the License is distributed on an
014 *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *   KIND, either express or implied.  See the License for the
016 *   specific language governing permissions and limitations
017 *   under the License.
018 *
019 */
020package org.apache.directory.shared.ldap.extras;
021
022
023import org.apache.directory.shared.ldap.codec.api.ControlFactory;
024import org.apache.directory.shared.ldap.codec.api.ExtendedRequestFactory;
025import org.apache.directory.shared.ldap.codec.api.LdapApiService;
026import org.apache.directory.shared.ldap.codec.api.UnsolicitedResponseFactory;
027import org.apache.directory.shared.ldap.extras.controls.SyncDoneValue;
028import org.apache.directory.shared.ldap.extras.controls.SyncInfoValue;
029import org.apache.directory.shared.ldap.extras.controls.SyncModifyDn;
030import org.apache.directory.shared.ldap.extras.controls.SyncRequestValue;
031import org.apache.directory.shared.ldap.extras.controls.SyncStateValue;
032import org.apache.directory.shared.ldap.extras.controls.ppolicy.PasswordPolicy;
033import org.apache.directory.shared.ldap.extras.controls.ppolicy.PasswordPolicyFactory;
034import org.apache.directory.shared.ldap.extras.controls.syncrepl_impl.SyncDoneValueFactory;
035import org.apache.directory.shared.ldap.extras.controls.syncrepl_impl.SyncInfoValueFactory;
036import org.apache.directory.shared.ldap.extras.controls.syncrepl_impl.SyncModifyDnFactory;
037import org.apache.directory.shared.ldap.extras.controls.syncrepl_impl.SyncRequestValueFactory;
038import org.apache.directory.shared.ldap.extras.controls.syncrepl_impl.SyncStateValueFactory;
039import org.apache.directory.shared.ldap.extras.extended.CancelRequest;
040import org.apache.directory.shared.ldap.extras.extended.CertGenerationRequest;
041import org.apache.directory.shared.ldap.extras.extended.GracefulDisconnectResponse;
042import org.apache.directory.shared.ldap.extras.extended.GracefulShutdownRequest;
043import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequest;
044import org.apache.directory.shared.ldap.extras.extended.ads_impl.cancel.CancelFactory;
045import org.apache.directory.shared.ldap.extras.extended.ads_impl.certGeneration.CertGenerationFactory;
046import org.apache.directory.shared.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectFactory;
047import org.apache.directory.shared.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownFactory;
048import org.apache.directory.shared.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureFactory;
049import org.osgi.framework.BundleActivator;
050import org.osgi.framework.BundleContext;
051import org.osgi.framework.ServiceReference;
052
053
054/**
055 * A BundleActivator for the ldap codec extras extension: extra ApacheDS and 
056 * Apache Directory Studio specific controls and extended operations. 
057 *
058 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
059 */
060public class ExtrasBundleActivator implements BundleActivator
061{
062    private ServiceReference codecServiceRef;
063    
064    
065    /**
066     * {@inheritDoc}
067     */
068    public void start( BundleContext context ) throws Exception
069    {
070        codecServiceRef = context.getServiceReference( LdapApiService.class.getName() );
071        LdapApiService codec = ( LdapApiService ) context.getService( codecServiceRef );
072        registerExtrasControls( codec );
073        registerExtrasExtendedOps( codec );
074    }
075    
076    
077    /**
078     * Registers all the extras controls present in this control pack.
079     *
080     * @param codec The codec service.
081     */
082    private void registerExtrasControls( LdapApiService codec )
083    {
084        ControlFactory<?,?> factory = new SyncDoneValueFactory( codec );
085        codec.registerControl( factory );
086        
087        factory = new SyncInfoValueFactory( codec );
088        codec.registerControl( factory );
089        
090        factory = new SyncModifyDnFactory( codec );
091        codec.registerControl( factory );
092        
093        factory = new SyncRequestValueFactory( codec );
094        codec.registerControl( factory );
095
096        factory = new SyncStateValueFactory( codec );
097        codec.registerControl( factory );
098        
099        factory = new PasswordPolicyFactory( codec );
100        codec.registerControl( factory );
101    }
102
103
104    /**
105     * Registers all the extras extended operations present in this control pack.
106     *
107     * @param codec The codec service.
108     */
109    private void registerExtrasExtendedOps( LdapApiService codec )
110    {
111        // --------------------------------------------------------------------
112        // Register Extended Request Factories
113        // --------------------------------------------------------------------
114        
115        
116        ExtendedRequestFactory<?,?> extReqfactory = new CancelFactory( codec );
117        codec.registerExtendedRequest( extReqfactory );
118        
119        extReqfactory = new CertGenerationFactory( codec );
120        codec.registerExtendedRequest( extReqfactory );
121
122        extReqfactory = new GracefulShutdownFactory( codec );
123        codec.registerExtendedRequest( extReqfactory );
124        
125        extReqfactory = new StoredProcedureFactory( codec );
126        codec.registerExtendedRequest( extReqfactory );
127        
128        
129        // --------------------------------------------------------------------
130        // Register Unsolicited Response Factories
131        // --------------------------------------------------------------------
132        
133        
134        UnsolicitedResponseFactory<?> unsolicitedResponseFactory = new GracefulDisconnectFactory( codec );
135        codec.registerUnsolicitedResponse( unsolicitedResponseFactory );
136    }
137    
138    
139    /**
140     * {@inheritDoc}
141     */
142    public void stop( BundleContext context ) throws Exception
143    {
144        LdapApiService codec = ( LdapApiService ) context.getService( codecServiceRef );
145        
146        codec.unregisterControl( SyncDoneValue.OID );
147        codec.unregisterControl( SyncInfoValue.OID );
148        codec.unregisterControl( SyncModifyDn.OID );
149        codec.unregisterControl( SyncRequestValue.OID );
150        codec.unregisterControl( SyncStateValue.OID );
151        codec.unregisterControl( PasswordPolicy.OID );
152        
153        codec.unregisterExtendedRequest( CancelRequest.EXTENSION_OID );
154        codec.unregisterExtendedRequest( CertGenerationRequest.EXTENSION_OID );
155        codec.unregisterExtendedRequest( GracefulShutdownRequest.EXTENSION_OID );
156        codec.unregisterExtendedRequest( StoredProcedureRequest.EXTENSION_OID );
157        
158        codec.unregisterUnsolicitedResponse( GracefulDisconnectResponse.EXTENSION_OID );
159    }
160}