/*******************************************************************************
 * Copyright 2014 Centre for Development of Advanced Computing(C-DAC), Pune
 *
 * 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 in.cdac.medinfo.csnotk.csnolib.util;

import java.io.IOException;
import java.util.Properties;

//Logs
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
/**
 * Class Reads the properties.
 *
 */
public class PropertyReader {

	private static Properties props;

	/**
	 * Loads System properties .
	 * @return Object of {@link Properties}.
	 * @throws IOException - If any exception occurred during IO operation.
	 */
	public static synchronized Properties loadSystemProperties(){
		if(null == props){
			props = new Properties();
		}
		return props;
	}

	/**
	 * Gets property.
	 * @param key
	 * 			 String value representing Key of property.
	 * @return String value of property.
	 */
	public static String getProperty(String key){
		Logger logger = LogManager.getLogger(PropertyReader.class);
		if(null !=  key){
			if(props==null)
				logger.info(LoggerUtility.CONSOLE, "prop is null");
			else
			return props.getProperty(key);
		}
		return null;
	}

	/**
	 * Sets property.
	 * @param key
	 * 			 String value representing Key of property.
	 */
	public static void setProperty(String key, String val){
		if(null !=  key){
			props.setProperty(key, val);
		}

	}
}
