/*
 * 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;

/**
 * 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 ConfUtil instance = null;

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

            File confFile;
            if (configFilePath != null && !configFilePath.isEmpty()) {
                confFile = new File(configFilePath);

            } else {
                confFile = new File(CarbonUtils.getCarbonConfigDirPath(),Constants.AUTOSCALER_CONFIG_FILE_NAME);
            }

            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 (instance == null) {
            instance = new ConfUtil (configFilePath);
        }
        return instance;
    }

    public XMLConfiguration getConfiguration(){
        return config;
    }
    
}

@@ -1164,16 +1164,42 @@
 io.File;
+%0Aimport java.util.HashMap;
 %0A%0A/**%0A *
@@ -1426,24 +1426,39 @@
  static 
+HashMap%3CString,
 ConfUtil
  instanc
@@ -1449,16 +1449,17 @@
 ConfUtil
+%3E
  instanc
@@ -1463,15 +1463,43 @@
 ance
- = null
+Map=new HashMap%3CString, ConfUtil%3E()
 ;%0A%0A 
@@ -1542,24 +1542,26 @@
 ePath) %7B%0A   
+//
      log.inf
@@ -1637,283 +1637,34 @@
 File
-;%0A            if (configFilePath != null && !configFilePath.isEmpty()) %7B%0A                confFile = new File(configFilePath);%0A%0A            %7D else %7B%0A                confFile = new File(CarbonUtils.getCarbonConfigDirPath(),Constants.AUTOSCALER_CONFIG_FILE_NAME);%0A            %7D%0A
+=new File(configFilePath);
 %0A   
@@ -1985,24 +1985,211 @@
 gFilePath) %7B
+%0A%0A%09    if (configFilePath == null %7C%7C configFilePath.isEmpty()) %7B%0A%09%09    configFilePath = Constants.AUTOSCALER_CONFIG_FILE_NAME;%0A%09    %7D%0A%09%09ConfUtil instance= instanceMap.get(configFilePath);
 %0A        if 
@@ -2255,32 +2255,83 @@
 onfigFilePath);%0A
+%09        instanceMap.put(configFilePath,instance);%0A
         %7D%0A      
@@ -2433,15 +2433,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

Update the conf util to support multiple configuration files