1 22 package org.jboss.mx.util; 23 24 import java.security.AccessController ; 25 import java.security.PrivilegedAction ; 26 27 35 public class PropertyAccess 36 { 37 static class PropertyReadAction implements PrivilegedAction 38 { 39 private String name; 40 private String defaultValue; 41 PropertyReadAction(String name, String defaultValue) 42 { 43 this.name = name; 44 this.defaultValue = defaultValue; 45 } 46 public Object run() 47 { 48 return System.getProperty(name, defaultValue); 49 } 50 } 51 static class PropertyWriteAction implements PrivilegedAction 52 { 53 private String name; 54 private String value; 55 PropertyWriteAction(String name, String value) 56 { 57 this.name = name; 58 this.value = value; 59 } 60 public Object run() 61 { 62 return System.setProperty(name, value); 63 } 64 } 65 66 public static String getProperty(String name) 67 { 68 return getProperty(name, null); 69 } 70 71 public static String getProperty(String name, String defaultValue) 72 { 73 PrivilegedAction action = new PropertyReadAction(name, defaultValue); 74 String property = (String ) AccessController.doPrivileged(action); 75 return property; 76 } 77 78 public static String setProperty(String name, String value) 79 { 80 PrivilegedAction action = new PropertyWriteAction(name, value); 81 String property = (String ) AccessController.doPrivileged(action); 82 return property; 83 } 84 85 } 86 | Popular Tags |