1 9 package org.eclipse.core.internal.registry; 10 11 import java.util.Properties ; 12 import org.eclipse.core.internal.runtime.RuntimeLog; 13 import org.eclipse.core.runtime.IStatus; 14 import org.eclipse.core.runtime.Status; 15 16 20 public class RegistryProperties { 21 22 public static final String empty = ""; 24 private static Properties registryProperties = new Properties (); 25 private static Object context = null; 27 public static void setContext(Object object) { 28 context = object; 29 } 30 31 public static String getProperty(String propertyName) { 32 String propertyValue = registryProperties.getProperty(propertyName); 33 if (propertyValue != null) 34 return propertyValue; 35 36 return getContextProperty(propertyName); 37 } 38 39 public static String getProperty(String property, String defaultValue) { 40 String result = RegistryProperties.getProperty(property); 41 return result == null ? defaultValue : result; 42 } 43 44 public static void setProperty(String propertyName, String propertyValue) { 45 registryProperties.setProperty(propertyName, propertyValue); 46 } 47 48 private static String getContextProperty(final String propertyName) { 52 if (context == null) 53 return System.getProperty(propertyName); 54 55 final String [] result = new String [1]; 56 try { 57 Runnable innerClass = new Runnable () { 60 public void run() { 61 org.osgi.framework.BundleContext bundleContext = (org.osgi.framework.BundleContext) context; 62 result[0] = bundleContext.getProperty(propertyName); 63 } 64 }; 65 innerClass.run(); 66 } catch (Exception e) { 67 IStatus status = new Status(Status.ERROR, IRegistryConstants.RUNTIME_NAME, 0, e.getMessage(), e); 72 RuntimeLog.log(status); 73 return null; 74 } 75 return result[0]; 76 } 77 } 78 | Popular Tags |