initialnamingclient.java

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

JAVA
1,249
字号
		is.close();            } catch (java.io.IOException ex) {		throw new org.omg.CORBA.COMM_FAILURE(ex.toString(),	        com.sun.corba.se.internal.orbutil.MinorCodes.GET_PROPERTIES_ERROR,		     CompletionStatus.COMPLETED_NO);            }        }        return resolvedInitialReferences;    }    private synchronized String[] cachedServices() {        if ( listOfInitialServices == null ) {            String[] list = null;            if (( listOfInitialServices==null) && (servicesURL != null)) {                // A URL was given, so use it.                Properties serviceProps = getServicesFromURL();                // Create a list of strings (the keys) and copy entries                list = new String[serviceProps.size()];                Enumeration theKeys = serviceProps.keys();                for (int index=0;theKeys.hasMoreElements();index++) {                    list[index] = (String)theKeys.nextElement();                }            }            else {                list = getInitialServices(orb.getORBInitialHost(),					  initialServicesPort);            }            listOfInitialServices = list;        }        return listOfInitialServices;    }    String[] getInitialServices(String host, int port)     {	// REVISIT - this should be implemented using DII to avoid	// duplicating unnecessary exception handling code.	boolean remarshal = true;	// Create a delegate (subcontract) to invoke on	ClientDelegate sc = this.getInitialRep(host, port);	// Invoke.	InputStream is = null;	// If there is a location forward then you will need	// to invoke again on the updated information.	// Just calling this same routine with the same host/port	// does not take the location forward info into account.	while (remarshal) {	    remarshal = false;	    OutputStream os = (OutputStream) sc.createRequest("list", false);	    try {		// The only reason null is passed is to get the version of		// invoke used by streams.  Otherwise the PortableInterceptor		// call stack will become unbalanced since the version of		// invoke which only takes the stream does not call 		// PortableInterceptor ending points.		// Note that the first parameter is ignored inside invoke.		is = sc.invoke((org.omg.CORBA.Object)null, os);	    } catch (ApplicationException e) {		throw new INTERNAL("InitialNamingClient.getInitialServices: Caught an ApplicationException.  This should never happen.");	    } catch (RemarshalException e) {		remarshal = true;	    }	}	// Unmarshal String[].	int length = is.read_long();	String[] ret = new String[length];	for (int i=0; i<length; i++)	    ret[i] = is.read_string();	// List all the Services registered in the Bootstrap Registry	// + All the Services registered using ORBInitInfo	java.util.Set orbInitKeySet = orbInitRefList.keySet();	if( orbInitKeySet != null ) {	    String[] newList = new String[ret.length +					 orbInitKeySet.size() ];	    int i;	    for( i = 0; i < length; i++ ) {		newList[i] = ret[i];	    }	    Object[] temp = orbInitKeySet.toArray();	    for( i = length; i < (length + orbInitKeySet.size()); i++ ) {		newList[i] = (String) temp[i];	    }	    return newList;	}	return ret;    }    /**     * This creates a GIOP 1.0 IOR.     * Used to bootstrap request as a GIOP 1.0 request.     * This is to inter-operate with old Name Service     * implementations from SUN.      */    private ClientDelegate getInitialRep(String host, int port) {	// Create a representation (delegate) for the initial name server.	// Create a new IOR	byte[] initialKey = new byte[4];	initialKey[0] = 0x49; initialKey[1] = 0x4e;	initialKey[2] = 0x49; initialKey[3] = 0x54;	IOR initialIOR = new IOR(orb, "", host, port, 				 GIOPVersion.V1_0.getMajor(),				 GIOPVersion.V1_0.getMinor(),				 ObjectKeyFactory.get().create(orb,initialKey),				 null);        // Create a subcontract        ClientDelegate rep = new ClientDelegate(orb, initialIOR,	    SubcontractList.defaultSubcontract);        return rep;    }    /**     * Resolve the stringified reference of one of the initially     * available CORBA services.     * @param identifier The stringified object reference of the     * desired service.     * @return An object reference for the desired service.     * @exception InvalidName The supplied identifier is not associated     * with a known service.     * @exception SystemException One of a fixed set of Corba system exceptions.     */    org.omg.CORBA.Object resolve_initial_references(String identifier)        throws InvalidName    {        return cachedInitialReferences(identifier);    }    private org.omg.CORBA.Object resolve(String identifier, String host,					 int port)    {	// REVISIT - this should be implemented using DII to avoid	// duplicating unnecessary exception handling code.	boolean remarshal = true;	// URL not specified: do bootstrapping	ClientDelegate sc = this.getInitialRep(host, port);	// Invoke.	InputStream is = null;	// If there is a location forward then you will need	// to invoke again on the updated information.	// Just calling this same routine with the same host/port	// does not take the location forward info into account.	while (remarshal) {	    remarshal = false;	    OutputStream os = (OutputStream) sc.createRequest("get", false);	    os.write_string(identifier);	    try {		// The only reason null is passed is to get the version of		// invoke used by streams.  Otherwise the PortableInterceptor		// call stack will become unbalanced since the version of		// invoke which only takes the stream does not call 		// PortableInterceptor ending points.		// Note that the first parameter is ignored inside invoke.		is = sc.invoke((org.omg.CORBA.Object)null, os);	    } catch (ApplicationException e) {		throw new INTERNAL("InitialNamingClient.resolve: Caught an ApplicationException.  This should never happen.");	    } catch (RemarshalException e) {		remarshal = true;	    }	}	return is.read_Object();    }    org.omg.CORBA.Object resolve_initial_references(String identifier,							   String modifier)    	throws InvalidName    {        int ind = modifier.indexOf(":");        if (ind <= 0)            throw new DATA_CONVERSION(	        com.sun.corba.se.internal.orbutil.MinorCodes.BAD_MODIFIER,	        CompletionStatus.COMPLETED_NO);        try {            String hostName = modifier.substring(0,ind);            int port = java.lang.Integer.parseInt(modifier.substring(ind+1,	        modifier.length()));            return resolve_initial_references(identifier, hostName, port);        } catch (Exception e) {	    throw new DATA_CONVERSION(	        com.sun.corba.se.internal.orbutil.MinorCodes.BAD_MODIFIER,	        CompletionStatus.COMPLETED_NO);        }    }    org.omg.CORBA.Object resolve_initial_references(String identifier,       String host, int port)       throws InvalidName    {        org.omg.CORBA.Object result = resolve(identifier, host, port);        if (result == null)            throw new InvalidName();        return result;    }    private synchronized org.omg.CORBA.Object cachedInitialReferences(                                                      String identifier)        throws InvalidName    {        org.omg.CORBA.Object result = null;        String sresult = null;        // Check cache        if (resolvedInitialReferences != null)            sresult = resolvedInitialReferences.getProperty(identifier);        // Found it?        if (sresult == null)  {	    // First try to resolve the identifier using -ORBInitDef definition	    sresult = resolveUsingORBInitRef( identifier );	    if( sresult == null ) {		// Second try to resolve the identifier using                // -ORBDefaultInitDef definition		    sresult = resolveUsingORBDefaultInitRef( identifier );	    }	    if( sresult == null ) {		// Last try to resolve the identifier using BootStrap protocol		sresult = resolveUsingBootstrapProtocol( identifier );		if( sresult == null ) {		    // If all three paths fail, Throw an InvalidName exception                    throw new InvalidName();		}	    }	    try {       		result = orb.string_to_object(sresult);	    } catch( Exception e ) {		result = null;	    }       	    if (resolvedInitialReferences == null)           	resolvedInitialReferences = new java.util.Properties();       	    // Add to cached properties            if (sresult != null && sresult.length() > 0)           	resolvedInitialReferences.put(identifier,sresult);	} else  {            // Get from cache            result = orb.string_to_object(sresult);        }        return result;    }    /** If GIOP Version is not correct, This method throws a BAD_PARAM      * Exception.      */    private void validateGIOPVersion( int major, int minor ) {        if((major>ORBConstants.MAJORNUMBER_SUPPORTED)         ||(minor>ORBConstants.MINORNUMBERMAX ) )        {	    // Bad Version Number for IIOP	    throw new org.omg.CORBA.BAD_PARAM(	        MinorCodes.INS_BAD_ADDRESS,                CompletionStatus.COMPLETED_NO);        }    }    /** Decode method removes URL escapes as per IETF 2386 RFP.     */    private String decode( String stringToDecode ) {        StringWriter theStringWithoutEscape = new StringWriter();        for( int i = 0; i < stringToDecode.length(); i++ )        {            char c = stringToDecode.charAt( i ) ;            if( c != '%' ) {                theStringWithoutEscape.write( c );            } else {                // Get the two hexadecimal digits and convert that into int                i++;                int Hex1 = ORBUtility.hexOf( stringToDecode.charAt(i) );                i++;                int Hex2 = ORBUtility.hexOf( stringToDecode.charAt(i) );                int value = (Hex1 * 16) + Hex2;                // Convert the integer to ASCII                theStringWithoutEscape.write( (char) value );           }        }        return theStringWithoutEscape.toString();    }}

⌨️ 快捷键说明

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