Package org.wso2.carbon.billing.mgt.util

Source Code of org.wso2.carbon.billing.mgt.util.Util

/*
*  Copyright (c) 2005-2011, 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.billing.mgt.util;

import org.osgi.framework.BundleContext;
import org.wso2.carbon.billing.core.*;
import org.wso2.carbon.billing.core.DataAccessManager;
import org.wso2.carbon.billing.mgt.api.MultitenancyBillingInfo;
import org.wso2.carbon.billing.mgt.handlers.MultitenancySubscriptionFeedingHandler;
import org.wso2.carbon.common.constants.StratosConstants;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.usage.api.TenantUsageRetriever;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.tenant.TenantManager;

public class Util {
    private static BillingManager billingManager = null;
    private static DataAccessManager dataAccessManager=null;
    private static RegistryService registryService;
    private static RealmService realmService;
    private static TenantUsageRetriever tenantUsageRetriever;
    private static MultitenancyBillingInfo billingInfo;

    public static synchronized void setRegistryService(RegistryService service) {
        if (registryService == null) {
            registryService = service;
        }
    }

    public static synchronized void setRealmService(RealmService service) {
        if (realmService == null) {
            realmService = service;
        }
    }

    public static void setTenantUsageRetriever(TenantUsageRetriever tenantUsageRetriever) {
        Util.tenantUsageRetriever = tenantUsageRetriever;
    }

    public static RealmService getRealmService() {
        return realmService;
    }

    public static RegistryService getRegistryService() {
        return registryService;
    }

    public static TenantUsageRetriever getTenantUsageRetriever() {
        return tenantUsageRetriever;
    }

    public static TenantManager getTenantManager() {
        if (realmService == null) {
            return null;
        }
        return realmService.getTenantManager();
    }

    public static BillingManager getBillingManager() {
        return billingManager;
    }

    public static void setBillingManager(BillingManager billingManager) {
        Util.billingManager = billingManager;
    }

    public static void registerSubscriptionFeedingHandlers(BundleContext bundleContext) {
        bundleContext.registerService(BillingHandler.class.getName(),
                new MultitenancySubscriptionFeedingHandler(), null);
    }

    public static void scheduleBilling() throws BillingException {
        BillingEngine billingEngine =
                billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID);
        billingEngine.scheduleBilling();
    }

    public static void registerBillingInfo(BundleContext bundleContext) throws Exception {
        billingInfo = new MultitenancyBillingInfo();
        bundleContext.registerService(MultitenancyBillingInfo.class.getName(), billingInfo, null);
    }

    public static MultitenancyBillingInfo getMultitenancyBillingInfo() {
        return billingInfo;
    }

    public static DataAccessManager getDataAccessManager() {
        return dataAccessManager;
    }

    public static void setDataAccessManager(DataAccessManager dataAccessManager) {
        Util.dataAccessManager = dataAccessManager;
    }

    public static void initDataAccessManager(){
        DataAccessManager dataAccessManager = new DataAccessManager(
                billingManager.getBillingConfiguration().getDataSource());
        Util.dataAccessManager = dataAccessManager;
    }
}
TOP

Related Classes of org.wso2.carbon.billing.mgt.util.Util

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.