001 /** 002 * 003 * Copyright 2005 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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: 406493 $ $Date: 2006-05-14 18:14:11 -0700 (Sun, 14 May 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 }