KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > interop > rmi > iiop > server > ServerNamingContext


1 /**
2  *
3  * Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.geronimo.interop.rmi.iiop.server;
19
20 import javax.naming.NameNotFoundException JavaDoc;
21 import javax.naming.NamingException JavaDoc;
22
23 import org.apache.geronimo.interop.adapter.Adapter;
24 import org.apache.geronimo.interop.naming.NameService;
25 import org.apache.geronimo.interop.naming.NameServiceLog;
26 import org.apache.geronimo.interop.rmi.iiop.CorbaObject;
27 import org.omg.CosNaming.BindingIteratorHolder JavaDoc;
28 import org.omg.CosNaming.BindingListHolder JavaDoc;
29 import org.omg.CosNaming.NameComponent JavaDoc;
30 import org.omg.CosNaming.NamingContext JavaDoc;
31 import org.omg.CosNaming.NamingContextExt JavaDoc;
32 import org.omg.CosNaming.NamingContextExtPackage.InvalidAddress JavaDoc;
33 import org.omg.CosNaming.NamingContextPackage.AlreadyBound JavaDoc;
34 import org.omg.CosNaming.NamingContextPackage.CannotProceed JavaDoc;
35 import org.omg.CosNaming.NamingContextPackage.InvalidName JavaDoc;
36 import org.omg.CosNaming.NamingContextPackage.NotFound JavaDoc;
37 import org.omg.CosNaming.NamingContextPackage.NotFoundReason JavaDoc;
38 import org.omg.CosNaming.NamingContextPackage.NotEmpty JavaDoc;
39
40 public class ServerNamingContext extends CorbaObject implements NamingContextExt JavaDoc {
41
42     private NameService nameService;
43     protected static ServerNamingContext snc = null;
44
45     public ServerNamingContext()
46     {
47         nameService = NameService.getInstance();
48     }
49
50     public org.omg.CORBA.Object JavaDoc resolve_str(String JavaDoc name) throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc {
51         return lookup(name, null);
52     }
53
54     public String JavaDoc to_string(NameComponent JavaDoc[] n) throws InvalidName JavaDoc {
55         throw NoImplement();
56     }
57
58     public NameComponent JavaDoc[] to_name(String JavaDoc sn) throws InvalidName JavaDoc {
59         throw NoImplement();
60     }
61
62     public String JavaDoc to_url(String JavaDoc addr, String JavaDoc sn) throws InvalidAddress JavaDoc, InvalidName JavaDoc {
63         throw NoImplement();
64     }
65
66     public org.omg.CORBA.Object JavaDoc resolve(NameComponent JavaDoc[] name) throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc {
67         return lookup(toString(name), name);
68     }
69
70     public void bind(NameComponent JavaDoc[] n, org.omg.CORBA.Object JavaDoc obj) throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc, AlreadyBound JavaDoc {
71         throw NoImplement();
72     }
73
74     public void bind_context(NameComponent JavaDoc[] n, NamingContext JavaDoc nc) throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc, AlreadyBound JavaDoc {
75         throw NoImplement();
76     }
77
78     public void rebind(NameComponent JavaDoc[] n, org.omg.CORBA.Object JavaDoc obj) throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc {
79         throw NoImplement();
80     }
81
82     public void rebind_context(NameComponent JavaDoc[] n, NamingContext JavaDoc nc) throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc {
83         throw NoImplement();
84     }
85
86     public void unbind(NameComponent JavaDoc[] n) throws NotFound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc {
87         throw NoImplement();
88     }
89
90     public void list(int how_many, BindingListHolder JavaDoc bl, BindingIteratorHolder JavaDoc bi) {
91         throw NoImplement();
92     }
93
94     public NamingContext JavaDoc new_context() {
95         throw NoImplement();
96     }
97
98     public NamingContext JavaDoc bind_new_context(NameComponent JavaDoc[] n) throws NotFound JavaDoc, AlreadyBound JavaDoc, CannotProceed JavaDoc, InvalidName JavaDoc {
99         throw NoImplement();
100     }
101
102     public void destroy() throws NotEmpty JavaDoc {
103         //TODO what should this do?
104
}
105
106     protected org.omg.CORBA.NO_IMPLEMENT JavaDoc NoImplement() {
107         return new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
108     }
109
110     protected org.omg.CORBA.Object JavaDoc lookup(String JavaDoc nameString, NameComponent JavaDoc[] name) throws NotFound JavaDoc {
111         try {
112             Object JavaDoc object = nameService.lookup(nameString);
113
114             if (object instanceof Adapter) {
115                 Adapter a = (Adapter) object;
116                 //RemoteInterface remote = a.getRemoteInterface();
117
//return remote.$getObjectRef();
118
return a.getObjectRef();
119             } else {
120                 NameServiceLog.getInstance().warnObjectHasNoRemoteInterface(nameString, object.getClass().getName());
121                 throw new NotFound JavaDoc(NotFoundReason.not_object, name);
122             }
123         } catch (NameNotFoundException JavaDoc notFound) {
124             // Assume warning message has already been logged.
125
throw new NotFound JavaDoc(NotFoundReason.missing_node, name);
126         } catch (NamingException JavaDoc ex) {
127             NameServiceLog.getInstance().warnNameNotFound(nameString, ex);
128             throw new NotFound JavaDoc(NotFoundReason.missing_node, name);
129         }
130     }
131
132     protected String JavaDoc toString(NameComponent JavaDoc[] name) {
133         int n = name.length;
134         if (n == 1) {
135             return name[0].id;
136         } else {
137             StringBuffer JavaDoc nameBuffer = new StringBuffer JavaDoc();
138             for (int i = 0; i < n; i++) {
139                 if (i > 0) {
140                     nameBuffer.append('/');
141                 }
142                 nameBuffer.append(name[i].id);
143                 if (name[i].kind.length() > 0) {
144                     nameBuffer.append(",kind=");
145                     nameBuffer.append(name[i].kind);
146                 }
147             }
148             return nameBuffer.toString();
149         }
150     }
151 }
152
Popular Tags