GetORBPropertiesFileAction.java revision 608:7e06bf1dcb09
1/* 2 * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26/* 27 * (C) Copyright IBM Corp. 1993 - 1997 - All Rights Reserved 28 * 29 * The original version of this source code and documentation is 30 * copyrighted and owned by IBM, Inc. These materials are provided under 31 * terms of a License Agreement between IBM and Sun. This technology is 32 * protected by multiple US and International patents. This notice and 33 * attribution to IBM may not be removed. 34 * 35 */ 36 37 38package javax.rmi.CORBA; 39 40import java.io.IOException; 41import java.io.File; 42import java.io.FileInputStream; 43 44import java.security.AccessController; 45import java.security.PrivilegedAction; 46import sun.security.action.GetPropertyAction; 47import java.util.Properties; 48 49class GetORBPropertiesFileAction implements PrivilegedAction { 50 private boolean debug = false ; 51 52 public GetORBPropertiesFileAction () { 53 } 54 55 private String getSystemProperty(final String name) { 56 // This will not throw a SecurityException because this 57 // class was loaded from rt.jar using the bootstrap classloader. 58 String propValue = (String) AccessController.doPrivileged( 59 new PrivilegedAction() { 60 public java.lang.Object run() { 61 return System.getProperty(name); 62 } 63 } 64 ); 65 66 return propValue; 67 } 68 69 private void getPropertiesFromFile( Properties props, String fileName ) 70 { 71 try { 72 File file = new File( fileName ) ; 73 if (!file.exists()) 74 return ; 75 76 FileInputStream in = new FileInputStream( file ) ; 77 78 try { 79 props.load( in ) ; 80 } finally { 81 in.close() ; 82 } 83 } catch (Exception exc) { 84 if (debug) 85 System.out.println( "ORB properties file " + fileName + 86 " not found: " + exc) ; 87 } 88 } 89 90 public Object run() 91 { 92 Properties defaults = new Properties() ; 93 94 String javaHome = getSystemProperty( "java.home" ) ; 95 String fileName = javaHome + File.separator + "lib" + File.separator + 96 "orb.properties" ; 97 98 getPropertiesFromFile( defaults, fileName ) ; 99 100 Properties results = new Properties( defaults ) ; 101 102 String userHome = getSystemProperty( "user.home" ) ; 103 fileName = userHome + File.separator + "orb.properties" ; 104 105 getPropertiesFromFile( results, fileName ) ; 106 return results ; 107 } 108} 109