initialnamingclient.java

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

JAVA
1,249
字号
      *  service name (identifier) under -ORBInitRef.      *  If there is one, It parses and tries to resolve the reference with      *  the given ORBInitDef definition.      *  returns the Stringified Object reference if successful in resolving,      *  Null is returned otherwise.      */     private String resolveUsingORBInitRef( String identifier ) {	String sresult = null;	org.omg.CORBA.Object result = null;	Object URLValue = orbInitRefList.get( identifier );	if( URLValue != null ) {	    CorbaLoc CorbaLocInstance = new CorbaLoc( );	    CorbaName CorbaNameInstance = new CorbaName( );	    // Check whether the URLValue is a CorbaLoc object	    if( URLValue.getClass().isInstance((Object) CorbaLocInstance ) ) {	        sresult = resolveCorbaloc( (CorbaLoc) URLValue );	    } else if( URLValue.getClass().isInstance((Object)                    CorbaNameInstance ) )	    {	        // Check whether the URLValue is a CorbaName object		org.omg.CORBA.Object theObject =                    resolveCorbaname( (CorbaName) URLValue );		try {		    sresult = orb.object_to_string( theObject );		} catch( Exception e ) {                    sresult = null;		}	    } else { 	        // It has to be IOR otherwise	        sresult = (String) URLValue;	    }	}	return sresult;     }     String resolveCorbaloc( CorbaLoc theCorbaLocObject ) {	String sresult = null;	// If RIR flag is true use the Bootstrap protocol	if( theCorbaLocObject.getRIRFlag( ) == true )  {	    sresult =               resolveUsingBootstrapProtocol(theCorbaLocObject.getKeyString());	} else {	    sresult = getIORUsingHostInfo( theCorbaLocObject.getHostInfo(),	  	theCorbaLocObject.getKeyString() );	}	return sresult;     }     private String getIORUsingHostInfo( java.util.Vector theHostInfo,         String theKeyString )     {        // If there is no KeyString then it's invalid        if( theKeyString == null ) {            return null;        }	String sresult = null;	IOR theIOR = null;	for( int i = 0; (i < theHostInfo.size()) && (theIOR == null ); i++ ) {	    HostInfo element = (HostInfo) theHostInfo.elementAt( i );	    theIOR = new IOR( orb, "", element.getHostName(),                     element.getPortNumber(), element.getMajorNumber(),		     element.getMinorNumber(), theKeyString, null );	    //First check whether there is a server listening for Locate Request	    //for the given key at Host and Port specified in the URL	    //If there is a server, then decide whether the IOR is valid or            //not	    theIOR = locateObject( theIOR, theKeyString.getBytes());	    if( theIOR != null ) {	        sresult = theIOR.stringify();	    }	}	return sresult;     }     org.omg.CORBA.Object resolveCorbaname( CorbaName theCorbaName ) {	org.omg.CORBA.Object result = null;	CorbaLoc theCorbaLoc = theCorbaName.getCorbaLoc( );	if( theCorbaLoc == null ) {	    return null;	}	// Case 1 of corbaname: rir#	if( theCorbaLoc.getRIRFlag( ) == true ) {	    try {		NamingContextExt theNamingContext =		    getDefaultRootNamingContext( );		String StringifiedName = theCorbaName.getStringifiedName( );		if( StringifiedName == null ) {		    // This means return the Root Naming context		    result = theNamingContext;		} else {		    result = theNamingContext.resolve_str( StringifiedName );		}	    } catch( Exception e ) {	        result = null;	    }	} else  {	    // Case 2 of corbaname: ::hostname#	    try {		String sresult = getIORUsingHostInfo( theCorbaLoc.getHostInfo(),                    theCorbaLoc.getKeyString() );		if( sresult != null ) {		    org.omg.CORBA.Object theObject =                        orb.string_to_object( sresult );		    if( theObject != null ) {		        NamingContextExt theNamingContext =			    NamingContextExtHelper.narrow( theObject );		        if( theNamingContext != null ) {		            String StringifiedName =                                theCorbaName.getStringifiedName( );                            //Return Root Naming Context if the Stringified Name                            // is null.                            result = theNamingContext;                            if( StringifiedName != null ) {		                result =                                    theNamingContext.resolve_str(                                        StringifiedName );                            }		        }	            }	        }	    } catch( Exception e ) {	        result = null;	    }	}	return result;     }     private java.util.Vector getHostNamesFromURL(String theHostPartOfURLString)     {	java.util.Vector theHosts = new java.util.Vector();	boolean nomoreCommas = false;	int index = 0;	for( int i = 0; (i < theHostPartOfURLString.length())                               && (nomoreCommas == false);  )	{	    int theCommaIndex = theHostPartOfURLString.indexOf( ',', index );	    if( theCommaIndex == -1 ) {	        // There are no more Hostnames and hence set the flag to true		// also get the Hostname and add it into the list.		nomoreCommas = true;		String temp = theHostPartOfURLString.substring( index );		theHosts.addElement( temp );	    } else {	        // Found a comma, which means there is a hostname after comma		// hence get the substring mapping to one of the hostname and		// port number.		String temp = theHostPartOfURLString.substring( index,			                                        theCommaIndex );		theHosts.addElement( temp );		index = theCommaIndex + 1;	    }	}	return theHosts;     }     private String resolveUsingBootstrapProtocol( String identifier ) {        String stringifiedReference = null;        // Use bootstrap protocol        org.omg.CORBA.Object result =            resolve(identifier, orb.getORBInitialHost(), initialServicesPort);        if (result != null) {	    stringifiedReference = orb.object_to_string( result );        }	return stringifiedReference;     }     private org.omg.CORBA.Object resolveIOR( String URLValue ) {	return null;     }     private NamingContextExt getDefaultRootNamingContext( ) {	if( rootNamingContextExt == null ) {	    try {	        rootNamingContextExt =	  	    NamingContextExtHelper.narrow(		    this.resolve_initial_references( "NameService" ) );	    } catch( Exception e ) {	        rootNamingContextExt = null;	    }        }	return rootNamingContextExt;     }     private String resolveUsingORBDefaultInitRef( String identifier ) {	// If the ORBDefaultInitDef is not defined simply return null	if( orbDefaultInitRef == null ) {		return null;	}	// If the ORBDefaultInitDef is  defined as corbaloc: then create the	// corbaloc String in the format        // <ORBInitDefaultInitDef Param>/<Identifier>	// and resolve it using resolveCorbaloc method	if( orbDefaultInitRef.startsWith( "corbaloc:" ) ) {	    String theCorbaLocString = orbDefaultInitRef + "/" + identifier;	    CorbaLoc theCorbaLoc = checkcorbalocGrammer( theCorbaLocString );	    if( theCorbaLoc != null ) {	        // We are just passing the string after 'corbaloc:'                // for resolution		return resolveCorbaloc( theCorbaLoc );	    } else {		return null;	    }	}	// If the ORBDefaultInitDef is  defined as corbaname: then create the	// corbaloc String in the format        // <ORBInitDefaultInitDef Param>#<Identifier>	// and resolve it using resolveCorbaname method	if( orbDefaultInitRef.startsWith( "corbaname:" ) ) {	    String theCorbaNameString = orbDefaultInitRef + "#" + identifier;	    CorbaName theCorbaName = checkcorbanameGrammer(theCorbaNameString);	    if( theCorbaName != null ) {		org.omg.CORBA.Object theObject =		    resolveCorbaname(theCorbaName );		if( theObject != null ) {		    return orb.object_to_string( theObject );		}	    } else {		return null;	    }	}	return null;     }     /** Locate Object returns true, If there is a Server listening at Host and      *  Port specified in the IOR and ObjectKey is valid. If not, then the      *  locate request will result in GIOPLocateReplyUnknownObject, in which      *  case a false is returned resulting in null IOR being returned.      */     private IOR locateObject( IOR ior, byte[] theObjectKey ) {	IOR theNewIOR = null;	LocateRequestMessage msg;        com.sun.corba.se.internal.iiop.IIOPOutputStream os;        com.sun.corba.se.internal.iiop.IIOPInputStream is;	try {	    ClientGIOP giop = orb.getClientGIOP();            Connection conn = giop.getConnection( ior );	    int id = giop.allocateRequestId() ;            GIOPVersion requestVersion =                GIOPVersion.chooseRequestVersion(orb, ior);            msg = MessageBase.createLocateRequest(                    (com.sun.corba.se.internal.iiop.ORB) orb, requestVersion,                    id, theObjectKey);            // This chooses the right buffering strategy for the locate msg.            // locate msgs 1.0 & 1.1 :=> grow, 1.2 :=> stream            os = com.sun.corba.se.internal.iiop.IIOPOutputStream.                    createIIOPOutputStreamForLocateMsg(                            requestVersion,                            (com.sun.corba.se.internal.iiop.ORB) orb, conn);            os.setMessage(msg);            msg.write(os);            is = conn.send(os, false);       	    LocateReplyMessage reply;            reply = (LocateReplyMessage) is.getMessage();	    switch(reply.getReplyStatus()) {	        case LocateReplyMessage.UNKNOWN_OBJECT :	            theNewIOR = null;    		    break;		case LocateReplyMessage.OBJECT_FORWARD :                case LocateReplyMessage.OBJECT_FORWARD_PERM :                    theNewIOR = reply.getIOR();		    break;		case LocateReplyMessage.OBJECT_HERE :                    theNewIOR = ior;                    break;		default:                    theNewIOR = null;                    break;	    }	} catch( Exception e ) {	    theNewIOR = null;	}	return theNewIOR;     }    /**     * Get a list of the initially available CORBA services.     * This does not work unless an ORBInitialHost is specified during     * initialization     * (or unless there is an ORB running on the AppletHost) since the     * localhostname is inaccessible to applets. If a service properties URL     * was specified then it is used, otherwise the bootstrapping protocol is     * used.     * @return A list of the initial services available.     */    String[] list_initial_services () {        // Call real function        return this.cachedServices();    }    private Properties getServicesFromURL() {        if ( resolvedInitialReferences == null ) {            try {		// Open connection		URLConnection urlc = servicesURL.openConnection();		java.io.InputStream is = urlc.getInputStream();		// Create and load properties		Properties serviceProps = new Properties();		serviceProps.load(is);		resolvedInitialReferences = serviceProps;

⌨️ 快捷键说明

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