src/share/classes/javax/rmi/CORBA/GetORBPropertiesFileAction.java

Thu, 17 Jun 2010 16:27:56 -0700

author
mikejwre
date
Thu, 17 Jun 2010 16:27:56 -0700
changeset 171
95db968660e7
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

Added tag jdk7-b98 for changeset 3b99409057e4

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

mercurial