KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jndi > url > corbaname > CorbanameUrl


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.jndi.url.corbaname;
25
26 import javax.naming.Name JavaDoc;
27 import javax.naming.NameParser JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29
30 import java.net.MalformedURLException JavaDoc;
31 import com.sun.jndi.toolkit.url.UrlUtil;
32 import com.sun.jndi.cosnaming.CNNameParser;
33
34 //START OF IASRI 4660742
35
import java.util.logging.*;
36 import com.sun.logging.*;
37 //END OF IASRI 4660742
38

39
40 /**
41  * Extract components of a "corbaname" URL.
42  *
43  * The format of an corbaname URL is defined in INS 99-12-03 as follows.
44  *<p>
45  * corbaname url = "corbaname:" <corbaloc_obj> ["#" <string_name>]
46  * corbaloc_obj = <obj_addr_list> ["/" <key_string>]
47  * obj_addr_list = as defined in a corbaloc URL
48  * key_string = as defined in a corbaloc URL
49  * string_name = stringified COS name | empty_string
50  *<p>
51  * Characters in <string_name> are escaped as follows.
52  * US-ASCII alphanumeric characters are not escaped. Any characters outside
53  * of this range are escaped except for the following:
54  * ; / : ? @ & = + $ , - _ . ! ~ * ; ( )
55  * Escaped characters is escaped by using a % followed by its 2 hexadecimal
56  * numbers representing the octet.
57  *<p>
58  * The corbaname URL is parsed into two parts: a corbaloc URL and a COS name.
59  * The corbaloc URL is constructed by concatenation "corbaloc:" with
60  * <corbaloc_obj>.
61  * The COS name is <string_name> with the escaped characters resolved.
62  *<p>
63  * A corbaname URL is resolved by:
64  *<ol>
65  *<li>Construct a corbaloc URL by concatenating "corbaloc:" and <corbaloc_obj>.
66  *<li>Resolve the corbaloc URL to a NamingContext by using
67  * nctx = ORB.string_to_object(corbalocUrl);
68  *<li>Resolve <string_name> in the NamingContext.
69  *</ol>
70  *
71  * @author Rosanna Lee
72  */

73
74 public final class CorbanameUrl {
75
76     // START OF IASRI 4660742
77
static Logger _logger=LogDomains.getLogger(LogDomains.JNDI_LOGGER);
78     // END OF IASRI 4660742
79

80     private String JavaDoc stringName;
81     private String JavaDoc location;
82
83     private static final NameParser JavaDoc parser = new CNNameParser();
84
85     /**
86      * Returns a possibly empty but non-null string that is the "string_name"
87      * portion of the URL.
88      */

89     public String JavaDoc getStringName() {
90     return stringName;
91     }
92
93     public Name JavaDoc getCosName() throws NamingException JavaDoc {
94     return parser.parse(stringName);
95     }
96
97     public String JavaDoc getLocation() {
98     return "corbaloc:" + location;
99     }
100
101     public CorbanameUrl(String JavaDoc url) throws MalformedURLException JavaDoc {
102
103     if (!url.startsWith("corbaname:")) {
104         throw new MalformedURLException JavaDoc("Invalid corbaname URL: " + url);
105     }
106
107     int addrStart = 10; // "corbaname:"
108

109     int addrEnd = url.indexOf('#', addrStart);
110     if (addrEnd < 0) {
111         addrEnd = url.length();
112         stringName = "";
113     } else {
114         stringName = UrlUtil.decode(url.substring(addrEnd+1));
115     }
116     location = url.substring(addrStart, addrEnd);
117     
118     int keyStart = location.indexOf("/");
119     if (keyStart >= 0) {
120         // Has key string
121
if (keyStart == (location.length() -1)) {
122         location += "NameService";
123         }
124     } else {
125         location += "/NameService";
126     }
127     }
128 /*
129     // for testing only
130     public static void main(String[] args) {
131     try {
132         CorbanameUrl url = new CorbanameUrl(args[0]);
133
134       // IASRI 4660742
135         //System.out.println("location: " + url.getLocation());
136         //System.out.println("string name: " + url.getStringName());
137       // IASRI 4660742
138       // START OF IASRI 4660742
139         if (_logger.isLoggable(Level.FINE)) {
140       _logger.log(Level.FINE,"location: " + url.getLocation());
141       _logger.log(Level.FINE,"string name: " + url.getStringName());
142         }
143       // END OF IASRI 4660742
144     } catch (MalformedURLException e) {
145       // IASRI 4660742
146         e.printStackTrace();
147       // IASRI 4660742
148       // START OF IASRI 4660742
149       _logger.log(Level.SEVERE,"java_jndi.excep_in_corbanameurl_main",e);
150       // END OF IASRI 4660742
151     }
152     }
153 */

154 }
155
Popular Tags