001 package org.apache.fulcrum.yaafi.service.systemproperty;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import org.apache.avalon.framework.configuration.Configuration;
023 import org.apache.avalon.framework.configuration.ConfigurationException;
024 import org.apache.avalon.framework.configuration.Reconfigurable;
025 import org.apache.avalon.framework.logger.AbstractLogEnabled;
026
027
028 /**
029 * Copies the properties found in the configuration into the SystemProperties
030 *
031 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
032 */
033
034 public class SystemPropertyServiceImpl
035 extends AbstractLogEnabled
036 implements SystemPropertyService, Reconfigurable
037 {
038 /**
039 * Constructor
040 */
041 public SystemPropertyServiceImpl()
042 {
043 // nothing to do here
044 }
045
046 /**
047 * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
048 */
049 public void configure(Configuration configuration) throws ConfigurationException
050 {
051 String key = null;
052 String value = null;
053 String oldValue = null;
054 Configuration[] systemProperties = configuration.getChildren("property");
055
056 for( int i=0; i<systemProperties.length; i++ )
057 {
058 key = systemProperties[i].getAttribute("name");
059 value = systemProperties[i].getValue();
060 oldValue = System.getProperty(key);
061
062 if( oldValue != null )
063 {
064 this.getLogger().debug(
065 "Changing the value of " + key + " from " + oldValue + " to " + value
066 );
067 }
068 else
069 {
070 this.getLogger().debug(
071 "Setting the value of " + key + " to " + value
072 );
073 }
074
075 System.setProperty( key, value );
076
077 }
078
079 this.getLogger().debug( "Processed the following number of properties : " + systemProperties.length );
080 }
081
082 /**
083 * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration)
084 */
085 public void reconfigure(Configuration configuration)
086 throws ConfigurationException
087 {
088 this.configure(configuration);
089 }
090 }