View Javadoc
1   package org.apache.fulcrum.yaafi.service.systemproperty;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.avalon.framework.configuration.Configuration;
23  import org.apache.avalon.framework.configuration.ConfigurationException;
24  import org.apache.avalon.framework.configuration.Reconfigurable;
25  import org.apache.avalon.framework.logger.AbstractLogEnabled;
26  
27  
28  /**
29   * Copies the properties found in the configuration into the SystemProperties
30   *
31   * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
32   */
33  
34  public class SystemPropertyServiceImpl
35      extends AbstractLogEnabled
36      implements SystemPropertyService, Reconfigurable
37  {
38      /**
39       * Constructor
40       */
41      public SystemPropertyServiceImpl()
42      {
43          // nothing to do here
44      }
45  
46      /**
47       * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
48       */
49      public void configure(Configuration configuration) throws ConfigurationException
50      {
51          String key      = null;
52          String value    = null;
53          String oldValue = null;
54          Configuration[] systemProperties = configuration.getChildren("property");
55  
56          for( int i=0; i<systemProperties.length; i++ )
57          {
58              key         = systemProperties[i].getAttribute("name");
59              value       = systemProperties[i].getValue();
60              oldValue    = System.getProperty(key);
61  
62              if( oldValue != null )
63              {
64                  this.getLogger().debug(
65                      "Changing the value of " + key + " from " + oldValue + " to " + value
66                      );
67              }
68              else
69              {
70                  this.getLogger().debug(
71                      "Setting the value of " + key + " to " + value
72                      );
73              }
74  
75              System.setProperty( key, value );
76  
77          }
78  
79          this.getLogger().debug( "Processed the following number of properties : " + systemProperties.length );
80      }
81  
82      /**
83       * @see org.apache.avalon.framework.configuration.Reconfigurable#reconfigure(org.apache.avalon.framework.configuration.Configuration)
84       */
85      public void reconfigure(Configuration configuration)
86          throws ConfigurationException
87      {
88          this.configure(configuration);
89      }
90  }