KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > yaafi > service > systemproperty > SystemPropertyServiceImpl


1 package org.apache.fulcrum.yaafi.service.systemproperty;
2
3 /*
4  * Copyright 2004 Apache Software Foundation
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.
15  *
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */

19
20 import org.apache.avalon.framework.configuration.Configurable;
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23 import org.apache.avalon.framework.logger.AbstractLogEnabled;
24
25
26 /**
27  * Copies the properties found in the configuration into the SystemProperties
28  *
29  * @author <a HREF="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
30  * @avalon.component name="SystemPropertyService" lifestyle="singleton"
31  * @avalon.service type="org.apache.fulcrum.yaafi.service.systemproperty.SystemPropertyService"
32  * @avalon.attribute key="urn:composition:deployment.timeout" value="0"
33  */

34
35 public class SystemPropertyServiceImpl
36     extends AbstractLogEnabled
37     implements SystemPropertyService, Configurable
38 {
39     /**
40      * Constructor
41      */

42     public SystemPropertyServiceImpl()
43     {
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 JavaDoc key = null;
52         String JavaDoc value = null;
53         String JavaDoc oldValue = null;
54         Configuration[] systemProperties = configuration.getChildren();
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             this.getLogger().debug( "Processed the following number of properties : " + systemProperties.length );
78         }
79     }
80
81 }
82
Popular Tags