1. /*
  2. * @(#)GetORBPropertiesFileAction.java 1.8 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * (C) Copyright IBM Corp. 1993 - 1997 - All Rights Reserved
  9. *
  10. * The original version of this source code and documentation is
  11. * copyrighted and owned by IBM, Inc. These materials are provided under
  12. * terms of a License Agreement between IBM and Sun. This technology is
  13. * protected by multiple US and International patents. This notice and
  14. * attribution to IBM may not be removed.
  15. *
  16. */
  17. package javax.rmi.CORBA;
  18. import java.io.IOException;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.security.AccessController;
  22. import java.security.PrivilegedAction;
  23. import sun.security.action.GetPropertyAction;
  24. import java.util.Properties;
  25. class GetORBPropertiesFileAction implements PrivilegedAction {
  26. private boolean debug = false ;
  27. public GetORBPropertiesFileAction () {
  28. }
  29. private String getSystemProperty(final String name) {
  30. // This will not throw a SecurityException because this
  31. // class was loaded from rt.jar using the bootstrap classloader.
  32. String propValue = (String) AccessController.doPrivileged(
  33. new PrivilegedAction() {
  34. public java.lang.Object run() {
  35. return System.getProperty(name);
  36. }
  37. }
  38. );
  39. return propValue;
  40. }
  41. private void getPropertiesFromFile( Properties props, String fileName )
  42. {
  43. try {
  44. File file = new File( fileName ) ;
  45. if (!file.exists())
  46. return ;
  47. FileInputStream in = new FileInputStream( file ) ;
  48. try {
  49. props.load( in ) ;
  50. } finally {
  51. in.close() ;
  52. }
  53. } catch (Exception exc) {
  54. if (debug)
  55. System.out.println( "ORB properties file " + fileName +
  56. " not found: " + exc) ;
  57. }
  58. }
  59. public Object run()
  60. {
  61. Properties defaults = new Properties() ;
  62. String javaHome = getSystemProperty( "java.home" ) ;
  63. String fileName = javaHome + File.separator + "lib" + File.separator +
  64. "orb.properties" ;
  65. getPropertiesFromFile( defaults, fileName ) ;
  66. Properties results = new Properties( defaults ) ;
  67. String userHome = getSystemProperty( "user.home" ) ;
  68. fileName = userHome + File.separator + "orb.properties" ;
  69. getPropertiesFromFile( results, fileName ) ;
  70. return results ;
  71. }
  72. }