001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.system.properties;
018
019 import java.util.Iterator;
020 import java.util.Properties;
021 import java.util.Map;
022
023 import org.apache.geronimo.gbean.GBeanInfo;
024 import org.apache.geronimo.gbean.GBeanInfoBuilder;
025 import org.apache.geronimo.system.serverinfo.ServerInfo;
026
027 /**
028 * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
029 */
030 public class SystemProperties {
031
032
033 public SystemProperties(Properties properties, Properties pathProperties, ServerInfo serverInfo) {
034 if (properties != null) {
035 for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) {
036 Map.Entry entry = (Map.Entry) iterator.next();
037 String propertyName = (String) entry.getKey();
038 String propertyValue = (String) entry.getValue();
039 if (System.getProperty(propertyName) == null) {
040 System.setProperty(propertyName, propertyValue);
041 }
042 }
043 }
044 if (pathProperties != null && serverInfo != null) {
045 for (Iterator iterator = pathProperties.entrySet().iterator(); iterator.hasNext();) {
046 Map.Entry entry = (Map.Entry) iterator.next();
047 String propertyName = (String) entry.getKey();
048 String propertyValue = (String) entry.getValue();
049 propertyValue = serverInfo.resolveServerPath(propertyValue);
050 if (System.getProperty(propertyName) == null) {
051 System.setProperty(propertyName, propertyValue);
052 }
053 }
054 }
055 }
056
057 public static final GBeanInfo GBEAN_INFO;
058
059 static {
060 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(SystemProperties.class, "GBean");
061 infoBuilder.addAttribute("systemProperties", Properties.class, true, true);
062 infoBuilder.addAttribute("systemPathProperties", Properties.class, true, true);
063 infoBuilder.addReference("ServerInfo", ServerInfo.class, "GBean");
064 infoBuilder.setConstructor(new String[] {"systemProperties", "systemPathProperties", "ServerInfo"});
065
066 GBEAN_INFO = infoBuilder.getBeanInfo();
067 }
068
069 public static GBeanInfo getGBeanInfo() {
070 return GBEAN_INFO;
071 }
072
073 }