Package org.wso2.carbon.adminconsole.core.internal

Source Code of org.wso2.carbon.adminconsole.core.internal.AdminConsoleServiceComponent

/*
*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing,
*  software distributed under the License is distributed on an
*  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
*  KIND, either express or implied.  See the License for the
*  specific language governing permissions and limitations
*  under the License.
*
*/
package org.wso2.carbon.adminconsole.core.internal;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.adminconsole.core.multitenancy.TenantDBData;
import org.wso2.carbon.adminconsole.core.services.DBMapperService;
import org.wso2.carbon.core.multitenancy.SuperTenantCarbonContext;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;
import org.wso2.carbon.utils.ConfigurationContextService;

/**
* This class activates the admin.console bundle
*
* @scr.component name="admin.console.url.service" immediate="true"
* @scr.reference name="registry.service" interface="org.wso2.carbon.registry.core.service.RegistryService"
* cardinality="1..1" policy="dynamic"  bind="setRegistryService" unbind="unsetRegistryService"
* @scr.reference name="carbon.core.configurationContextService"
* interface="org.wso2.carbon.utils.ConfigurationContextService"
* cardinality="1..1" policy="dynamic" bind="setConfigurationContextService"
* unbind="unsetConfigurationContextService"
*/
public class AdminConsoleServiceComponent {

    private static Log log = LogFactory.getLog(AdminConsoleServiceComponent.class);

    private static RegistryService registryService;

    private ConfigurationContext configurationContext;

    /**
     * Activates the bundle.
     *
     * @param componentContext ComponentContext
     */
    protected void activate(ComponentContext componentContext) {
        AdminConsoleBundleActivator adminConsoleBundleActivator;
        BundleContext bundleContext = componentContext.getBundleContext();

        try {
            adminConsoleBundleActivator = new AdminConsoleBundleActivator();
            adminConsoleBundleActivator.start(bundleContext);

            bundleContext.registerService(AbstractAxis2ConfigurationContextObserver.class.getName(),
                    new AdminConsoleAxis2ConfigObserver(),null);

            bundleContext.registerService(
                    DBMapperService.class.getName(), new TenantDBData(
                            SuperTenantCarbonContext.getCurrentContext(
                                    this.configurationContext).getTenantId()), null);

        } catch (Throwable e) {
            String msg = "Failed To Register Admin Console Bundle As An OSGi Service";
            log.error(msg, e);
        }
    }

    /**
     * Deactivates the bundle. The content of this method is intentionally left blank as the
     * underlying OSGi layer handles the corresponding task.
     *
     * @param componentContext ComponentContext
     */
    protected void deactivate(ComponentContext componentContext) {

    }

    /**
     * Sets Registry Service
     *
     * @param registryService registerService
     */
    protected void setRegistryService(RegistryService registryService) {
        AdminConsoleServiceComponent.registryService = registryService;
    }

    /**
     * Unsets Registry Service
     *
     * @param registryService registerService
     */
    protected void unsetRegistryService(RegistryService registryService) {
        AdminConsoleServiceComponent.registryService = null;
    }
   
    public static RegistryService getRegistryService(){
        return registryService;
    }

    /**
     * This method is used to bind the ConfigurationContext which is being used in order to access
     * it in this particular class
     *
     * @param configurationContextService configuration context service required to grab the current
     */
    public void setConfigurationContextService(
            ConfigurationContextService configurationContextService) {
        this.configurationContext = configurationContextService.getServerConfigContext();
    }

    /**
     * This method is used to unbind the ConfigurationContext which is being used from the context
     * of this particular class
     *
     * @param configurationContextService configuration context service required to grab the current
     */
    public void unsetConfigurationContextService(
            ConfigurationContextService configurationContextService) {
        this.configurationContext = null;
    }

}
TOP

Related Classes of org.wso2.carbon.adminconsole.core.internal.AdminConsoleServiceComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.