Java tutorial
/* * Copyright 2014 BlueScope Steel. * * 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 com.bluescopesteel.foldermonitor.config; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.SystemConfiguration; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * * @author Mitchell Just (Mitchell.Just@BlueScopeSteel.com) */ public class ConfigManager { private static final Log log = LogFactory.getLog(ConfigManager.class); private static CompositeConfiguration config; public synchronized static Configuration getConfig() { if (config == null) { try { log.info("Creating new configuration object"); config = new CompositeConfiguration(); config.addConfiguration(new PropertiesConfiguration("default.properties")); try { config.addConfiguration(new PropertiesConfiguration("config.properties")); } catch (ConfigurationException ex) { log.info("No installed configuration file found"); } config.addConfiguration(new SystemConfiguration()); } catch (ConfigurationException ex) { log.error("Error creating configuration", ex); } } return config; } }