orb.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,939 行 · 第 1/5 页
JAVA
1,939 行
// possible for the Applet instance to be null. // Get the full list of property names that we are interested in String[] propertyNames = getPropertyNames(); String[] propertyNamePrefixes = getPropertyNamePrefixes(); if (app != null) { appletCodeBase = app.getCodeBase(); if (appletCodeBase != null) appletHost = appletCodeBase.getHost( ); } // Build up the full list of configuration properties // from the applet-params and props-argument. // Make Properties Vector to handle multiple -ORBInitDef s Properties propList = new Properties(); // Until we decide it's ok for getSystemProperty() to // use AccessController.beginPrivileged(), I've commented // out the use of System properties for applets since // this will result in confusing SecurityExceptions in // most situations. // /* findORBPropertiesFromSystem(propList, propertyNames, propertyNamePrefixes); */ findPropertiesFromProperties(propList, props, propertyNames, propertyNamePrefixes); findPropertiesFromApplet(propList, app, propertyNames, propertyNamePrefixes); checkAppletPropertyDefaults(propList); // Use the full props list to set ORB state. parseProperties(propList); } /** * Initialize any necessary ORB state; get attributes if possible. * Called from org.omg.CORBA.ORB.init(). * @param params An array of parameters in the form of alternating <br> * "-param-name" and "param-value" strings. * @param props the application properties */ protected void set_parameters (String[] params, Properties props) { // Get the full list of property names that we are interested in String[] propertyNames = getPropertyNames(); String[] propertyNamePrefixes = getPropertyNamePrefixes(); // Build up the full list of configuration properties // from the command-line-params, props-argument, System properties. Properties propList = new Properties(); Vector orbInitRefList = new Vector(); findORBPropertiesFromSystem(propList, propertyNames, propertyNamePrefixes); findPropertiesFromProperties(propList, props, propertyNames, propertyNamePrefixes); findPropertiesFromFile(propList, propertyNames, propertyNamePrefixes); findPropertiesFromArgs(propList, orbInitRefList, params, propertyNames, propertyNamePrefixes); checkApplicationPropertyDefaults(propList); // Use the full props list to set ORB state. parseProperties(propList); boolean result = initialNamingClient.setORBInitRefList( orbInitRefList ); // If we are unsuccessful in setting the ORBInitDef list then it means // there are some malformed URLs presesnt if( result == false ) { // Make sure to add the right minor codes here, for now it is // reusing one of the old Minorcode. throw new org.omg.CORBA.BAD_PARAM(MinorCodes.BAD_STRINGIFIED_IOR, CompletionStatus.COMPLETED_NO); } } /** Return a list of property names that this ORB is interested in. * This may be overridden by subclasses, but subclasses must call * super.getPropertyNames() to get all names. */ protected String[] getPropertyNames() { String[] names = new String[JavaIDLPropertyNames.length]; for ( int i=0; i<JavaIDLPropertyNames.length; i++ ) names[i] = JavaIDLPropertyNames[i]; if (ORBInitDebug) dprint( "getPropertyNames returns " + ORBUtility.objectToString( names ) ) ; return names; } /** Return a list of property name prefixes that this ORB is interested in. * This may be overridden by subclasses, but subclasses must call * super.getPropertyNames() to get all names. */ protected String[] getPropertyNamePrefixes() { String[] names = new String[JavaIDLPropertyNamePrefixes.length]; for ( int i=0; i<JavaIDLPropertyNamePrefixes.length; i++ ) { names[i] = JavaIDLPropertyNamePrefixes[i]; } if (ORBInitDebug) { dprint( "getPropertyNamePrefixes returns " + ORBUtility.objectToString( names ) ) ; } return names; } /* * A callback is used since sometimes we cannot actually get our * hands on the properties object (e.g., System.properties). */ private void findPropertiesWithPrefix(String[] propertyNamePrefixes, Enumeration namesToSearch, GetPropertyCallback getProperty, String source, Properties resultProperties) { while (namesToSearch.hasMoreElements()) { String pn = (String) namesToSearch.nextElement(); for (int j = 0; j < propertyNamePrefixes.length; j++) { if (pn.startsWith(propertyNamePrefixes[j])) { String value = getProperty.get(pn); // Note: do a put even if value is null since just // the presence of the property may be significant. resultProperties.put(pn, value); if (ORBInitDebug) { dprint( "Found prefixed property " + pn + "=" + value + " in " + source); } } } } } protected boolean singleParam(String param) { // Return true if this param does not have a data field after it // (e.g. for on/off flags). return false; } protected String findMatchingPropertyName( String[] propertyNames, String suffix ) { for (int ctr=0; ctr<propertyNames.length; ctr++) { if (propertyNames[ctr].endsWith( suffix )) { return propertyNames[ctr] ; } } return null ; } // // Map command-line arguments to ORB properties. // protected void findPropertiesFromArgs(Properties props, Vector orbInitRefList, String[] params, String[] propertyNames, String[] propertyNamePrefixes) { // REVISIT: Parameter propertyNamePrefixes is ignored at this time. // No OMG specs have -ORB<prefix> at this time. if (ORBInitDebug) dprint( "findPropertiesFromArgs called with params=" + ORBUtility.objectToString( params ) + " propertyNames = " + ORBUtility.objectToString( propertyNames ) ) ; if (params == null) return; // All command-line args are of the form "-ORBkey value". // The key is mapped to org.omg.CORBA.key. String name ; String value ; for ( int i=0; i<params.length; i++ ) { value = null ; name = null ; if ( params[i] != null && params[i].startsWith("-ORB") ) { String argName = params[i].substring( 1 ) ; name = findMatchingPropertyName( propertyNames, argName ) ; if (name != null) if (singleParam(params[i])) { value = params[i] ; } else if ( i+1 < params.length && params[i+1] != null ) { value = params[++i]; } } if (value != null) { if (ORBInitDebug) dprint( "Found property " + name + "=" + value + " in args" ) ; if( name.equals( "org.omg.CORBA.ORBInitRef" ) ) { orbInitRefList.add( value ); } else { props.put( name, value ) ; } } } } // // Map applet parameters to ORB properties. // protected void findPropertiesFromApplet(Properties props, Applet app, String[] propertyNames, String[] propertyNamePrefixes) { // REVISIT: propertyNamePrefixes is ignored at this time. // There is no Java API to get a applet parameter // by specifying its prefix. if (app == null) return; for (int i=0; i < propertyNames.length; i++) { String value = app.getParameter(propertyNames[i]); if (value == null) continue; props.put(propertyNames[i], value); } // // Special Case: // // Convert any applet parameter relative URLs to an // absolute URL based on the Document Root. This is so HTML URLs can be // kept relative which is sometimes useful for managing the // Document Root layout. // for (int i=0; i < JavaIDLURLPropertyNames.length; i++) { String value; value = props.getProperty(JavaIDLURLPropertyNames[i]); if (value == null) continue; try { URL url; url = new URL(app.getDocumentBase(), value); props.put(JavaIDLURLPropertyNames[i], url.toExternalForm()); } catch (java.net.MalformedURLException ex) { // // This will be caught again later if this property is used. // Don't worry about reporting exceptions now. // } } } private static Class thisClass = ORB.class; private static String getSystemProperty(final String name) { return (String)AccessController.doPrivileged(new GetPropertyAction(name)); } private static Enumeration getSystemPropertyNames() { // This will not throw a SecurityException because this // class was loaded from rt.jar using the bootstrap classloader. return (Enumeration) AccessController.doPrivileged( new PrivilegedAction() { public java.lang.Object run() { return System.getProperties().propertyNames(); } } ); } private void getPropertiesFromFile( Properties props, String fileName ) { try { File file = new File( fileName ) ; if (!file.exists()) return ; FileInputStream in = new FileInputStream( file ) ; try { props.load( in ) ; } finally { in.close() ; } } catch (Exception exc) { if (ORBInitDebug) dprint( "ORB properties file " + fileName + " not found: " + exc) ; } } Properties getFileProperties() { Properties defaults = new Properties() ; String javaHome = getSystemProperty( "java.home" ) ; String fileName = javaHome + File.separator + "lib" + File.separator + "orb.properties" ; getPropertiesFromFile( defaults, fileName ) ; Properties results = new Properties( defaults ) ; String userHome = getSystemProperty( "user.home" ) ; fileName = userHome + File.separator + "orb.properties" ; getPropertiesFromFile( results, fileName ) ; return results ; } protected void findPropertiesFromFile(Properties props, String[] propertyNames, String[] propertyNamePrefixes) { final Properties fileProps = getFileProperties() ; if (fileProps==null) return ; for (int i=0; i < propertyNames.length; i++) { String value; value = (String)fileProps.getProperty(propertyNames[i]); if (value == null) continue; props.put(propertyNames[i], value); if (ORBInitDebug) dprint( "Found property " + propertyNames[i] + "=" + value + " in file properties" ) ; } findPropertiesWithPrefix( propertyNamePrefixes, fileProps.propertyNames(), new GetPropertyCallback() { public String get(String name) { return fileProps.getProperty(name); } }, "file properties", props ); } // // Map System properties to ORB properties. // Security bug fix 4278205: // Allow only reading of system properties with ORB prefixes. // Previously a malicious subclass was able to read ANY system property. // private void findORBPropertiesFromSystem(Properties props, String[] propertyNames, String[] propertyNamePrefixes) { for (int i=0; i < propertyNames.length; i++) { if (propertyNames[i].startsWith( ORBConstants.OMG_PREFIX ) || propertyNames[i].startsWith( ORBConstants.SUN_PREFIX ) || propertyNames[i].startsWith( ORBConstants.SUN_LC_PREFIX ) || propertyNames[i].startsWith( ORBConstants.SUN_LC_VERSION_PREFIX )) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?