KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > naming > namingutil > CorbanameURL


1 /*
2  * @(#)CorbanameURL.java 1.7 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.naming.namingutil;
9
10 import com.sun.corba.se.impl.logging.NamingSystemException;
11 import com.sun.corba.se.spi.logging.CORBALogDomains;
12
13 /**
14  * The corbaname: URL definitions from the -ORBInitDef and -ORBDefaultInitDef's
15  * will be stored in this object. This object is capable of storing CorbaLoc
16  * profiles as defined in the CorbaName grammer.
17  *
18  * @Author Hemanth
19  */

20 public class CorbanameURL extends INSURLBase
21 {
22     private static NamingSystemException wrapper =
23     NamingSystemException.get( CORBALogDomains.NAMING ) ;
24
25     /**
26      * This constructor takes a corbaname: url with 'corbaname:' prefix stripped
27      * and initializes all the variables accordingly. If there are any parsing
28      * errors then BAD_PARAM exception is raised.
29      */

30     public CorbanameURL( String JavaDoc aURL ) {
31         String JavaDoc url = aURL;
32   
33         // First Clean the URL Escapes if there are any
34
try {
35             url = Utility.cleanEscapes( url );
36         } catch( Exception JavaDoc e ) {
37             badAddress( e );
38         }
39
40         int delimiterIndex = url.indexOf( '#' );
41         String JavaDoc corbalocString = null;
42         if( delimiterIndex != -1 ) {
43                 // Append corbaloc: for Grammar check, Get the string between
44
// corbaname: and # which forms the corbaloc string
45
corbalocString = "corbaloc:" +
46                     url.substring( 0, delimiterIndex ) + "/";
47         } else {
48             // Build a corbaloc string to check the grammar.
49
// 10 is the length of corbaname:
50
corbalocString = "corbaloc:" + url.substring( 0, url.length() );
51             // If the string doesnot end with a / then add one to end the
52
// URL correctly
53
if( corbalocString.endsWith( "/" ) != true ) {
54                 corbalocString = corbalocString + "/";
55             }
56         }
57         try {
58             // Check the corbaloc grammar and set the returned corbaloc
59
// object to the CorbaName Object
60
INSURL insURL =
61                 INSURLHandler.getINSURLHandler().parseURL( corbalocString );
62             copyINSURL( insURL );
63             // String after '#' is the Stringified name used to resolve
64
// the Object reference from the rootnaming context. If
65
// the String is null then the Root Naming context is passed
66
// back
67
if((delimiterIndex > -1) &&
68            (delimiterIndex < (aURL.length() - 1)))
69             {
70         int start = delimiterIndex + 1 ;
71         String JavaDoc result = url.substring(start) ;
72         theStringifiedName = result ;
73             }
74         } catch( Exception JavaDoc e ) {
75             badAddress( e );
76         }
77     }
78
79     /**
80      * A Utility method to throw BAD_PARAM exception.
81      */

82     private void badAddress( java.lang.Throwable JavaDoc e )
83         throws org.omg.CORBA.BAD_PARAM JavaDoc
84     {
85     throw wrapper.insBadAddress( e ) ;
86     }
87
88     /**
89      * A Utility method to copy all the variables from CorbalocURL object to
90      * this instance.
91      */

92     private void copyINSURL( INSURL url ) {
93         rirFlag = url.getRIRFlag( );
94         theEndpointInfo = (java.util.ArrayList JavaDoc) url.getEndpointInfo( );
95         theKeyString = url.getKeyString( );
96         theStringifiedName = url.getStringifiedName( );
97     }
98
99     public boolean isCorbanameURL( ) {
100         return true;
101     }
102
103 }
104
Popular Tags