Save This Page
Home » openjdk-7 » javax » rmi » CORBA » [javadoc | source]
    1   /*
    2    * Copyright 1999-2001 Sun Microsystems, Inc.  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.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any 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   
   38   package javax.rmi.CORBA;
   39   
   40   import java.io.IOException;
   41   import java.io.File;
   42   import java.io.FileInputStream;
   43   
   44   import java.security.AccessController;
   45   import java.security.PrivilegedAction;
   46   import sun.security.action.GetPropertyAction;
   47   import java.util.Properties;
   48   
   49   class 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   }

Save This Page
Home » openjdk-7 » javax » rmi » CORBA » [javadoc | source]