1 /* 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.corba.se.impl.naming.namingutil; 27 28 import com.sun.corba.se.impl.logging.NamingSystemException; 29 import com.sun.corba.se.spi.logging.CORBALogDomains; 30 31 /** 32 * The corbaname: URL definitions from the -ORBInitDef and -ORBDefaultInitDef's 33 * will be stored in this object. This object is capable of storing CorbaLoc 34 * profiles as defined in the CorbaName grammer. 35 * 36 * @Author Hemanth 37 */ 38 public class CorbanameURL extends INSURLBase 39 { 40 private static NamingSystemException wrapper = 41 NamingSystemException.get( CORBALogDomains.NAMING ) ; 42 43 /** 44 * This constructor takes a corbaname: url with 'corbaname:' prefix stripped 45 * and initializes all the variables accordingly. If there are any parsing 46 * errors then BAD_PARAM exception is raised. 47 */ 48 public CorbanameURL( String aURL ) { 49 String url = aURL; 50 51 // First Clean the URL Escapes if there are any 52 try { 53 url = Utility.cleanEscapes( url ); 54 } catch( Exception e ) { 55 badAddress( e ); 56 } 57 58 int delimiterIndex = url.indexOf( '#' ); 59 String corbalocString = null; 60 if( delimiterIndex != -1 ) { 61 // Append corbaloc: for Grammar check, Get the string between 62 // corbaname: and # which forms the corbaloc string 63 corbalocString = "corbaloc:" + 64 url.substring( 0, delimiterIndex ) + "/"; 65 } else { 66 // Build a corbaloc string to check the grammar. 67 // 10 is the length of corbaname: 68 corbalocString = "corbaloc:" + url.substring( 0, url.length() ); 69 // If the string doesnot end with a / then add one to end the 70 // URL correctly 71 if( corbalocString.endsWith( "/" ) != true ) { 72 corbalocString = corbalocString + "/"; 73 } 74 } 75 try { 76 // Check the corbaloc grammar and set the returned corbaloc 77 // object to the CorbaName Object 78 INSURL insURL = 79 INSURLHandler.getINSURLHandler().parseURL( corbalocString ); 80 copyINSURL( insURL ); 81 // String after '#' is the Stringified name used to resolve 82 // the Object reference from the rootnaming context. If 83 // the String is null then the Root Naming context is passed 84 // back 85 if((delimiterIndex > -1) && 86 (delimiterIndex < (aURL.length() - 1))) 87 { 88 int start = delimiterIndex + 1 ; 89 String result = url.substring(start) ; 90 theStringifiedName = result ; 91 } 92 } catch( Exception e ) { 93 badAddress( e ); 94 } 95 } 96 97 /** 98 * A Utility method to throw BAD_PARAM exception. 99 */ 100 private void badAddress( java.lang.Throwable e ) 101 throws org.omg.CORBA.BAD_PARAM 102 { 103 throw wrapper.insBadAddress( e ) ; 104 } 105 106 /** 107 * A Utility method to copy all the variables from CorbalocURL object to 108 * this instance. 109 */ 110 private void copyINSURL( INSURL url ) { 111 rirFlag = url.getRIRFlag( ); 112 theEndpointInfo = (java.util.ArrayList) url.getEndpointInfo( ); 113 theKeyString = url.getKeyString( ); 114 theStringifiedName = url.getStringifiedName( ); 115 } 116 117 public boolean isCorbanameURL( ) { 118 return true; 119 } 120 121 }