initialnamingclient.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,249 行 · 第 1/4 页

JAVA
1,249
字号
/* * @(#)InitialNamingClient.java	1.50 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Licensed Materials - Property of IBM * RMI-IIOP v1.0 * Copyright IBM Corp. 1998 1999  All Rights Reserved * * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */package com.sun.corba.se.internal.corba;import java.net.*;import java.util.*;import java.io.StringWriter;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.DATA_CONVERSION;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.ORBPackage.InvalidName;import org.omg.CORBA.portable.ApplicationException;import org.omg.CORBA.portable.Delegate;import org.omg.CORBA.portable.InputStream;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.RemarshalException;import com.sun.corba.se.internal.core.*;import com.sun.corba.se.internal.CosNaming.MinorCodes;import com.sun.corba.se.internal.orbutil.SubcontractList;import com.sun.corba.se.internal.orbutil.ORBConstants;import com.sun.corba.se.internal.core.GIOPVersion;import com.sun.corba.se.internal.core.IOR;import com.sun.corba.se.internal.orbutil.ORBUtility;import com.sun.corba.se.internal.iiop.messages.MessageBase;import com.sun.corba.se.internal.iiop.messages.LocateRequestMessage;import com.sun.corba.se.internal.iiop.messages.LocateReplyMessage;import com.sun.corba.se.internal.ior.ObjectKeyFactory ;import org.omg.CosNaming.*;import com.sun.corba.se.internal.iiop.*;/** This class encapsulates all the state and logic for listing and *  resolving services that are published in the initial naming (bootstrap) *  service. It is only called through list_initial_services() and *  resolve_initial_references() in ORB.java. Also, INS grammer parsing *  routines are in this class. */public class InitialNamingClient{    static private final int defaultInitialServicesPort =        ORBConstants.DEFAULT_INITIAL_PORT;    // State for the initial services: a URL if specified by a URL,    // otherwise a representation to invoke on,    // a port and its default value for the endpoint, a list of    // initial services (a cache), and a list of resolved services (a cache).    private URL servicesURL = null;    protected int initialServicesPort = defaultInitialServicesPort;    private String[] listOfInitialServices;    private java.util.Properties resolvedInitialReferences = null;    // ORBInitRefList contains a list of corbaloc and corbaname objects    // defined with -ORBInitRef definition.    private java.util.Hashtable orbInitRefList;    // contains the -ORBDefaultInitRef definition.    private String orbDefaultInitRef;    com.sun.corba.se.internal.corba.ORB orb;    // Root Naming Context for default resolution of names.    private NamingContextExt rootNamingContextExt;    public InitialNamingClient(com.sun.corba.se.internal.corba.ORB orb) {	this.orb = orb;        orbInitRefList = new java.util.Hashtable();	orbDefaultInitRef = null;    }    void setServicesURL(URL url) {	servicesURL = url;    }    void setInitialServicesPort(int port) {	initialServicesPort = port;    }    /** sets the -ORBInitRef definitions in the vector.     */    boolean setORBInitRefList( java.util.Vector theList ) {	boolean status = true;	if( theList == null ) {	    status = false;	} else {       	    for( int i = 0; (i < theList.size()) && (status == true); i++ ) {	        status = parseORBInitRef( (String) theList.elementAt(i) );	    }	}	return status;    }    /** adds the -ORBInitRef definitions in the vector.     */    boolean addORBInitRef( String initRefProperty ) {        return parseORBInitRef( initRefProperty );    }    /** There will be one -ORBDefaultInitRef definition, which will be set here.     */    boolean setORBDefaultInitRef( String theOrbDefaultInitRef ) {	orbDefaultInitRef = theOrbDefaultInitRef;	return true;    }    /** This method parses all -ORBInitRef definitions and returns true or     *  false based on the correct syntax according to INS specifications.     */    private boolean parseORBInitRef( String theOrbInitRef )			throws org.omg.CORBA.BAD_PARAM    {	boolean status = true;	if( (theOrbInitRef == null ) || (theOrbInitRef.length() == 0 ) )	{            // If the string after -ORBInitRef is null then return false.	    status = false;	} else {	    String name = null;	    String value = null;	    int equalToIndex = 0;	    equalToIndex = theOrbInitRef.indexOf( '=' );	    if( equalToIndex == -1 ) {                // If '=' is missing in the -ORBInitRef then it is wrong.		status = false;	    } else {		name = theOrbInitRef.substring( 0, equalToIndex );		value = theOrbInitRef.substring( equalToIndex + 1 );		if( value == null || value.length() == 0 ) {                    // If there is no string after '=' then it is wrong.		    status = false;		} else {		    Object theValue = null;		    if ( value.startsWith( "corbaloc:" ) == true ) {                        // -ORBInitRef String starts with corbaloc:.                        // So check the corbaloc: grammer.			CorbaLoc theCorbaLocObject =                            checkcorbalocGrammer( value );			if( theCorbaLocObject != null ) {			    theValue = theCorbaLocObject;			} else {                            // Could not build CorbaLoc object which means                            // there is a syntax error.			    status = false;			}		    }		    else if ( value.startsWith( "corbaname:" ) == true ) {                        // -ORBInitRef String starts with corbaname:.                        // So check the corbaname: grammer.			CorbaName theCorbaNameObject =                            checkcorbanameGrammer( value );			if( theCorbaNameObject != null ) {			    theValue = theCorbaNameObject;			} else {                            // Could not build CorbaName object which means                            // there is a syntax error.			    status = false;			}		    }		    else if ( value.startsWith(			IOR.STRINGIFY_PREFIX ) == true )  {			// If it is IOR Object store it as it is.			theValue = value;			status = true;		    } else {                        // If it does not start with corbaloc: or corbaname: or                        // IOR: then it is worng.			status = false;		    }		    if( status == true ) {			try {                            // If the CorbaLoc or CorbaName or IOR object is                            // built successfully then add that to the list.			    orbInitRefList.put( name, theValue );			} catch( Exception e ) {			    status = false;			}		    } else {			throw new org.omg.CORBA.BAD_PARAM(                            MinorCodes.INS_BAD_SCHEME_NAME,                            CompletionStatus.COMPLETED_NO);		    }		}	    }	}	return status;     }     /** Check whether the given 'corbaloc' is valid according to INS      *  specification.      *  returns CorbaLoc object which contains endpointinfo and objectKey.      *  _REVISIT_ : Cleanup for Tiger      */     public CorbaLoc checkcorbalocGrammer( String value )		throws org.omg.CORBA.BAD_PARAM     {	CorbaLoc theCorbaLocObject = new CorbaLoc( );	// Get the substring after corbaloc:	if( value != null ) {	    try {	        // First Clean the URL Escapes if there are any		value = decode( value );	    } catch( Exception e ) {		// There is something wrong with the URL escapes		// and hence throw the exception		throw new org.omg.CORBA.BAD_PARAM(		    MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART,                    CompletionStatus.COMPLETED_NO);	    }            // String length of corbaloc: is 9	    int startIndex = 9;            int endIndex = value.indexOf( '/' );            // BUG FIX for 4336809            if( endIndex == -1 ) {                // If there is no '/' then the endIndex is at the end of the URL                endIndex = value.length();            }            if( endIndex == 1 )  {                // There are no characters after corbaloc: then it is an error.		throw new org.omg.CORBA.BAD_PARAM(		    MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART,                    CompletionStatus.COMPLETED_NO);            }            else {		// Anything between corbaloc: and / are the host information		// of the server where the Service Object is located                java.util.Vector hostNames = getHostNamesFromURL(                    value.substring( startIndex, endIndex ) );		if( ( hostNames == null )		  ||( hostNames.size() == 0 ) )		{		    // hostName is null which means the address portion		    // of the url is incorrect		    throw new org.omg.CORBA.BAD_PARAM(                        MinorCodes.INS_BAD_ADDRESS,                        CompletionStatus.COMPLETED_NO);		}		for( int i = 0;                   (i < hostNames.size()) && (theCorbaLocObject != null) ; i++ )	        {	            String hostName = (String)hostNames.elementAt( i );		    String host = null;                    // 2089 is the default port number according to INS spec.                    // GIOP 1.2 is the default version.		    int port = 2089;		    int major = 1;		    int minor = 2;		    if( hostName.startsWith( "iiop:" ) ) {			// Check the iiop syntax			int at = hostName.indexOf( '@' );			if( at == -1 ) {			    // There is no Major and Minor number			    try {			        host = hostName.substring( 5 );				if( ( host == null )			  	  ||( host.length() == 0 ) )				{                                    // _REVISIT_ Add a new method to throw                                     // BAD_PARAM exception and then invoke                                     // that method to throw BAD_PARAM exception				    // hostName is null which means the address				    // portion of the url is incorrect				    throw new org.omg.CORBA.BAD_PARAM(					MinorCodes.INS_BAD_ADDRESS,                                       	CompletionStatus.COMPLETED_NO);				} else {                                    // A Hack to differentiate IPV6 address                                    // from IPV4 address, Current Resolution                                    // is to use [ ] to differentiate ipv6 host                                    int squareBracketBeginIndex =                                         host.indexOf ( '[' );                                    if( squareBracketBeginIndex != -1 ) {                                        // ipv6Host should be enclosed in                                        // [ ], if not it will result in a                                        // BAD_PARAM exception                                        String ipv6Port = getIPV6Port( host );                                        if( ipv6Port != null ) {                                            port = Integer.parseInt( ipv6Port );                                        }                                        host = getIPV6Host( host );                                    } else { 				        // If there is a colon, Make sure what				        // follows after colon is indeed a                                         // Integer If it is not then we have an                                        // invalid port number				        int colon = host.indexOf( ':' );				        if( colon != -1 ) {				 	    port = Integer.parseInt(					            host.substring( colon+1) );					    host = host.substring( 0, colon );                                       }				    }				}			    } catch( Exception e ) {				// Any kind of Exception is bad here.                                org.omg.CORBA.BAD_PARAM exception = 				    new org.omg.CORBA.BAD_PARAM(				        MinorCodes.INS_BAD_ADDRESS,                                        CompletionStatus.COMPLETED_NO);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?