initialnamingclient.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,249 行 · 第 1/4 页
JAVA
1,249 行
exception.initCause(e); throw exception; } } else { try { String version = hostName.substring( 5, at ); int dot = version.indexOf('.'); // There is a version without ., which means // Malformed list if (dot < 0) { theCorbaLocObject = null; } else { // Substring after iiop: and before . which // will be a major number (IIOP version). major = Integer.parseInt( version.substring(0, dot)); minor = Integer.parseInt( version.substring(dot+1)); validateGIOPVersion(major, minor); // A Hack to differentiate IPV6 address // from IPV4 address, Current Resolution // is to use [ ] to differentiate ipv6 host int squareBracketBeginIndex = hostName.indexOf ( '[' ); if( squareBracketBeginIndex != -1 ) { // hostName info conatins iiop version, // get the hostinfo using the '[' token host = hostName.substring( squareBracketBeginIndex ); // 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 { host = hostName.substring( at+1 ); int colon = host.indexOf( ':' ); if( colon != -1 ) { port = Integer.parseInt( host.substring( colon+1) ); host = host.substring( 0, colon ); } } } } // Any kind of exception is bad here, It could be // number format exception or Null String exception catch( Exception e ) { org.omg.CORBA.BAD_PARAM exception = new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_ADDRESS, CompletionStatus.COMPLETED_NO); exception.initCause(e); throw exception; } } } else if( hostName.startsWith( "rir:" ) ) { //Check the rir syntax try { String afterRIR = hostName.substring( 4 ); // There should not be anything after rir:, If // there is something. // Then we have an invalid URL if( afterRIR.length() != 0 ) { throw new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); } else { theCorbaLocObject.setRIRFlag( ); } } catch( Exception e ) { // Any exception is bad here org.omg.CORBA.BAD_PARAM exception = new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); exception.initCause(e); throw exception; } } else if( hostName.startsWith( ":" ) ) { // Check the default iiop syntax try { // String after : host = hostName.substring( 1 ); // It is invalid to have a url in the form // corbaloc::rir:,:/<ObjectKey> // Bug Fix: 4404982 if( ( host == null ) ||( host.length() == 0 ) ) { throw new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); } // @ in Hostname is invalid int at = host.indexOf( '@' ); if( at != -1 ) { try { // GIOP Version number like 1.2 // will be decoded as major = 1 and // minor 2. major = Integer.parseInt( host.substring(0, 1)); minor = Integer.parseInt( host.substring(2, 3)); validateGIOPVersion( major, minor ); // Host Info will be after @ host = hostName.substring( at + 2 ); } catch( Exception e ) { // Any Exception is bad here, Possible cause // could be a malformed GIOP Version. org.omg.CORBA.BAD_PARAM exception = new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); exception.initCause(e); throw exception; } } // If there is a colon, Make sure to check // that the string after : is indeed number // So that we can use it as Port Number int colon = host.indexOf( ':' ); if( colon != -1 ) { port = Integer.parseInt( host.substring( colon+1) ); host = host.substring( 0, colon ); } } catch( Exception e ) { org.omg.CORBA.BAD_PARAM exception = new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); exception.initCause(e); throw exception; } } else { // Right now we are not allowing any other protocol // other than iiop:, rir: so raise exception indicating // that the URL is malformed throw new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); } if( ( theCorbaLocObject != null ) &&( theCorbaLocObject.getRIRFlag() == false ) ) { // Add the Host information if RIR flag is set, // If RIR is set then it means use the internal Boot // Strap protocol for Key String resolution HostInfo newHostInfo = new HostInfo( ); newHostInfo.setVersion( major, minor ); newHostInfo.setHostName( host ); newHostInfo.setPortNumber( port ); theCorbaLocObject.addHostInfo( newHostInfo ); } } if( theCorbaLocObject != null ) { try { String keyString = null; // _REVISIT_ Clean up the logic here to make it // more readable. // If there is nothing after corbaloc:hostinfo/ // then NameService is the default KeyString if( value.length() <= (endIndex + 1) ) { keyString = "NameService"; } else { keyString = value.substring( endIndex + 1 ); } theCorbaLocObject.setKeyString( keyString ); } catch( Exception e ) { org.omg.CORBA.BAD_PARAM exception = new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); exception.initCause(e); throw exception; } } else { // The URL doesn't have a Slash after corbaloc or has a // slash at the wrong place. throw new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); } } } return theCorbaLocObject; } /** * Returns an IPV6 Host that is inside [ ] tokens. There is no validation * done here, if it is an incorrect IPV6 address then the request through * this URL results in a COMM_FAILURE, otherwise malformed list will * result in BAD_PARAM exception thrown in checkcorbalocGrammer. */ private String getIPV6Host( String endpointInfo ) { // ipv6Host should be enclosed in // [ ], if not it will result in a // BAD_PARAM exception int squareBracketEndIndex = endpointInfo.indexOf ( ']' ); // get the host between [ ] String ipv6Host = endpointInfo.substring( 1, squareBracketEndIndex ); return ipv6Host; } /** * Returns an IPV6 Port that is after [<ipv6>]:. There is no validation * done here, if it is an incorrect port then the request through * this URL results in a COMM_FAILURE, otherwise malformed list will * result in BAD_PARAM exception thrown in checkcorbalocGrammer. */ private String getIPV6Port( String endpointInfo ) { int squareBracketEndIndex = endpointInfo.indexOf ( ']' ); // If there is port information, then it has to be after ] bracket // indexOf returns the count from the index of zero as the base, so // equality check requires squareBracketEndIndex + 1. if( (squareBracketEndIndex + 1) != (endpointInfo.length( )) ) { if( endpointInfo.charAt( squareBracketEndIndex + 1 ) != ':' ) { throw new RuntimeException( "Host and Port is not separated by ':'" ); } // PortInformation should be after ']:' delimiter // If there is an exception then it will be caught in // checkcorbaGrammer method and rethrown as BAD_PARAM return endpointInfo.substring( squareBracketEndIndex + 2 ); } return null; } /** Quickly check whether the given corbaname is valid * return true if it is and false otherwise */ public CorbaName checkcorbanameGrammer( String value ) throws org.omg.CORBA.BAD_PARAM { CorbaName theCorbaNameObject = null; // First Clean the URL Escapes if there are any try { value = decode( value ); } catch( Exception e ) { throw new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); } int index = value.indexOf( '#' ); if( index != -1 ) { try { // Append corbaloc: for Grammer check, Get the string between // corbaname: and # which forms the corbaloc string String corbalocString = "corbaloc:" + value.substring( 10, index ) + "/"; // Check the corbaloc grammer and set the returned corbaloc // object to the CorbaName Object CorbaLoc theCorbaLocObject = checkcorbalocGrammer( corbalocString ); if( theCorbaLocObject != null ) { theCorbaNameObject = new CorbaName( ); theCorbaNameObject.setCorbaLoc( theCorbaLocObject ); // String after '#' is the Stringified name used to resolve // the Object reference from the rootnaming context. If // the String is null then the Root Naming context is passed // back String StringifiedName = value.substring( index + 1 ); if(( StringifiedName != null ) && ( StringifiedName.length() != 0 ) ) { theCorbaNameObject.setStringifiedName(StringifiedName); } } } catch( Exception e ) { // Any kind of exception is bad here throw new org.omg.CORBA.BAD_PARAM( MinorCodes.INS_BAD_SCHEME_SPECIFIC_PART, CompletionStatus.COMPLETED_NO); } } // This is the case with no # in the string else { // Build a corbaloc string to check the grammer. // 10 is the length of corbaname: String corbalocString = "corbaloc:" + value.substring( 10, value.length() ); // If the string doesnot end with a / then add one to end the // URL correctly if( corbalocString.endsWith( "/" ) != true ) { corbalocString = corbalocString + "/"; } // Check the corbaloc grammer and set the returned corbaloc // object to the CorbaName Object CorbaLoc theCorbaLocObject = checkcorbalocGrammer( corbalocString ); if( theCorbaLocObject != null ) { theCorbaNameObject = new CorbaName( ); theCorbaNameObject.setCorbaLoc( theCorbaLocObject ); // If the Key String is null then the Root Naming context // is passed back //theCorbaNameObject.setStringifiedName(null); } } return theCorbaNameObject; } /** resolveUsingORBInitRef is called first when ever * resolve_initial_reference is called. * This method, checks to see if there is an entry for the requested
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?