1 9 package org.eclipse.osgi.framework.internal.core; 10 11 import java.util.Properties ; 12 import java.util.PropertyPermission ; 13 14 18 public class FrameworkProperties { 19 20 private static Properties properties; 21 22 private static final String USING_SYSTEM_PROPERTIES_KEY = "osgi.framework.useSystemProperties"; 27 static { 28 Properties systemProperties = System.getProperties(); 29 String usingSystemProperties = systemProperties.getProperty(USING_SYSTEM_PROPERTIES_KEY); 30 if (usingSystemProperties == null || usingSystemProperties.equalsIgnoreCase(Boolean.TRUE.toString())) { 31 properties = systemProperties; 32 } else { 33 properties = new Properties (); 36 properties.putAll(systemProperties); 40 } 41 } 42 43 public static Properties getProperties() { 44 SecurityManager sm = System.getSecurityManager(); 45 if (sm != null) 46 sm.checkPropertiesAccess(); 47 return properties; 48 } 49 50 public static String getProperty(String key) { 51 return getProperty(key, null); 52 } 53 54 public static String getProperty(String key, String defaultValue) { 55 SecurityManager sm = System.getSecurityManager(); 56 if (sm != null) 57 sm.checkPropertyAccess(key); 58 return properties.getProperty(key, defaultValue); 59 } 60 61 public static String setProperty(String key, String value) { 62 SecurityManager sm = System.getSecurityManager(); 63 if (sm != null) 64 sm.checkPermission(new PropertyPermission (key, "write")); return (String ) properties.put(key, value); 66 } 67 68 public static String clearProperty(String key) { 69 SecurityManager sm = System.getSecurityManager(); 70 if (sm != null) 71 sm.checkPermission(new PropertyPermission (key, "write")); return (String ) properties.remove(key); 73 } 74 } 75 | Popular Tags |