You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2013/06/28 21:27:13 UTC

[29/51] [partial] initial commit to apache incubator. Here just commit WSO2 Stratos code base as it is. After that will start re-factor code to apache

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java
new file mode 100644
index 0000000..a523b60
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingManager.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.conf.BillingConfiguration;
+import org.wso2.carbon.billing.core.conf.BillingTaskConfiguration;
+import org.wso2.carbon.billing.core.jdbc.DataAccessObject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A class to handle multiple billing engines
+ */
+public class BillingManager {
+    private static final Log log = LogFactory.getLog(BillingManager.class);
+    private static BillingManager billingManager;
+    private BillingConfiguration billingConfiguration;
+    private DataAccessObject dataAccessObject;
+    private Map<String, BillingEngine> billingEngines = new HashMap<String, BillingEngine>();
+
+    public static BillingManager getInstance() throws BillingException {
+        if (billingManager == null) {
+            String msg = "Billing Manager is not initialized.";
+            log.error(msg);
+            throw new BillingException(msg);
+        }
+        return billingManager;
+    }
+
+    public static void destroyInstance() {
+        billingManager = null;
+    }
+
+    public BillingManager(BillingConfiguration billingConfiguration) throws BillingException {
+        if (billingManager != null) {
+            String msg = "Billing Manager should not be initialized twice";
+            log.error(msg);
+            throw new BillingException(msg);
+        }
+        
+        this.billingConfiguration = billingConfiguration;
+        this.dataAccessObject = new DataAccessObject(billingConfiguration.getDataSource());
+        //Create billing engine corresponds to given billingTaskConfigurations
+        Map<String, BillingTaskConfiguration> billingTaskConfigs =
+                billingConfiguration.getBillingTaskConfigs();
+        for (Map.Entry<String, BillingTaskConfiguration> entry : billingTaskConfigs.entrySet()) {
+            String billingTaskName = entry.getKey();
+            BillingTaskConfiguration billingTaskConfiguration = entry.getValue();
+            BillingEngine billingEngine =
+                    new BillingEngine(billingTaskConfiguration, dataAccessObject);
+            billingEngines.put(billingTaskName, billingEngine);
+        }
+        billingManager = this;
+    }
+
+    public BillingConfiguration getBillingConfiguration() {
+        return billingConfiguration;
+    }
+
+    public DataAccessObject getDataAccessObject() {
+        return dataAccessObject;
+    }
+
+    public BillingEngine getBillingEngine(String billingTaskName) {
+        return billingEngines.get(billingTaskName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java
new file mode 100644
index 0000000..403938f
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/BillingTenantMgtListenerImpl.java
@@ -0,0 +1,203 @@
+/*
+ *  Copyright (c) 2005-2008, 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.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.dataobjects.Customer;
+import org.wso2.carbon.billing.core.dataobjects.Item;
+import org.wso2.carbon.billing.core.dataobjects.Subscription;
+import org.wso2.carbon.billing.core.internal.Util;
+import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
+import org.wso2.carbon.stratos.common.exception.StratosException;
+import org.wso2.carbon.stratos.common.internal.CloudCommonServiceComponent;
+import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
+import org.wso2.carbon.user.api.Tenant;
+import org.wso2.carbon.user.api.TenantManager;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+
+public class BillingTenantMgtListenerImpl implements TenantMgtListener{
+
+    private static Log log = LogFactory.getLog(BillingTenantMgtListenerImpl.class);
+    /**
+     * Adds the subscription entry when the tenant is created
+     * @param tenantInfo Tenant information
+     * @throws StratosException if adding subscription failed
+     */
+    public void onTenantCreate(TenantInfoBean tenantInfo) throws StratosException {
+        Customer customer = new Customer();
+        customer.setName(tenantInfo.getTenantDomain());
+        customer.setEmail(tenantInfo.getEmail());
+        customer.setStartedDate(new Date(tenantInfo.getCreatedDate().getTimeInMillis()));
+        customer.setFullName(tenantInfo.getFirstname() + " " + tenantInfo.getLastname());
+
+        customer.setId(tenantInfo.getTenantId());
+        Subscription subscription = new Subscription();
+        subscription.setCustomer(customer);
+        subscription.setActive(false);
+        subscription.setActiveSince(Calendar.getInstance().getTime());
+        subscription.setItem(new Item());
+        subscription.setSubscriptionPlan(tenantInfo.getUsagePlan());
+        try {
+            Util.getDataAccessManager().addSubscription(subscription);
+        } catch (Exception e) {
+            String msg = "Could not add new subscription for tenant: " +tenantInfo.getTenantDomain();
+            log.error( msg + e.getMessage(), e);
+            throw new StratosException(msg, e);
+        }
+    }
+
+    public void onTenantUpdate(TenantInfoBean tenantInfo) throws StratosException {
+        try {
+            if (tenantInfo.getUsagePlan() == null) {
+                return;
+            }
+            Subscription currentSubscription = Util.getDataAccessManager().
+                    getActiveSubscriptionOfCustomer(tenantInfo.getTenantId());
+            if (currentSubscription != null && currentSubscription.getSubscriptionPlan() != null) {
+                if (!currentSubscription.getSubscriptionPlan().equals(tenantInfo.getUsagePlan())) {
+                    boolean updated = Util.getDataAccessManager().
+                            changeSubscription(tenantInfo.getTenantId(), tenantInfo.getUsagePlan());
+                    if (updated) {
+                        log.info("Usage plan was changed successfully from " + currentSubscription.getSubscriptionPlan() +
+                                " to " + tenantInfo.getUsagePlan());
+                    }
+                }
+            }else{
+                //tenant does not have an active subscription. First we have to check whether the tenant
+                //is active. If he is active only we will add a new usage plan. Otherwise it is useless
+                //to add a usage plan to an inactive tenant
+                TenantManager tenantManager = CloudCommonServiceComponent.getTenantManager();
+                Tenant tenant = tenantManager.getTenant(tenantInfo.getTenantId());
+                if(tenant.isActive()){
+                    //we add a new subscription
+                    Subscription subscription = new Subscription();
+                    subscription.setActive(true);
+                    subscription.setSubscriptionPlan(tenantInfo.getUsagePlan());
+                    subscription.setActiveSince(null);
+                    subscription.setActiveUntil(null);
+                    Customer customer = new Customer();
+                    customer.setName(tenantInfo.getTenantDomain());
+                    customer.setId(tenantInfo.getTenantId());
+                    subscription.setCustomer(customer);
+
+                    int subsId = Util.getDataAccessManager().addSubscription(subscription);
+                    if(subsId>0){
+                        log.info("Added a new " + subscription.getSubscriptionPlan() + " usage plan for the tenant " +
+                                tenantInfo.getTenantDomain());
+                    }
+                }
+            }
+        } catch (Exception e) {
+            String msg = "Error occurred while changing the subscription plan for tenant: " + tenantInfo.getTenantDomain();
+            log.error(msg, e);
+            throw new StratosException(msg, e);
+        }
+    }
+
+    public void onTenantRename(int tenantId, String oldDomainName, String newDomainName) throws StratosException {
+        //Nothing to be done
+    }
+
+    public void onTenantInitialActivation(int tenantId) throws StratosException {
+        onTenantActivation(tenantId);
+    }
+
+    public void onTenantActivation(int tenantId) throws StratosException {
+        //On tenant activation we need to activate the subscription
+
+        try {
+
+            Subscription subscription = Util.getDataAccessManager().getActiveSubscriptionOfCustomer(tenantId);
+
+            if (subscription != null) {
+                String msg = "Unable to activate the subscription for tenant: " + tenantId +
+                        ". An active subscription already exists";
+                log.info(msg);
+            } else {
+                List<Subscription> inactiveSubscriptions = Util.getDataAccessManager().getInactiveSubscriptionsOfCustomer(tenantId);
+                if (inactiveSubscriptions.size() == 1) {
+                    //This is the scenario where the tenant has registered, but not activated yet
+                    subscription = inactiveSubscriptions.get(0);
+                    boolean activated = Util.getDataAccessManager().activateSubscription(subscription.getId());
+                    if (activated) {
+                        log.info("Subscription was activated for tenant: " + tenantId);
+                    }
+                }else if(inactiveSubscriptions.size() > 1){
+                    //this is the scenario where the tenant has been deactivated by admin and
+                    //again activated. Here, I am adding a new active subscription which is similar to the
+                    //last existed one
+                    //inactiveSubscriptions.get(0) gives the latest inactive subscription
+                    Subscription subscriptionToAdd = inactiveSubscriptions.get(0);
+                    subscriptionToAdd.setActive(true);
+                    subscriptionToAdd.setActiveSince(null);
+                    subscriptionToAdd.setActiveUntil(null);
+
+                    int subsId = Util.getDataAccessManager().addSubscription(subscriptionToAdd);
+                    if(subsId>0){
+                        log.info("New subscription: " + subscriptionToAdd.getSubscriptionPlan() +
+                                " added and it was activated for tenant: " + tenantId);
+                    }
+                }else{
+                    //this means there are no subscriptions. Lets handle this later
+                }
+            }
+        } catch (Exception e) {
+            String msg = "Error occurred while activating the subscription for tenant: " +
+                    tenantId;
+            log.error(msg, e);
+            throw new StratosException(msg, e);
+        }
+    }
+
+    public void onTenantDeactivation(int tenantId) throws StratosException {
+        try{
+            Subscription currentActiveSubscription = Util.getDataAccessManager().getActiveSubscriptionOfCustomer(tenantId);
+            if(currentActiveSubscription==null){
+                String msg = "There is no active subscription to deactivate for tenant: " +
+                        tenantId + " on tenant deactivation";
+                log.info(msg);
+            }else {
+                boolean deactivated = Util.getDataAccessManager().deactivateActiveSubscription(tenantId);
+                if(deactivated){
+                    log.info("Subscription deactivated on tenant deactivation");
+                }else{
+                    log.info("Subscription was not deactivated on tenant deactivation");
+                }
+            }
+        } catch (Exception e){
+            String msg = "Error occurred while deactivating the active subscription for tenant: " + tenantId;
+            log.error(msg, e);
+            throw new StratosException(msg, e);
+        }
+    }
+
+    public void onSubscriptionPlanChange(int tenentId, String oldPlan, String newPlan) throws StratosException {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public int getListenerOrder() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java
new file mode 100644
index 0000000..89cce4c
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/DataAccessManager.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.dataobjects.Customer;
+import org.wso2.carbon.billing.core.dataobjects.Subscription;
+import org.wso2.carbon.billing.core.internal.Util;
+import org.wso2.carbon.billing.core.jdbc.DataAccessObject;
+import org.wso2.carbon.stratos.common.exception.StratosException;
+import org.wso2.carbon.user.api.Tenant;
+import org.wso2.carbon.user.api.TenantManager;
+
+import javax.sql.DataSource;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class DataAccessManager {
+
+    private static Log log = LogFactory.getLog(DataAccessManager.class);
+    private DataAccessObject dataAccessObject = null;
+
+    public DataAccessManager(DataSource dataSource) {
+        this.dataAccessObject = new DataAccessObject(dataSource);
+    }
+    
+    public DataAccessManager(DataAccessObject dao){
+        this.dataAccessObject = dao;
+    }
+
+    public void beginTransaction() throws BillingException {
+        dataAccessObject.beginTransaction();
+    }
+
+    public void commitTransaction() throws BillingException {
+        dataAccessObject.commitTransaction();
+    }
+
+    public void rollbackTransaction() throws BillingException {
+        dataAccessObject.rollbackTransaction();
+    }
+
+    public int addSubscription(Subscription subscription) throws BillingException {
+        int subscriptionId = 0;
+        try {
+            beginTransaction();
+            subscriptionId = dataAccessObject.addSubscription(subscription,
+                                subscription.getSubscriptionPlan());
+            commitTransaction();
+        } catch(Exception e){
+            String msg = "Error occurred while adding subscription: " + subscription.getSubscriptionPlan()+
+                            " for the customer " + subscription.getCustomer().getName() + " " + e.getMessage() ;
+            log.error(msg, e);
+            rollbackTransaction();
+            throw new BillingException(msg, e);
+        }
+        return subscriptionId;
+    }
+
+    public void deleteBillingData(int tenantId) throws BillingException {
+        try {
+            beginTransaction();
+            dataAccessObject.deleteBillingData(tenantId);
+            commitTransaction();
+        } catch (Exception e) {
+            rollbackTransaction();
+            String msg = "Error occurred while deleting subscription for tenant id: " + tenantId ;
+            log.error(msg, e);
+            throw new BillingException(msg, e);
+        }
+    }
+
+    public List<Customer> getCustomersWithName(String customerName) throws BillingException {
+        TenantManager tenantManager = Util.getRealmService().getTenantManager();
+        List<Customer> customers = new ArrayList<Customer>();
+        try {
+            int tenantId = tenantManager.getTenantId(customerName);
+            Tenant tenant = tenantManager.getTenant(tenantId);
+            if (tenant != null) {
+                Customer customer = new Customer();
+                customer.setId(tenant.getId());
+                customer.setName(tenant.getDomain());
+                customer.setStartedDate(tenant.getCreatedDate());
+                customer.setEmail(tenant.getEmail());
+                //customer.setAddress();
+                customers.add(customer);
+            }
+        } catch (Exception e) {
+            String msg = "Failed to get customers for customers: " + customerName + ".";
+            log.error(msg, e);
+            throw new BillingException(msg, e);
+        }
+
+        return customers;
+    }
+
+    public Subscription getSubscription(int subscriptionId) throws BillingException {
+        Subscription subscription = null;
+        try {
+            beginTransaction();
+            subscription = dataAccessObject.getSubscription(subscriptionId);
+            commitTransaction();
+        } catch(Exception e){
+            String msg = "Error occurred while getting subscription with id: " + subscriptionId +
+                            " " + e.getMessage();
+            log.error(msg, e);
+            rollbackTransaction();
+            throw new BillingException(msg, e);
+        }
+        return subscription;
+    }
+
+    public Subscription getActiveSubscriptionOfCustomer(int customerId) throws BillingException {
+        Subscription subscription;
+        try {
+            beginTransaction();
+            subscription = dataAccessObject.getActiveSubscriptionOfCustomer(customerId);
+            commitTransaction();
+        } catch(Exception e){
+            String msg = "Error occurred while getting active subscription for customer: "
+                            + customerId + " " + e.getMessage();
+            log.error(msg, e);
+            rollbackTransaction();
+            throw new BillingException(msg, e);
+        }
+        return subscription;
+    }
+
+    public int getItemIdWithName(String name, int parentId) throws BillingException {
+        int itemId;
+        try {
+            beginTransaction();
+            itemId = dataAccessObject.getItemId(name, parentId);
+            commitTransaction();
+        } catch(Exception e){
+            String msg = "Error occurred while getting item id for item name: " + name +
+                            " " + e.getMessage();
+            log.error(msg, e);
+            rollbackTransaction();
+            throw new BillingException(msg, e);
+        }
+        return itemId;
+    }
+
+    public boolean changeSubscription(int customerId, String subscriptionPlan) throws BillingException {
+        boolean changed = false;
+        String oldSubscriptionPlan = null;
+
+        try {
+            beginTransaction();
+            Subscription oldSubscription = getActiveSubscriptionOfCustomer(customerId);
+            if(oldSubscription!=null){
+                oldSubscriptionPlan = oldSubscription.getSubscriptionPlan();
+            }
+            changed = dataAccessObject.changeSubscription(customerId, subscriptionPlan);
+            commitTransaction();
+        } catch(Exception e){
+            String msg = "Error occurred while changing subscription to: " + subscriptionPlan +
+                            " for customer: " + customerId + " " + e.getMessage();
+            log.error(msg, e);
+            rollbackTransaction();
+            throw new BillingException(msg, e);
+        }
+
+        try {
+            // Notify Listeners about the subscription change
+            Util.alertTenantSubscriptionPlanChange(
+                    customerId, oldSubscriptionPlan, subscriptionPlan);
+        } catch (StratosException e) {
+            log.error(e.getMessage(), e);
+            throw new BillingException(e.getMessage(), e);
+        }
+
+        return changed;
+    }
+
+    public List<Subscription> getInactiveSubscriptionsOfCustomer(int customerId) throws BillingException {
+        List<Subscription> subscriptions;
+        try {
+            beginTransaction();
+            subscriptions = dataAccessObject.getInactiveSubscriptionsOfCustomer(customerId);
+            commitTransaction();
+        } catch(Exception e){
+            String msg = "Error occurred while getting inactive subscriptions of customer: " +
+                            customerId + " " + e.getMessage();
+            log.error(msg, e);
+            rollbackTransaction();
+            throw new BillingException(msg, e);
+        }
+        return subscriptions;
+
+    }
+
+    public boolean activateSubscription(int subscriptionId) throws BillingException {
+        boolean activated = false;
+        try {
+            beginTransaction();
+            activated = dataAccessObject.activateSubscription(subscriptionId);
+            commitTransaction();
+        } catch(Exception e){
+            String msg = "Error occurred while activating subscription with id: " + subscriptionId +
+                            " " + e.getMessage();
+            log.error(msg, e);
+            rollbackTransaction();
+            throw new BillingException(msg, e);
+        }
+        return activated;
+    }
+
+    public boolean deactivateActiveSubscription(int tenantId) throws BillingException {
+        boolean deactivated = false;
+        try{
+            beginTransaction();
+            deactivated = dataAccessObject.deactivateCurrentSubscriptoin(tenantId);
+            commitTransaction();
+        }catch(Exception e){
+            rollbackTransaction();
+            String msg = "Error occurred while deactivating the active subscription of customer: " +
+                            tenantId;
+            log.error(msg, e);
+            throw new BillingException(msg, e);
+        }
+
+        return deactivated;
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java
new file mode 100644
index 0000000..04260fd
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/OutstandingBalanceInfoBean.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.beans;
+
+import java.util.Date;
+
+/**
+ * This class holds the data to be shown in the invoice summary page of all
+ * tenants
+ */
+public class OutstandingBalanceInfoBean {
+
+    private int invoiceId;
+    private String customerName;
+    private String subscription;
+    private String carriedForward;
+    private Date lastPaymentDate;
+    private Date lastInvoiceDate;
+    private String lastPaidAmount;
+
+    public int getInvoiceId() {
+        return invoiceId;
+    }
+
+    public void setInvoiceId(int invoiceId) {
+        this.invoiceId = invoiceId;
+    }
+
+    public String getCustomerName() {
+        return customerName;
+    }
+
+    public void setCustomerName(String customerName) {
+        this.customerName = customerName;
+    }
+
+    public String getSubscription() {
+        return subscription;
+    }
+
+    public void setSubscription(String subscription) {
+        this.subscription = subscription;
+    }
+
+    public String getCarriedForward() {
+        return carriedForward;
+    }
+
+    public void setCarriedForward(String carriedForward) {
+        this.carriedForward = carriedForward;
+    }
+
+    public Date getLastPaymentDate() {
+        return lastPaymentDate;
+    }
+
+    public void setLastPaymentDate(Date lastPaymentDate) {
+        this.lastPaymentDate = lastPaymentDate;
+    }
+
+    public String getLastPaidAmount() {
+        return lastPaidAmount;
+    }
+
+    public void setLastPaidAmount(String lastPaidAmount) {
+        this.lastPaidAmount = lastPaidAmount;
+    }
+
+    public Date getLastInvoiceDate() {
+        return lastInvoiceDate;
+    }
+
+    public void setLastInvoiceDate(Date lastInvoiceDate) {
+        this.lastInvoiceDate = lastInvoiceDate;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java
new file mode 100644
index 0000000..68e968e
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/beans/PaginatedBalanceInfoBean.java
@@ -0,0 +1,52 @@
+/*
+*  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.billing.core.beans;
+
+import org.wso2.carbon.utils.Pageable;
+
+import java.util.List;
+
+/**
+ * Class used paginating the invoice summaries of all tenants
+ */
+public class PaginatedBalanceInfoBean implements Pageable {
+
+    private OutstandingBalanceInfoBean[] balanceInfoBeans;
+    private int numberOfPages;
+
+    public OutstandingBalanceInfoBean[] getBalanceInfoBeans() {
+        return balanceInfoBeans;
+    }
+
+    public void setBalanceInfoBeans(OutstandingBalanceInfoBean[] balanceInfoBeans) {
+        this.balanceInfoBeans = balanceInfoBeans;
+    }
+
+    public int getNumberOfPages() {
+        return numberOfPages;
+    }
+
+    public void setNumberOfPages(int numberOfPages) {
+        this.numberOfPages = numberOfPages;
+    }
+
+    public <T> void set(List<T> items) {
+        this.balanceInfoBeans =
+                items.toArray(new OutstandingBalanceInfoBean[items.size()]);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingConfiguration.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingConfiguration.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingConfiguration.java
new file mode 100644
index 0000000..0027f16
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingConfiguration.java
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.conf;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.BillingConstants;
+import org.wso2.carbon.billing.core.BillingException;
+import org.wso2.carbon.billing.core.internal.Util;
+import org.wso2.carbon.ndatasource.common.DataSourceException;
+
+import javax.sql.DataSource;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * This class reads the billing-config.xml file and
+ * keeps the billing task configurations in a map.
+ * There are two configurations, one for scheduled bill generation
+ * and the other for on-demand bill generation
+ */
+public class BillingConfiguration {
+    private static final Log log = LogFactory.getLog(BillingConfiguration.class);
+    DataSource dataSource;
+    Map<String, BillingTaskConfiguration> billingTaskConfigs = new HashMap<String, BillingTaskConfiguration>();
+
+    public BillingConfiguration(String billingConfigFile) throws BillingException {
+        try {
+            dataSource = (DataSource) Util.getDataSourceService().getDataSource(BillingConstants.WSO2_BILLING_DS).getDSObject();
+            OMElement billingConfig = buildOMElement(new FileInputStream(billingConfigFile));
+            deserialize(billingConfig);
+        } catch (FileNotFoundException e) {
+            String msg = "Unable to find the file responsible for billing task configs: "
+                            + billingConfigFile;
+            log.error(msg, e);
+            throw new BillingException(msg, e);
+        } catch (DataSourceException e) {
+            String msg = "Error retrieving Billing datasource from master-datasources.xml configuration.";
+            log.error(msg, e);
+            throw new BillingException(msg, e);
+        }
+    }
+
+    private OMElement buildOMElement(InputStream inputStream) throws BillingException {
+        XMLStreamReader parser;
+        try {
+            parser = XMLInputFactory.newInstance().createXMLStreamReader(inputStream);
+        } catch (XMLStreamException e) {
+            String msg = "Error in initializing the parser to build the OMElement.";
+            log.error(msg, e);
+            throw new BillingException(msg, e);
+        }
+
+        StAXOMBuilder builder = new StAXOMBuilder(parser);
+        return builder.getDocumentElement();
+    }
+    
+    /*
+       Deserialize the following
+       <billingConfig xmlns="http://wso2.com/carbon/multitenancy/billing/config">
+           <dbConfig>
+                ...
+           </dbConfig>
+           <tasks>
+                <task id="multitenancyScheduledTask">
+                    ...
+                </task>
+                <task id="multitenancyViewingTask">
+                    ...
+                </task>
+            </tasks>
+        </billingConfig>
+     */
+    private void deserialize(OMElement billingConfigEle) throws BillingException {
+        Iterator billingConfigChildIt = billingConfigEle.getChildElements();
+        
+        while (billingConfigChildIt.hasNext()) {
+            OMElement billingConfigChildEle = (OMElement) billingConfigChildIt.next();
+            
+            if (new QName(BillingConstants.CONFIG_NS, BillingConstants.TASKS,
+                    BillingConstants.NS_PREFIX).equals(billingConfigChildEle.getQName())) {
+                //element is "tasks"
+                Iterator taskConfigChildIt = billingConfigChildEle.getChildElements();
+                while (taskConfigChildIt.hasNext()) {
+                    OMElement taskConfigEle = (OMElement) taskConfigChildIt.next();
+                    String id = taskConfigEle.getAttributeValue(new QName(BillingConstants.ATTR_ID));
+                    BillingTaskConfiguration taskConfig =
+                            new BillingTaskConfiguration(id, taskConfigEle);
+                    billingTaskConfigs.put(id, taskConfig);
+                }
+            } else {
+                String msg = "Unknown element in Billing Configuration: " +
+                                billingConfigChildEle.getQName().getLocalPart();
+                log.error(msg);
+                throw new BillingException(msg);
+            }
+        }
+    }
+
+    /*
+     * Deserialise dbConfigElement (Given below) and initialize data source
+        <dbConfig>
+            <url>jdbc:mysql://localhost:3306/billing</url>
+            <userName>billing</userName>
+            <password>billing</password>
+            <driverName>com.mysql.jdbc.Driver</driverName>
+            <maxActive>80</maxActive>
+            <maxWait>60000</maxWait>
+            <minIdle>5</minIdle>
+            <validationQuery>SELECT 1</validationQuery>
+        </dbConfig>
+     */
+    /*private void initDataSource(OMElement dbConfigEle) throws BillingException {
+        // initializing the data source and load the database configurations
+        Iterator dbConfigChildIt = dbConfigEle.getChildElements();
+        dataSource = new BasicDataSource();
+        
+        while (dbConfigChildIt.hasNext()) {
+            
+            OMElement dbConfigChildEle = (OMElement) dbConfigChildIt.next();
+            if (new QName(BillingConstants.CONFIG_NS, BillingConstants.DBCONFIG_URL,
+                    BillingConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+                dataSource.setUrl(dbConfigChildEle.getText());
+            } else if (new QName(BillingConstants.CONFIG_NS, BillingConstants.DBCONFIG_USER_NAME,
+                    BillingConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+                dataSource.setUsername(dbConfigChildEle.getText());
+            } else if (new QName(BillingConstants.CONFIG_NS, BillingConstants.DBCONFIG_PASSWORD,
+                    BillingConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+                dataSource.setPassword(dbConfigChildEle.getText());
+            } else if (new QName(BillingConstants.CONFIG_NS, BillingConstants.DBCONFIG_DRIVER_NAME,
+                    BillingConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+                dataSource.setDriverClassName(dbConfigChildEle.getText());
+            } else if (new QName(BillingConstants.CONFIG_NS, BillingConstants.DBCONFIG_MAX_ACTIVE,
+                    BillingConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+                dataSource.setMaxActive(Integer.parseInt(dbConfigChildEle.getText()));
+            } else if (new QName(BillingConstants.CONFIG_NS, BillingConstants.DBCONFIG_MAX_WAIT,
+                    BillingConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+                dataSource.setMaxWait(Integer.parseInt(dbConfigChildEle.getText()));
+            } else if (new QName(BillingConstants.CONFIG_NS, BillingConstants.DBCONFIG_MIN_IDLE,
+                    BillingConstants.NS_PREFIX).equals(dbConfigChildEle.getQName())) {
+                dataSource.setMinIdle(Integer.parseInt(dbConfigChildEle.getText()));
+            } else if (new QName(BillingConstants.CONFIG_NS, 
+                    BillingConstants.DBCONFIG_VALIDATION_QUERY, BillingConstants.NS_PREFIX)
+                    .equals(dbConfigChildEle.getQName())) {
+                dataSource.setValidationQuery(dbConfigChildEle.getText());
+            } else {
+                String msg = "Unknown element in DBConfig of Billing Configuration: " +
+                                dbConfigChildEle.getQName().getLocalPart();
+                log.error(msg);
+                throw new BillingException(msg);
+            }
+        }
+    }*/
+
+    public Map<String, BillingTaskConfiguration> getBillingTaskConfigs() {
+        return billingTaskConfigs;
+    }
+
+    public DataSource getDataSource() {
+        return dataSource;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingTaskConfiguration.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingTaskConfiguration.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingTaskConfiguration.java
new file mode 100644
index 0000000..5530ed1
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/conf/BillingTaskConfiguration.java
@@ -0,0 +1,251 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.conf;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.billing.core.BillingConstants;
+import org.wso2.carbon.billing.core.BillingException;
+import org.wso2.carbon.billing.core.BillingHandler;
+import org.wso2.carbon.billing.core.scheduler.ScheduleHelper;
+
+import javax.xml.namespace.QName;
+import java.util.*;
+
+public class BillingTaskConfiguration {
+    private static final Log log = LogFactory.getLog(BillingTaskConfiguration.class);
+
+    private String id;
+    private ScheduleHelper scheduleHelper = null;
+    private Map<String, String> schedulerHelperArgs;
+    private String schedulerServiceName;
+
+    private List<BillingHandler> billingHandlers = new ArrayList<BillingHandler>();
+    private List<HandlerConfigBean> handlerArgs = new ArrayList<HandlerConfigBean>(); //key - handler service name
+    private static Map<String, ScheduleHelper> schedulerServices =
+            new HashMap<String, ScheduleHelper>(); 
+    private static Map<String, BillingHandler> handlerServices =
+            new HashMap<String, BillingHandler>();
+
+    private class HandlerConfigBean {
+        public String name;
+        public boolean isServiceType;
+        public Map<String, String> constructorArgs;
+
+        public HandlerConfigBean(String name, boolean isServiceType, Map<String, String> constructorArgs){
+            this.name = name;
+            this.isServiceType = isServiceType;
+            this.constructorArgs = constructorArgs;
+        }
+    }
+
+    public BillingTaskConfiguration(String id, OMElement billingConfigEle) throws BillingException {
+        this.id = id;
+        deserialize(billingConfigEle);
+    }
+
+    /*
+     *  Deserialize following and creates tasks
+        <task id="multitenancyScheduledTask">
+            <subscriptionFilter>multitenancy</subscriptionFilter>
+            <schedule scheduleHelperClass="package.ClassName">
+                ...
+            </schedule>
+            <handlers>
+                ...
+            </handlers>
+        </task>
+     */
+    private void deserialize(OMElement taskConfigEle) throws BillingException {
+        Iterator billingConfigChildIt = taskConfigEle.getChildElements();
+        
+        while (billingConfigChildIt.hasNext()) {
+            OMElement childEle = (OMElement) billingConfigChildIt.next();
+            if (new QName(BillingConstants.CONFIG_NS, BillingConstants.SCHEDULE_CONF_KEY,
+                    BillingConstants.NS_PREFIX).equals(childEle.getQName())) {
+                deserializeSchedule(childEle);
+            } else if (new QName(BillingConstants.CONFIG_NS, BillingConstants.HANDLERS,
+                    BillingConstants.NS_PREFIX).equals(childEle.getQName())) {
+                deserializeHandlers(childEle);
+            } else {
+                String msg = "Unknown element in task configuration for task " + id +
+                                ": " + childEle.getQName().getLocalPart();
+                log.error(msg);
+                throw new BillingException(msg);
+            }
+        }
+    }
+
+    /*
+        <handlers>
+            <handler service="serviceName">
+            </handler>
+            <handler class="org.wso2.carbon.billing.core.handlers.EmailSendingHandler">
+                <parameter name="file">email-billing-notifications.xml</parameter>
+            </handler>
+        </handlers>
+     */
+    private void deserializeHandlers(OMElement handlersEle) throws BillingException {
+        // iterate through each billingHandlers
+        Iterator handlersChildIt = handlersEle.getChildElements();
+        
+        while (handlersChildIt.hasNext()) {
+            OMElement handlerEle = (OMElement) handlersChildIt.next();
+            if (!(new QName(BillingConstants.CONFIG_NS, BillingConstants.HANDLER,
+                    BillingConstants.NS_PREFIX).equals(handlerEle.getQName()))) {
+                String msg = "Unknown element in handler configuration for task " + id +
+                                ": " + handlerEle.getQName().getLocalPart();
+                log.error(msg);
+                throw new BillingException(msg);
+            }
+
+            // get the parameters for handler
+            Iterator handlerParametersIt = handlerEle.getChildElements();
+            Map<String, String> constructorArgs = extractConstructorArgs(handlerParametersIt);
+            String handlerClassName =
+                    handlerEle.getAttributeValue(new QName(BillingConstants.HANDLER_CLASS_ATTR));
+            if (handlerClassName == null) {
+                // className is not given. So, it uses a handlerService
+                String handlerServiceName = handlerEle.getAttributeValue(
+                        new QName(BillingConstants.HANDLER_SERVICE_ATTR));
+                HandlerConfigBean bean = new HandlerConfigBean(handlerServiceName, true, constructorArgs);
+                handlerArgs.add(bean);
+            } else {
+                HandlerConfigBean bean = new HandlerConfigBean(handlerClassName, false, constructorArgs);
+                handlerArgs.add(bean);
+            }
+        }
+    }
+
+    /* 
+     * Deserialize following and creates scheduleHelper
+        <schedule scheduleHelperClass="package.ClassName">
+            <parameter name="dayToTriggerOn">1</parameter>
+            <parameter name="hourToTriggerOn">0</parameter>
+            <parameter name="timeZone">GMT-8:00</parameter>
+        </schedule>
+     */
+    private void deserializeSchedule(OMElement scheduleEle) throws BillingException {
+        Iterator scheduleHelperConfigChildIt = scheduleEle.getChildElements();
+        Map<String, String> constructorArgs = extractConstructorArgs(scheduleHelperConfigChildIt);
+        
+        // get the scheduleHelper class name
+        String className = scheduleEle.getAttributeValue(
+                new QName(BillingConstants.TRIGGER_CALCULATOR_CLASS_ATTR));
+        
+        if (className == null) {
+            //className is not given; it is using scheduler service
+            schedulerServiceName = scheduleEle.getAttributeValue(
+                    new QName(BillingConstants.TRIGGER_CALCULATOR_SERVICE_ATTR));
+            schedulerHelperArgs = constructorArgs;
+        } else {
+            //className is given; Construct the object
+            scheduleHelper = (ScheduleHelper) constructObject(className);
+            scheduleHelper.init(constructorArgs);
+        }
+    }
+
+    public ScheduleHelper getScheduleHelper() throws BillingException {
+        if (scheduleHelper == null && schedulerServiceName != null) {
+            scheduleHelper = schedulerServices.get(schedulerServiceName);
+            if (scheduleHelper == null) {
+                String msg = "The scheduler helper service: " + schedulerServiceName +
+                                " is not loaded.";
+                log.error(msg);
+                throw new BillingException(msg);
+            }
+            scheduleHelper.init(schedulerHelperArgs);
+        }
+        return scheduleHelper;
+    }
+
+    public List<BillingHandler> getBillingHandlers() throws BillingException {
+        // We have to combine the handlers and handlerServices as a single list and return. When
+        // creating and initializing handerServices, remove them from the handelerArgs so that they
+        // will be included only once
+        if(!handlerArgs.isEmpty()){
+            for(HandlerConfigBean bean : handlerArgs){
+                if(bean.isServiceType){
+                    BillingHandler handlerService = handlerServices.get(bean.name);
+                    if (handlerService == null) {
+                        billingHandlers = null;
+                        String msg = "The handler service: " + bean.name + " is not loaded.";
+                        log.error(msg);
+                        throw new BillingException(msg);
+                    }
+                    handlerService.init(bean.constructorArgs);
+                    billingHandlers.add(handlerService);
+
+                } else {
+                    BillingHandler handler = (BillingHandler) constructObject(bean.name);
+                    handler.init(bean.constructorArgs);
+                    billingHandlers.add(handler);
+                }
+            }
+
+            //all the billing handler services are initialized properly, can clear handlerArgs
+            handlerArgs.clear();
+        }
+        return billingHandlers;
+    }
+
+    private static Object constructObject(String className) throws BillingException {
+        try {
+            return Class.forName(className).newInstance();
+        } catch (ClassNotFoundException e) {
+            String msg = "The class: " + className + " is not in the classpath.";
+            log.error(msg, e);
+            throw new BillingException(msg, e);
+        } catch (Exception e) {
+            String msg = "Error in initializing the object for " + className + ".";
+            log.error(msg);
+            throw new BillingException(msg, e);
+        }
+    }
+
+    private static Map<String, String> extractConstructorArgs(Iterator parameterIt) {
+        Map<String, String> constructorArgs = new HashMap<String, String>();
+        
+        while (parameterIt.hasNext()) {
+            OMElement paramEle = (OMElement) parameterIt.next();
+            if (!new QName(BillingConstants.CONFIG_NS, BillingConstants.SCHEDULE_CONF_PARAM_KEY,
+                    BillingConstants.NS_PREFIX).equals(paramEle.getQName())) {
+                continue;
+            }
+            
+            String paramName = paramEle.getAttributeValue(
+                    new QName(BillingConstants.SCHEDULE_CONF_PARAM_NAME_KEY));
+            String paramValue = paramEle.getText();
+            constructorArgs.put(paramName, paramValue);
+        }
+        return constructorArgs;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    // the following two methods will be called when the services are available for the schedule
+    // helper and the billing handlers
+    public static void addScheduleHelper(ScheduleHelper scheduleHelper) {
+        schedulerServices.put(scheduleHelper.getClass().getName(), scheduleHelper);
+    }
+
+    public static void addBillingHandler(BillingHandler billingHandler) {
+        handlerServices.put(billingHandler.getClass().getName(), billingHandler);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Cash.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Cash.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Cash.java
new file mode 100644
index 0000000..e9d760a
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Cash.java
@@ -0,0 +1,304 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.dataobjects;
+
+import org.wso2.carbon.billing.core.BillingException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.regex.Pattern;
+
+
+public class Cash {
+    private static final Log log = LogFactory.getLog(Cash.class);
+    public static final String CURRENCY_USD = "$";
+    public static final String DEFAULT_CURRENCY = CURRENCY_USD;
+
+    public enum Sign {
+        POSITIVE, NEGATIVE
+    };
+
+    String currency;
+    int wholeNumber;
+    int decimalNumber;
+    Sign sign = Sign.POSITIVE; // true for positive
+
+    private static final String notNumbersRegEx = "[^0-9]";
+    private static final Pattern notNumbersPattern = Pattern.compile(notNumbersRegEx);
+
+    public Cash() {
+        // the default constructor for Cash
+    }
+
+    public Cash(Cash copyFrom) {
+        this.currency = copyFrom.getCurrency();
+        this.wholeNumber = copyFrom.getWholeNumber();
+        this.decimalNumber = copyFrom.getDecimalNumber();
+        this.sign = copyFrom.getSign();
+    }
+
+    public Cash(String cashString) throws BillingException {
+        if (cashString == null) {
+            cashString = "$0";
+        }
+        if (cashString.startsWith(CURRENCY_USD)) {
+            cashString = cashString.substring(CURRENCY_USD.length());
+            currency = CURRENCY_USD;
+        }
+        // possible other currencies
+        else {
+            currency = DEFAULT_CURRENCY;
+        }
+
+        if (cashString.startsWith("-")) {
+            sign = Sign.NEGATIVE;
+            cashString = cashString.substring(1);
+        } else if (cashString.startsWith("+")) {
+            sign = Sign.POSITIVE;
+            cashString = cashString.substring(1);
+        } else {
+            sign = Sign.POSITIVE;
+        }
+
+        if (cashString.contains(".")) {
+            String wholeNumberStr = cashString.substring(0, cashString.indexOf("."));
+            if (wholeNumberStr.trim().equals("")) {
+                String msg = "Whole number can not be empty";
+                throw new BillingException(msg);
+            }
+            if (notNumbersPattern.matcher(wholeNumberStr).find()) {
+                String msg = "The whole number expected to have only 0-9 characters.: " +
+                                wholeNumberStr + " is not a number. ";
+                throw new BillingException(msg);
+            }
+            
+            String decimalNumberStr = cashString.substring(cashString.indexOf(".") + 1);
+            if (notNumbersPattern.matcher(decimalNumberStr).find()) {
+                String msg = "The decimal number expected to have only 0-9 characters.: " +
+                                decimalNumberStr + " is not a number. ";
+                throw new BillingException(msg);
+            }
+            if (decimalNumberStr.length() == 0) {
+                String msg = "String after the decimal point is zero.";
+                throw new BillingException(msg);
+            } else if (decimalNumberStr.length() > 2) {
+                String msg = "String after the decimal point is greater than 2";
+                throw new BillingException(msg);
+            } else if (decimalNumberStr.length() == 1) {
+                decimalNumberStr += "0";
+            }
+            
+            wholeNumber = Integer.parseInt(wholeNumberStr);
+            decimalNumber = Integer.parseInt(decimalNumberStr);
+            
+        } else {
+            if (notNumbersPattern.matcher(cashString).find()) {
+                String msg = "The cash string to have only 0-9 characters.: " + cashString +
+                                " is not a number. ";
+                throw new BillingException(msg);
+            }
+            
+            wholeNumber = Integer.parseInt(cashString);
+            decimalNumber = 0;
+        }
+    }
+
+    public Sign getSign() {
+        return sign;
+    }
+
+    public void setSign(Sign sign) {
+        this.sign = sign;
+    }
+
+    public String getCurrency() {
+        return currency;
+    }
+
+    public void setCurrency(String currency) {
+        this.currency = currency;
+    }
+
+    public int getWholeNumber() {
+        return wholeNumber;
+    }
+
+    public void setWholeNumber(int wholeNumber) {
+        this.wholeNumber = wholeNumber;
+    }
+
+    public int getDecimalNumber() {
+        return decimalNumber;
+    }
+
+    public void setDecimalNumber(int decimalNumber) {
+        this.decimalNumber = decimalNumber;
+    }
+
+    public String serializeToString() {
+        String str = currency;
+        if (sign == Sign.NEGATIVE) {
+            str += "-";
+        }
+        str += wholeNumber + ".";
+        if (decimalNumber < 10) {
+            str += "0" + decimalNumber;
+        } else {
+            str += decimalNumber;
+        }
+        return str;
+    }
+
+    @Override
+    public String toString() {
+        return serializeToString();
+    }
+
+    public static Cash add(Cash a, Cash b) throws BillingException {
+        if (!a.getCurrency().equals(b.getCurrency())) {
+            // we still not support this.
+            String msg = "Can not add in-similar currencies: " + a.getCurrency() + "!=" +
+                            b.getCurrency() + ".";
+            log.error(msg);
+            throw new BillingException(msg);
+        }
+        
+        if (a.getSign() == Sign.POSITIVE && b.getSign() == Sign.NEGATIVE) {
+            Cash b2 = new Cash(b);
+            b2.setSign(Sign.POSITIVE);
+            return subtract(a, b2);
+        }
+        
+        if (a.getSign() == Sign.NEGATIVE && b.getSign() == Sign.POSITIVE) {
+            Cash a2 = new Cash(a);
+            a2.setSign(Sign.POSITIVE);
+            return subtract(b, a2);
+        }
+        
+        if (a.getSign() == Sign.NEGATIVE && b.getSign() == Sign.NEGATIVE) {
+            Cash a2 = new Cash(a);
+            Cash b2 = new Cash(b);
+            a2.setSign(Sign.POSITIVE);
+            b2.setSign(Sign.POSITIVE);
+            Cash c2 = add(a2, b2);
+            c2.setSign(Sign.NEGATIVE);
+            return c2;
+        }
+        
+        int decimalSum = a.getDecimalNumber() + b.getDecimalNumber();
+        int wholeSum = a.getWholeNumber() + b.getWholeNumber();
+
+        Cash cash = new Cash();
+        cash.setCurrency(a.getCurrency());
+        if (decimalSum >= 100) {
+            decimalSum -= 100;
+            wholeSum += 1;
+        }
+        cash.setDecimalNumber(decimalSum);
+        cash.setWholeNumber(wholeSum);
+        cash.setSign(Sign.POSITIVE);
+        return cash;
+    }
+
+    public static Cash subtract(Cash a, Cash b) throws BillingException {
+        if (!a.getCurrency().equals(b.getCurrency())) {
+            // we still not support this.
+            String msg = "Can not add in-similar currencies: " + a.getCurrency() + "!=" +
+                            b.getCurrency() + ".";
+            log.error(msg);
+            throw new BillingException(msg);
+        }
+        
+        if (a.getSign() == Sign.POSITIVE && b.getSign() == Sign.NEGATIVE) {
+            Cash b2 = new Cash(b);
+            b2.setSign(Sign.POSITIVE);
+            return add(a, b2);
+        }
+        
+        if (a.getSign() == Sign.NEGATIVE && b.getSign() == Sign.POSITIVE) {
+            Cash a2 = new Cash(a);
+            a2.setSign(Sign.POSITIVE);
+            Cash c2 = add(b, a2);
+            c2.setSign(Sign.NEGATIVE);
+            return c2;
+        }
+        
+        if (a.getSign() == Sign.NEGATIVE && b.getSign() == Sign.NEGATIVE) {
+            Cash a2 = new Cash(a);
+            Cash b2 = new Cash(b);
+            a2.setSign(Sign.POSITIVE);
+            b2.setSign(Sign.POSITIVE);
+            Cash c2 = subtract(a2, b2);
+            if (c2.getSign() == Sign.NEGATIVE) {
+                c2.setSign(Sign.POSITIVE);
+            } else {
+                c2.setSign(Sign.NEGATIVE);
+            }
+            return c2;
+        }
+        
+        int decimalSum = a.getDecimalNumber() - b.getDecimalNumber();
+        int wholeSum = a.getWholeNumber() - b.getWholeNumber();
+
+        if (wholeSum < 0 || (decimalSum < 0 && wholeSum == 0)) {
+            // then it is negative value
+            Cash c = subtract(b, a);
+            c.setSign(Sign.NEGATIVE);
+            return c;
+        }
+
+        Cash cash = new Cash();
+        cash.setCurrency(a.getCurrency());
+        if (decimalSum < 0) {
+            decimalSum += 100;
+            wholeSum -= 1;
+        }
+
+        cash.setDecimalNumber(decimalSum);
+        cash.setWholeNumber(wholeSum);
+        return cash;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (!(o instanceof Cash)) {
+            return false;
+        }
+        Cash otherCash = (Cash) o;
+        return otherCash.serializeToString().equals(this.serializeToString());
+    }
+
+    @Override
+    public int hashCode() {
+        return serializeToString().hashCode();
+    }
+
+    public Cash multiply(double multiplyBy) {
+        long answerInCent = (long) (wholeNumber * 100 * multiplyBy + decimalNumber * multiplyBy);
+        int newWholeNumber = (int) (answerInCent / 100);
+        int newDecimalNumber = (int) (answerInCent % 100);
+
+        Cash cash = new Cash();
+        cash.setCurrency(this.getCurrency());
+        if (newWholeNumber < 0) {
+            cash.setSign(Sign.NEGATIVE);
+        }
+        cash.setWholeNumber(newWholeNumber);
+        cash.setDecimalNumber(newDecimalNumber);
+        return cash;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Customer.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Customer.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Customer.java
new file mode 100644
index 0000000..e12d5d2
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Customer.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.dataobjects;
+
+import java.util.Date;
+
+/**
+ * Customer class - This holds the information of tenants
+ * i.e. customer=tenant
+ */
+public class Customer {
+    private int id;
+    private String name;
+    private String context;
+    private String fullName;
+    private String email;
+    private Date startedDate;
+    private String address;
+    private Invoice activeInvoice;
+    private long totalBandwidth;
+    private long totalStorage;
+    private long totalCartridgeCPUHours;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getFullName() {
+        return fullName;
+    }
+
+    public void setFullName(String fullName) {
+        this.fullName = fullName;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getContext() {
+        return context;
+    }
+
+    public void setContext(String context) {
+        this.context = context;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public Date getStartedDate() {
+        return new Date(startedDate.getTime());
+    }
+
+    public void setStartedDate(Date startedDate) {
+        this.startedDate = new Date(startedDate.getTime());
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    /**
+     * This will be used by rules to retrieve the active invoice
+     *
+     * @return
+     */
+    public final Invoice getActiveInvoice() {
+        return activeInvoice;
+    }
+
+    public final void setActiveInvoice(Invoice invoice) {
+        this.activeInvoice = invoice;
+    }
+
+    public long getTotalBandwidth() {
+        return totalBandwidth;
+    }
+
+    public void setTotalBandwidth(long totalBandwidth) {
+        this.totalBandwidth = totalBandwidth;
+    }
+
+    public long getTotalStorage() {
+        return totalStorage;
+    }
+
+    public void setTotalStorage(long totalStorage) {
+        this.totalStorage = totalStorage;
+    }
+
+    public long getTotalCartridgeCPUHours() {
+        return totalCartridgeCPUHours;
+    }
+
+    public void setTotalCartridgeCPUHours(long totalCartridgeCPUHours) {
+        this.totalCartridgeCPUHours = totalCartridgeCPUHours;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        Customer customer = (Customer) o;
+
+        if (id != customer.id) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Discount.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Discount.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Discount.java
new file mode 100644
index 0000000..862b1fd
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Discount.java
@@ -0,0 +1,88 @@
+/*
+*  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.billing.core.dataobjects;
+
+
+import java.util.Date;
+
+public class Discount {
+    
+    private int id;
+    private int tenantId;
+    private float percentage;
+    private float amount;
+    private Date startDate;
+    private Date endDate;
+    private boolean isPercentageType;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(int tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    public float getPercentage() {
+        return percentage;
+    }
+
+    public void setPercentage(float percentage) {
+        this.percentage = percentage;
+    }
+
+    public float getAmount() {
+        return amount;
+    }
+
+    public void setAmount(float amount) {
+        this.amount = amount;
+    }
+
+    public Date getStartDate() {
+        return startDate;
+    }
+
+    public void setStartDate(Date startDate) {
+        this.startDate = startDate;
+    }
+
+    public Date getEndDate() {
+        return endDate;
+    }
+
+    public void setEndDate(Date endDate) {
+        this.endDate = endDate;
+    }
+
+    public boolean isPercentageType() {
+        return isPercentageType;
+    }
+
+    public void setPercentageType(boolean percentageType) {
+        isPercentageType = percentageType;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Invoice.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Invoice.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Invoice.java
new file mode 100644
index 0000000..697ae77
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Invoice.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.dataobjects;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Invoice class - holds the invoice information
+ */
+public class Invoice {
+    int id;
+    Date date;
+    Date startDate;
+    Date endDate;
+    Cash boughtForward;
+    Cash carriedForward;
+    Cash totalCost;
+    Cash totalPayment;
+    Customer customer;
+    List<Subscription> subscriptions = new ArrayList<Subscription>();
+    List<Payment> payments = new ArrayList<Payment>();
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Date getDate() {
+        return new Date(date.getTime());
+    }
+
+    public void setDate(Date date) {
+        this.date = new Date(date.getTime());
+    }
+
+    public Date getStartDate() {
+        return new Date(startDate.getTime());
+    }
+
+    public void setStartDate(Date startDate) {
+        this.startDate = new Date(startDate.getTime());
+    }
+
+    public Date getEndDate() {
+        return new Date(endDate.getTime());
+    }
+
+    public void setEndDate(Date endDate) {
+        this.endDate = new Date(endDate.getTime());
+    }
+
+    public Cash getBoughtForward() {
+        return boughtForward;
+    }
+
+    public void setBoughtForward(Cash boughtForward) {
+        this.boughtForward = boughtForward;
+    }
+
+    public Cash getCarriedForward() {
+        return carriedForward;
+    }
+
+    public void setCarriedForward(Cash carriedForward) {
+        this.carriedForward = carriedForward;
+    }
+
+    public Cash getTotalCost() {
+        return totalCost;
+    }
+
+    public void setTotalCost(Cash totalCost) {
+        this.totalCost = totalCost;
+    }
+
+    public Cash getTotalPayment() {
+        return totalPayment;
+    }
+
+    public void setTotalPayment(Cash totalPayment) {
+        this.totalPayment = totalPayment;
+    }
+
+    public Customer getCustomer() {
+        return customer;
+    }
+
+    public void setCustomer(Customer customer) {
+        this.customer = customer;
+    }
+
+    public List<Subscription> getSubscriptions() {
+        return subscriptions;
+    }
+
+    public void setSubscriptions(List<Subscription> subscriptions) {
+        this.subscriptions = subscriptions;
+    }
+
+    public List<Payment> getPayments() {
+        return payments;
+    }
+
+    public void setPayments(List<Payment> payments) {
+        this.payments = payments;
+    }
+
+    public void addPayment(Payment payment) {
+        this.payments.add(payment);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Item.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Item.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Item.java
new file mode 100644
index 0000000..8c92238
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Item.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.dataobjects;
+
+import java.util.List;
+
+public class Item {
+    private int id;
+    private String name;
+    private Cash cost;
+    private Cash creditLimit; //this is the credit limit defined by the billing rules
+    private int bandwidthLimit;
+    private Cash bandwidthOveruseCharge;
+    private int resourceVolumeLimit;
+    private Cash resourceVolumeOveruseCharge;
+    private int cartridgeCPUHourLimit;
+    private Cash cartridgeCPUOveruseCharge;
+    private String description;
+    private Item parent;
+    private List<? extends Item> children;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Cash getCost() {
+        return cost;
+    }
+
+    public void setCost(Cash cost) {
+        this.cost = cost;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public Item getParent() {
+        return parent;
+    }
+
+    public void setParent(Item parent) {
+        this.parent = parent;
+    }
+
+    public List<? extends Item> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<? extends Item> children) {
+        this.children = children;
+    }
+
+    public Cash getCreditLimit() {
+        return creditLimit;
+    }
+
+    public void setCreditLimit(Cash creditLimit) {
+        this.creditLimit = creditLimit;
+    }
+
+    public int getBandwidthLimit() {
+        return bandwidthLimit;
+    }
+
+    public void setBandwidthLimit(int bandwidthLimit) {
+        this.bandwidthLimit = bandwidthLimit;
+    }
+
+    public Cash getBandwidthOveruseCharge() {
+        return bandwidthOveruseCharge;
+    }
+
+    public void setBandwidthOveruseCharge(Cash bandwidthOveruseCharge) {
+        this.bandwidthOveruseCharge = bandwidthOveruseCharge;
+    }
+
+    public int getResourceVolumeLimit() {
+        return resourceVolumeLimit;
+    }
+
+    public void setResourceVolumeLimit(int resourceVolumeLimit) {
+        this.resourceVolumeLimit = resourceVolumeLimit;
+    }
+
+    public Cash getResourceVolumeOveruseCharge() {
+        return resourceVolumeOveruseCharge;
+    }
+
+    public void setResourceVolumeOveruseCharge(Cash resourceVolumeOveruseCharge) {
+        this.resourceVolumeOveruseCharge = resourceVolumeOveruseCharge;
+    }
+
+    public int getCartridgeCPUHourLimit() {
+        return cartridgeCPUHourLimit;
+    }
+
+    public void setCartridgeCPUHourLimit(int cartridgeCPUHourLimit) {
+        this.cartridgeCPUHourLimit = cartridgeCPUHourLimit;
+    }
+
+    public Cash getCartridgeCPUOveruseCharge() {
+        return cartridgeCPUOveruseCharge;
+    }
+
+    public void setCartridgeCPUOveruseCharge(Cash cartridgeCPUOveruseCharge) {
+        this.cartridgeCPUOveruseCharge = cartridgeCPUOveruseCharge;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        Item item = (Item) o;
+
+        if (name != null ? !name.equals(item.name) : item.name != null) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return name != null ? name.hashCode() : 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Payment.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Payment.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Payment.java
new file mode 100644
index 0000000..e99f5d7
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Payment.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.dataobjects;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class Payment {
+    int id;
+    Date date;
+    Cash amount;
+    String description;
+    List<Subscription> subscriptions;
+    Invoice invoice;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Date getDate() {
+        if(date!=null){
+            return new Date(date.getTime());
+        }else{
+            return null;
+        }
+    }
+
+    public void setDate(Date date) {
+        if(date!=null){
+            this.date = new Date(date.getTime());
+        }else{
+            this.date = null;
+        }
+    }
+
+    public Cash getAmount() {
+        return amount;
+    }
+
+    public void setAmount(Cash amount) {
+        this.amount = amount;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public List<Subscription> getSubscriptions() {
+        return subscriptions;
+    }
+
+    public void setSubscriptions(List<Subscription> subscriptions) {
+        this.subscriptions = subscriptions;
+    }
+
+    public void addSubscription(Subscription subscription) {
+        if (this.subscriptions == null) {
+            this.subscriptions = new ArrayList<Subscription>();
+        }
+        subscriptions.add(subscription);
+    }
+
+    public Invoice getInvoice() {
+        return invoice;
+    }
+
+    public void setInvoice(Invoice invoice) {
+        this.invoice = invoice;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/384b3de9/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Subscription.java
----------------------------------------------------------------------
diff --git a/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Subscription.java b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Subscription.java
new file mode 100644
index 0000000..0b9fbf3
--- /dev/null
+++ b/components/stratos/billing/org.wso2.carbon.billing.core/2.1.3/src/main/java/org/wso2/carbon/billing/core/dataobjects/Subscription.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed 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.core.dataobjects;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Subscription class - information on subscriptions which the users
+ * are subscribed to.
+ */
+public class Subscription {
+    int id;
+    Date activeSince;
+    Date activeUntil;
+    Item item;
+    Customer customer;
+    boolean active;
+    int invoiceSubscriptionId = -1; // requires only if associated with an invoice
+    List<Payment> payments;
+    String subscriptionPlan;        //i.e. multitenance-small, multitencay-medium .....
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Date getActiveSince() {
+        if(activeSince!=null){
+            return  new Date(activeSince.getTime());
+        }else{
+            return null;
+        }
+    }
+
+    public void setActiveSince(Date activeSince) {
+        if(activeSince!=null){
+            this.activeSince = new Date(activeSince.getTime());
+        }else{
+            this.activeSince = null;
+        }
+
+    }
+
+    public Date getActiveUntil() {
+        if(activeUntil!=null){
+            return  new Date(activeUntil.getTime());
+        }else{
+            return null;
+        }
+    }
+
+    public void setActiveUntil(Date activeUntil) {
+        if(activeUntil!=null){
+            this.activeUntil = new Date(activeUntil.getTime());
+        }else{
+            this.activeUntil = null;
+        }
+
+    }
+
+    public Item getItem() {
+        return item;
+    }
+
+    public void setItem(Item item) {
+        this.item = item;
+    }
+
+    public Customer getCustomer() {
+        return customer;
+    }
+
+    public void setCustomer(Customer customer) {
+        this.customer = customer;
+    }
+
+    public boolean isActive() {
+        return active;
+    }
+
+    public void setActive(boolean active) {
+        this.active = active;
+    }
+
+    public int getInvoiceSubscriptionId() {
+        return invoiceSubscriptionId;
+    }
+
+    public void setInvoiceSubscriptionId(int invoiceSubscriptionId) {
+        this.invoiceSubscriptionId = invoiceSubscriptionId;
+    }
+
+    public List<Payment> getPayments() {
+        return payments;
+    }
+
+    public void setPayments(List<Payment> payments) {
+        this.payments = payments;
+    }
+
+    public String getSubscriptionPlan() {
+        return subscriptionPlan;
+    }
+
+    public void setSubscriptionPlan(String subscriptionPlan) {
+        this.subscriptionPlan = subscriptionPlan;
+    }
+}