/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF 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.apache.stratos.autoscaler.util;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.Constants;
import org.wso2.carbon.utils.CarbonUtils;

import java.io.File;
import java.util.HashMap;

/**
 * This class contains utility methods for read Autoscaler configuration file.
 */
public class ConfUtil {

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

    private XMLConfiguration config;

    private static HashMap<String,ConfUtil> instanceMap=new HashMap<String, ConfUtil>();

    private ConfUtil(String configFilePath) {
   //     log.info("Loading configuration.....");
        try {

            File confFile=new File(configFilePath);
            config = new XMLConfiguration(confFile);
        } catch (ConfigurationException e) {
            log.error("Unable to load autoscaler configuration file",e);
            config = new XMLConfiguration();  // continue with default values
        }
    }

    public static ConfUtil getInstance(String configFilePath) {

	    if (configFilePath == null || configFilePath.isEmpty()) {
		    configFilePath = Constants.AUTOSCALER_CONFIG_FILE_NAME;
	    }
		ConfUtil instance= instanceMap.get(configFilePath);
        if (instance == null) {
            instance = new ConfUtil (configFilePath);
	        instanceMap.put(configFilePath,instance);
        }
        return instance;
    }

    public XMLConfiguration getConfiguration(){
        return config;
    }

}

@@ -1104,50 +1104,8 @@
 nts;
-%0Aimport org.wso2.carbon.utils.CarbonUtils;
 %0A%0Aim
@@ -1206,19 +1206,8 @@
 ead 
-Autoscaler 
 conf
@@ -1354,16 +1354,55 @@
 onfig;%0A%0A
+%09//To maintain the map of config files%0A
     priv
@@ -1533,58 +1533,8 @@
 ) %7B%0A
-   //     log.info(%22Loading configuration.....%22);%0A
     
@@ -1736,19 +1736,8 @@
 oad 
-autoscaler 
 conf
@@ -1843,32 +1843,169 @@
        %7D%0A    %7D%0A%0A
+%09/**%0A%09 * Get the instance of the configuration file%0A%09 * @param configFilePath configuration file name%0A%09 * @return ConfUtil instance%0A%09 */%0A
     public stati
@@ -2418,16 +2418,78 @@
 %0A    %7D%0A%0A
+%09/**%0A%09 * Get configurations%0A%09 * @return XMLConfiguration%0A%09 */%0A
     publ

Update the conf util to support multiple configuration files