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.api.ldap.extras;
021
022
023import org.apache.directory.api.ldap.codec.api.ControlFactory;
024import org.apache.directory.api.ldap.codec.api.LdapApiService;
025import org.apache.directory.api.ldap.extras.controls.ad.AdDirSync;
026import org.apache.directory.api.ldap.extras.controls.ad_impl.AdDirSyncFactory;
027import org.apache.directory.api.ldap.extras.controls.ppolicy.PasswordPolicy;
028import org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyFactory;
029import org.apache.directory.api.ldap.extras.controls.syncrepl.syncDone.SyncDoneValue;
030import org.apache.directory.api.ldap.extras.controls.syncrepl.syncInfoValue.SyncInfoValue;
031import org.apache.directory.api.ldap.extras.controls.syncrepl.syncInfoValue.SyncRequestValue;
032import org.apache.directory.api.ldap.extras.controls.syncrepl.syncState.SyncStateValue;
033import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueFactory;
034import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncInfoValueFactory;
035import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueFactory;
036import org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncStateValueFactory;
037import org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelFactory;
038import org.apache.directory.api.ldap.extras.extended.ads_impl.certGeneration.CertGenerationFactory;
039import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectFactory;
040import org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownFactory;
041import org.apache.directory.api.ldap.extras.extended.ads_impl.pwdModify.PasswordModifyFactory;
042import org.apache.directory.api.ldap.extras.extended.ads_impl.startTls.StartTlsFactory;
043import org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureFactory;
044import org.apache.directory.api.ldap.extras.extended.ads_impl.whoAmI.WhoAmIFactory;
045import org.apache.directory.api.ldap.extras.extended.cancel.CancelRequest;
046import org.apache.directory.api.ldap.extras.extended.certGeneration.CertGenerationRequest;
047import org.apache.directory.api.ldap.extras.extended.gracefulDisconnect.GracefulDisconnectResponse;
048import org.apache.directory.api.ldap.extras.extended.gracefulShutdown.GracefulShutdownRequest;
049import org.apache.directory.api.ldap.extras.extended.pwdModify.PasswordModifyRequest;
050import org.apache.directory.api.ldap.extras.extended.startTls.StartTlsRequest;
051import org.apache.directory.api.ldap.extras.extended.storedProcedure.StoredProcedureRequest;
052import org.apache.directory.api.ldap.extras.extended.whoAmI.WhoAmIRequest;
053import org.osgi.framework.BundleActivator;
054import org.osgi.framework.BundleContext;
055import org.osgi.framework.ServiceReference;
056
057
058/**
059 * A BundleActivator for the ldap codec extras extension: extra ApacheDS and 
060 * Apache Directory Studio specific controls and extended operations. 
061 *
062 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
063 */
064public class ExtrasBundleActivator implements BundleActivator
065{
066    private ServiceReference<?> codecServiceRef;
067
068
069    /**
070     * {@inheritDoc}
071     */
072    public void start( BundleContext context ) throws Exception
073    {
074        codecServiceRef = context.getServiceReference( LdapApiService.class.getName() );
075        LdapApiService codec = ( LdapApiService ) context.getService( codecServiceRef );
076        registerExtrasControls( codec );
077        registerExtrasExtendedOps( codec );
078    }
079
080
081    /**
082     * Registers all the extras controls present in this control pack.
083     *
084     * @param codec The codec service.
085     */
086    private void registerExtrasControls( LdapApiService codec )
087    {
088        ControlFactory<SyncDoneValue> syncDoneValuefactory = new SyncDoneValueFactory( codec );
089        codec.registerControl( syncDoneValuefactory );
090
091        ControlFactory<SyncInfoValue> syncInfoValueFactory = new SyncInfoValueFactory( codec );
092        codec.registerControl( syncInfoValueFactory );
093
094        ControlFactory<SyncRequestValue> syncRequestValueFactory = new SyncRequestValueFactory( codec );
095        codec.registerControl( syncRequestValueFactory );
096
097        ControlFactory<SyncStateValue> syncStateValuefactory = new SyncStateValueFactory( codec );
098        codec.registerControl( syncStateValuefactory );
099
100        ControlFactory<PasswordPolicy> passwordPolicyFactory = new PasswordPolicyFactory( codec );
101        codec.registerControl( passwordPolicyFactory );
102        
103        ControlFactory<AdDirSync> adDirSyncFactory = new AdDirSyncFactory( codec );
104        codec.registerControl( adDirSyncFactory );
105    }
106
107
108    /**
109     * Registers all the extras extended operations present in this control pack.
110     *
111     * @param codec The codec service.
112     */
113    private void registerExtrasExtendedOps( LdapApiService codec )
114    {
115        // --------------------------------------------------------------------
116        // Register Extended Request Factories
117        // --------------------------------------------------------------------
118
119        CancelFactory cancelFactory = new CancelFactory( codec );
120        codec.registerExtendedRequest( cancelFactory );
121
122        CertGenerationFactory certGenerationFactory = new CertGenerationFactory( codec );
123        codec.registerExtendedRequest( certGenerationFactory );
124
125        GracefulShutdownFactory gracefulShutdownFactory = new GracefulShutdownFactory( codec );
126        codec.registerExtendedRequest( gracefulShutdownFactory );
127
128        StoredProcedureFactory storedProcedureFactory = new StoredProcedureFactory( codec );
129        codec.registerExtendedRequest( storedProcedureFactory );
130
131        PasswordModifyFactory passwordModifyFactory = new PasswordModifyFactory( codec );
132        codec.registerExtendedRequest( passwordModifyFactory );
133
134        GracefulDisconnectFactory gracefulDisconnectFactory = new GracefulDisconnectFactory( codec );
135        codec.registerExtendedRequest( gracefulDisconnectFactory );
136
137        WhoAmIFactory whoAmIFactory = new WhoAmIFactory( codec );
138        codec.registerExtendedRequest( whoAmIFactory );
139
140        StartTlsFactory startTlsFactory = new StartTlsFactory( codec );
141        codec.registerExtendedRequest( startTlsFactory );
142    }
143
144
145    /**
146     * {@inheritDoc}
147     */
148    public void stop( BundleContext context ) throws Exception
149    {
150        LdapApiService codec = ( LdapApiService ) context.getService( codecServiceRef );
151
152        codec.unregisterControl( SyncDoneValue.OID );
153        codec.unregisterControl( SyncInfoValue.OID );
154        codec.unregisterControl( SyncRequestValue.OID );
155        codec.unregisterControl( SyncStateValue.OID );
156        codec.unregisterControl( PasswordPolicy.OID );
157
158        codec.unregisterExtendedRequest( CancelRequest.EXTENSION_OID );
159        codec.unregisterExtendedRequest( CertGenerationRequest.EXTENSION_OID );
160        codec.unregisterExtendedRequest( GracefulShutdownRequest.EXTENSION_OID );
161        codec.unregisterExtendedRequest( StoredProcedureRequest.EXTENSION_OID );
162        codec.unregisterExtendedRequest( GracefulDisconnectResponse.EXTENSION_OID );
163        codec.unregisterExtendedRequest( PasswordModifyRequest.EXTENSION_OID );
164        codec.unregisterExtendedRequest( WhoAmIRequest.EXTENSION_OID );
165        codec.unregisterExtendedRequest( StartTlsRequest.EXTENSION_OID );
166    }
167}