/*
 * 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 java.io.File;
import java.util.HashMap;

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

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

    private XMLConfiguration config;

	//To maintain the map of config files
    private static HashMap<String,ConfUtil> instanceMap=new HashMap<String, ConfUtil>();

    private ConfUtil(String configFilePath) {
        try {

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

	/**
	 * Get the instance of the configuration file
	 * @param configFilePath configuration file name
	 * @return ConfUtil instance
	 */
    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;
    }

	/**
	 * Get configurations
	 * @return XMLConfiguration
	 */
    public XMLConfiguration getConfiguration(){
        return config;
    }

}

@@ -1251,20 +1251,17 @@
 Util %7B%0A%0A
-    
+%09
 private 
@@ -1309,28 +1309,25 @@
 il.class);%0A%0A
-    
+%09
 private XMLC
@@ -1387,20 +1387,17 @@
 g files%0A
-    
+%09
 private 
@@ -1418,16 +1418,17 @@
 %3CString,
+ 
 ConfUtil
@@ -1440,17 +1440,19 @@
 tanceMap
-=
+ = 
 new Hash
@@ -1477,20 +1477,17 @@
 il%3E();%0A%0A
-    
+%09
 private 
@@ -1524,35 +1524,20 @@
 ) %7B%0A
-        try %7B%0A%0A            
+%09%09try %7B%0A%0A%09%09%09
 File
@@ -1545,17 +1545,19 @@
 confFile
-=
+ = 
 new File
@@ -1574,28 +1574,19 @@
 ePath);%0A
-            
+%09%09%09
 config =
@@ -1618,24 +1618,18 @@
 fFile);%0A
-        
+%09%09
 %7D catch 
@@ -1657,28 +1657,19 @@
 on e) %7B%0A
-            
+%09%09%09
 log.erro
@@ -1710,24 +1710,16 @@
 le%22,
+ 
 e);%0A
-            
+%09%09%09
 conf
@@ -1780,30 +1780,21 @@
  values%0A
-        %7D%0A    
+%09%09%7D%0A%09
 %7D%0A%0A%09/**%0A
@@ -1840,16 +1840,20 @@
 on file%0A
+%09 *%0A
 %09 * @par
@@ -1925,28 +1925,25 @@
 stance%0A%09 */%0A
-    
+%09
 public stati
@@ -1992,20 +1992,17 @@
 th) %7B%0A%0A%09
-    
+%09
 if (conf
@@ -2053,20 +2053,17 @@
 ()) %7B%0A%09%09
+%09
-    
 configFi
@@ -2111,20 +2111,17 @@
 _NAME;%0A%09
-    
+%09
 %7D%0A%09%09Conf
@@ -2133,16 +2133,17 @@
 instance
+ 
 = instan
@@ -2169,24 +2169,18 @@
 ePath);%0A
-        
+%09%09
 if (inst
@@ -2199,20 +2199,11 @@
 ) %7B%0A
-            
+%09%09%09
 inst
@@ -2221,17 +2221,16 @@
 ConfUtil
- 
 (configF
@@ -2240,24 +2240,18 @@
 Path);%0A%09
-        
+%09%09
 instance
@@ -2273,16 +2273,17 @@
 ilePath,
+ 
 instance
@@ -2289,26 +2289,14 @@
 e);%0A
-        %7D%0A        
+%09%09%7D%0A%09%09
 retu
@@ -2308,20 +2308,17 @@
 stance;%0A
-    
+%09
 %7D%0A%0A%09/**%0A
@@ -2340,16 +2340,20 @@
 rations%0A
+%09 *%0A
 %09 * @ret
@@ -2378,20 +2378,17 @@
 on%0A%09 */%0A
-    
+%09
 public X
@@ -2425,18 +2425,13 @@
 on()
+ 
 %7B%0A
-        
+%09%09
 retu
@@ -2445,12 +2445,9 @@
 ig;%0A
-    
+%09
 %7D%0A%0A%7D

Update the conf util to support multiple configuration files