/*
 * 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.commons.configuration;

/**
 * A configuration based on the system properties.
 *
 * @author Emmanuel Bourg
 * @version $Revision$, $Date$
 * @since 1.1
 */
public class SystemConfiguration extends MapConfiguration
{
    /**
     * Create a Configuration based on the system properties.
     *
     * @see System#getProperties
     */
    public SystemConfiguration()
    {
        super(System.getProperties());
    }

    /**
     * The method allows system properties to be set from a property file.
     * 
     * @param fileName The name of the property file.
     * @throws Exception if an error occurs.
     * @since 1.6
     */
    public static void setSystemProperties(String fileName) throws Exception
    {
        setSystemProperties(null, fileName);
    }

    /**
     * The method allows system properties to be set from a property file.
     * 
     * @param basePath The base path to look for the property file.
     * @param fileName The name of the property file.
     * @throws Exception if an error occurs.
     * @since 1.6
     */
    public static void setSystemProperties(String basePath, String fileName) throws Exception
    {
        PropertiesConfiguration config = fileName.endsWith(".xml")
            ? new XMLPropertiesConfiguration() : new PropertiesConfiguration();
        if (basePath != null)
        {
            config.setBasePath(basePath);
        }
        config.setFileName(fileName);
        config.load();
        setSystemProperties(config);
    }

    /**
     * Set System properties from a configuration file.
     * 
     * @param systemConfig The configuration containing the properties to be set.
     * @since 1.6
     */
    public static void setSystemProperties(PropertiesConfiguration systemConfig)
    {
        ConfigurationUtils.copy(systemConfig, new SystemConfiguration());
    }
}

@@ -839,16 +839,130 @@
 ation;%0A%0A
+import org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A%0Aimport java.util.Iterator;%0A%0A
 /**%0A * A
@@ -1146,16 +1146,91 @@
 ation%0A%7B%0A
+    private static Log log = LogFactory.getLog(SystemConfiguration.class);%0A
     /**%0A
@@ -1503,32 +1503,24 @@
 perty file.%0A
-     * %0A
      * @para
@@ -1846,32 +1846,24 @@
 perty file.%0A
-     * %0A
      * @para
@@ -2555,16 +2555,8 @@
 le.%0A
-     * %0A
     
@@ -2758,73 +2758,400 @@
     
-ConfigurationUtils.copy(systemConfig, new SystemConfiguration());
+Iterator iter = systemConfig.getKeys();%0A        while (iter.hasNext())%0A        %7B%0A            String key = (String) iter.next();%0A            String value = (String) systemConfig.getProperty(key);%0A            if (log.isDebugEnabled())%0A            %7B%0A                log.debug(%22Setting system property %22 + key + %22 to %22 + value);%0A            %7D%0A            System.setProperty(key, value);%0A        %7D
 %0A   

Revert prior change. For some reason using ConfigurationUtils.copy() causes all sorts of problems when DefaultConfigurationBuilder is performing this operation on JBoss.