1. /*
  2. * @(#)GetPropertyAction.java 1.1 04/01/16
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.orbutil ;
  8. /**
  9. * A convenience class for retrieving the string value of a system
  10. * property as a privileged action. This class is directly copied
  11. * from sun.security.action.GetPropertyAction in order to avoid
  12. * depending on the sun.security.action package.
  13. *
  14. * <p>An instance of this class can be used as the argument of
  15. * <code>AccessController.doPrivileged</code>.
  16. *
  17. * <p>The following code retrieves the value of the system
  18. * property named <code>"prop"</code> as a privileged action: <p>
  19. *
  20. * <pre>
  21. * String s = (String) java.security.AccessController.doPrivileged(
  22. * new GetPropertyAction("prop"));
  23. * </pre>
  24. *
  25. * @author Roland Schemers
  26. * @author Ken Cavanaugh
  27. * @see java.security.PrivilegedAction
  28. * @see java.security.AccessController
  29. */
  30. public class GetPropertyAction implements java.security.PrivilegedAction {
  31. private String theProp;
  32. private String defaultVal;
  33. /**
  34. * Constructor that takes the name of the system property whose
  35. * string value needs to be determined.
  36. *
  37. * @param theProp the name of the system property.
  38. */
  39. public GetPropertyAction(String theProp) {
  40. this.theProp = theProp;
  41. }
  42. /**
  43. * Constructor that takes the name of the system property and the default
  44. * value of that property.
  45. *
  46. * @param theProp the name of the system property.
  47. * @param defaulVal the default value.
  48. */
  49. public GetPropertyAction(String theProp, String defaultVal) {
  50. this.theProp = theProp;
  51. this.defaultVal = defaultVal;
  52. }
  53. /**
  54. * Determines the string value of the system property whose
  55. * name was specified in the constructor.
  56. *
  57. * @return the string value of the system property,
  58. * or the default value if there is no property with that key.
  59. */
  60. public Object run() {
  61. String value = System.getProperty(theProp);
  62. return (value == null) ? defaultVal : value;
  63. }
  64. }