KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > rmi > CORBA > GetORBPropertiesFileAction


1 /*
2  * @(#)GetORBPropertiesFileAction.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /*
9  * (C) Copyright IBM Corp. 1993 - 1997 - All Rights Reserved
10  *
11  * The original version of this source code and documentation is
12  * copyrighted and owned by IBM, Inc. These materials are provided under
13  * terms of a License Agreement between IBM and Sun. This technology is
14  * protected by multiple US and International patents. This notice and
15  * attribution to IBM may not be removed.
16  *
17  */

18
19
20 package javax.rmi.CORBA;
21
22 import java.io.IOException JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileInputStream JavaDoc;
25
26 import java.security.AccessController JavaDoc;
27 import java.security.PrivilegedAction JavaDoc;
28 import sun.security.action.GetPropertyAction;
29 import java.util.Properties JavaDoc;
30
31 class GetORBPropertiesFileAction implements PrivilegedAction JavaDoc {
32     private boolean debug = false ;
33
34     public GetORBPropertiesFileAction () {
35     }
36
37     private String JavaDoc getSystemProperty(final String JavaDoc name) {
38     // This will not throw a SecurityException because this
39
// class was loaded from rt.jar using the bootstrap classloader.
40
String JavaDoc propValue = (String JavaDoc) AccessController.doPrivileged(
41         new PrivilegedAction JavaDoc() {
42         public java.lang.Object JavaDoc run() {
43                 return System.getProperty(name);
44             }
45             }
46     );
47
48     return propValue;
49     }
50
51     private void getPropertiesFromFile( Properties JavaDoc props, String JavaDoc fileName )
52     {
53         try {
54         File JavaDoc file = new File JavaDoc( fileName ) ;
55         if (!file.exists())
56         return ;
57
58             FileInputStream JavaDoc in = new FileInputStream JavaDoc( file ) ;
59         
60         try {
61         props.load( in ) ;
62         } finally {
63         in.close() ;
64         }
65         } catch (Exception JavaDoc exc) {
66             if (debug)
67                 System.out.println( "ORB properties file " + fileName +
68             " not found: " + exc) ;
69         }
70     }
71
72     public Object JavaDoc run()
73     {
74         Properties JavaDoc defaults = new Properties JavaDoc() ;
75
76     String JavaDoc javaHome = getSystemProperty( "java.home" ) ;
77     String JavaDoc fileName = javaHome + File.separator + "lib" + File.separator +
78         "orb.properties" ;
79
80     getPropertiesFromFile( defaults, fileName ) ;
81
82     Properties JavaDoc results = new Properties JavaDoc( defaults ) ;
83
84         String JavaDoc userHome = getSystemProperty( "user.home" ) ;
85         fileName = userHome + File.separator + "orb.properties" ;
86
87     getPropertiesFromFile( results, fileName ) ;
88     return results ;
89     }
90 }
91
Popular Tags