1 7 8 package com.sun.corba.se.impl.naming.namingutil; 9 10 import java.util.*; 11 12 import com.sun.corba.se.spi.logging.CORBALogDomains ; 13 import com.sun.corba.se.impl.logging.NamingSystemException ; 14 15 22 public class CorbalocURL extends INSURLBase 23 { 24 static NamingSystemException wrapper = NamingSystemException.get( 25 CORBALogDomains.NAMING_READ ) ; 26 27 32 public CorbalocURL( String aURL ) { 33 String url = aURL; 34 35 if( url != null ) { 36 try { 37 url = Utility.cleanEscapes( url ); 39 } catch( Exception e ) { 40 badAddress( e ); 43 } 44 int endIndex = url.indexOf( '/' ); 45 if( endIndex == -1 ) { 46 endIndex = url.length(); 48 } 49 if( endIndex == 0 ) { 51 badAddress( null ); 53 } 54 StringTokenizer endpoints = new StringTokenizer( 57 url.substring( 0, endIndex ), "," ); 58 while( endpoints.hasMoreTokens( ) ) { 64 String endpointInfo = endpoints.nextToken(); 65 IIOPEndpointInfo iiopEndpointInfo = null; 66 if( endpointInfo.startsWith( "iiop:" ) ) { 67 iiopEndpointInfo = handleIIOPColon( endpointInfo ); 68 } else if( endpointInfo.startsWith( "rir:" ) ) { 69 handleRIRColon( endpointInfo ); 70 rirFlag = true; 71 } else if( endpointInfo.startsWith( ":" ) ) { 72 iiopEndpointInfo = handleColon( endpointInfo ); 73 } else { 74 badAddress( null ); 78 } 79 if ( rirFlag == false ) { 80 if( theEndpointInfo == null ) { 84 theEndpointInfo = new java.util.ArrayList ( ); 85 } 86 theEndpointInfo.add( iiopEndpointInfo ); 87 } 88 } 89 if( url.length() > (endIndex + 1) ) { 92 theKeyString = url.substring( endIndex + 1 ); 93 } 94 } 95 } 96 97 98 102 private void badAddress( java.lang.Throwable e ) 103 { 104 throw wrapper.insBadAddress( e ) ; 105 } 106 107 111 private IIOPEndpointInfo handleIIOPColon( String iiopInfo ) 112 { 113 iiopInfo = iiopInfo.substring( NamingConstants.IIOP_LENGTH ); 115 return handleColon( iiopInfo ); 116 } 117 118 119 123 private IIOPEndpointInfo handleColon( String iiopInfo ) { 124 iiopInfo = iiopInfo.substring( 1 ); 126 String hostandport = iiopInfo; 127 StringTokenizer tokenizer = new StringTokenizer( iiopInfo, "@" ); 129 IIOPEndpointInfo iiopEndpointInfo = new IIOPEndpointInfo( ); 130 int tokenCount = tokenizer.countTokens( ); 131 if( ( tokenCount == 0 ) 138 ||( tokenCount > 2 )) 139 { 140 badAddress( null ); 141 } 142 if( tokenCount == 2 ) { 143 String version = tokenizer.nextToken( ); 145 int dot = version.indexOf('.'); 146 if (dot == -1) { 149 badAddress( null ); 150 } 151 try { 152 iiopEndpointInfo.setVersion( 153 Integer.parseInt( version.substring( 0, dot )), 154 Integer.parseInt( version.substring(dot+1)) ); 155 hostandport = tokenizer.nextToken( ); 156 } catch( Throwable e ) { 157 badAddress( e ); 158 } 159 } 160 try { 161 int squareBracketBeginIndex = hostandport.indexOf ( '[' ); 165 if( squareBracketBeginIndex != -1 ) { 166 String ipv6Port = getIPV6Port( hostandport ); 170 if( ipv6Port != null ) { 171 iiopEndpointInfo.setPort( Integer.parseInt( ipv6Port )); 172 } 173 iiopEndpointInfo.setHost( getIPV6Host( hostandport )); 174 return iiopEndpointInfo; 175 } 176 tokenizer = new StringTokenizer( hostandport, ":" ); 177 if( tokenizer.countTokens( ) == 2 ) { 183 iiopEndpointInfo.setHost( tokenizer.nextToken( ) ); 185 iiopEndpointInfo.setPort( Integer.parseInt( 186 tokenizer.nextToken( ))); 187 } else { 188 if( ( hostandport != null ) 189 &&( hostandport.length() != 0 ) ) 190 { 191 iiopEndpointInfo.setHost( hostandport ); 195 } 196 } 200 } catch( Throwable e ) { 201 badAddress( e ); 205 } 206 Utility.validateGIOPVersion( iiopEndpointInfo ); 207 return iiopEndpointInfo; 208 } 209 210 213 private void handleRIRColon( String rirInfo ) 214 { 215 if( rirInfo.length() != NamingConstants.RIRCOLON_LENGTH ) { 216 badAddress( null ); 217 } 218 } 219 220 226 private String getIPV6Port( String endpointInfo ) 227 { 228 int squareBracketEndIndex = endpointInfo.indexOf ( ']' ); 229 if( (squareBracketEndIndex + 1) != (endpointInfo.length( )) ) { 233 if( endpointInfo.charAt( squareBracketEndIndex + 1 ) != ':' ) { 234 throw new RuntimeException ( 235 "Host and Port is not separated by ':'" ); 236 } 237 return endpointInfo.substring( squareBracketEndIndex + 2 ); 241 } 242 return null; 243 } 244 245 246 252 private String getIPV6Host( String endpointInfo ) { 253 int squareBracketEndIndex = endpointInfo.indexOf ( ']' ); 257 String ipv6Host = endpointInfo.substring( 1, squareBracketEndIndex ); 259 return ipv6Host; 260 } 261 262 265 public boolean isCorbanameURL( ) { 266 return false; 267 } 268 269 270 } 271 | Popular Tags |