KickJava   Java API By Example, From Geeks To Geeks.

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


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.spi.ResolveResult JavaDoc;
27 import javax.naming.*;
28 import java.util.Hashtable JavaDoc;
29 import java.net.MalformedURLException JavaDoc;
30
31 import com.sun.jndi.cosnaming.IiopUrl;
32
33 /**
34  * A corbaname URL context.
35  *
36  * @author Rosanna Lee
37  */

38
39 public class corbanameURLContext
40     extends com.sun.jndi.toolkit.url.GenericURLContext {
41
42     corbanameURLContext(Hashtable JavaDoc env) {
43     super(env);
44     }
45
46     /**
47       * Resolves 'name' into a target context with remaining name.
48       * It only resolves the hostname/port number. The remaining name
49       * contains the rest of the name found in the URL.
50       *
51       * For example, with a corbaname URL
52       * "corbaname:iiop://localhost:900#rest/of/name",
53       * this method resolves "corbaname:iiop://localhost:900" to the "NameService"
54       * context on for the ORB at 'localhost' on port 900,
55       * and returns as the remaining name "rest/of/name".
56       */

57     protected ResolveResult JavaDoc getRootURLContext(String JavaDoc name, Hashtable JavaDoc env)
58     throws NamingException {
59     return corbanameURLContextFactory.getUsingURLIgnoreRest(name, env);
60     }
61
62     /**
63      * Return the suffix of a corbaname url.
64      * prefix parameter is ignored.
65      */

66     protected Name getURLSuffix(String JavaDoc prefix, String JavaDoc url)
67     throws NamingException {
68         // Rewrite to corbaname url
69
url = corbanameURLContextFactory.rewriteUrl(url);
70         try {
71         IiopUrl parsedUrl = new IiopUrl(url);
72         return parsedUrl.getCosName();
73         } catch (MalformedURLException JavaDoc e) {
74         throw new InvalidNameException(e.getMessage());
75         }
76     }
77
78     /**
79       * Finds the prefix of a corbaname URL.
80       * This is all of the non-string name portion of the URL.
81       * The string name portion always occurs after the '#'
82       * so we just need to look for that.
83       */

84     protected String JavaDoc getURLPrefix(String JavaDoc url) throws NamingException {
85     int start = url.indexOf('#');
86
87     if (start < 0) {
88         return url; // No '#', prefix is the entire URL
89
}
90
91     return url.substring(0, start);
92     }
93 }
94
Popular Tags