KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > naming > remote > proxy > LocalContext


1 package org.sapia.ubik.rmi.naming.remote.proxy;
2
3 import java.lang.reflect.UndeclaredThrowableException JavaDoc;
4 import java.rmi.RemoteException JavaDoc;
5 import java.util.Hashtable JavaDoc;
6
7 import javax.naming.Context JavaDoc;
8 import javax.naming.Name JavaDoc;
9 import javax.naming.NameParser JavaDoc;
10 import javax.naming.NamingEnumeration JavaDoc;
11 import javax.naming.NamingException JavaDoc;
12
13 import org.sapia.archie.jndi.proxy.ContextProxy;
14 import org.sapia.ubik.mcast.DomainName;
15 import org.sapia.ubik.rmi.naming.remote.DomainInfo;
16 import org.sapia.ubik.rmi.naming.remote.RemoteContext;
17 import org.sapia.ubik.rmi.naming.remote.StubTweaker;
18 import org.sapia.ubik.rmi.server.StubContainer;
19
20
21 /**
22  * @author Yanick Duchesne
23  * <dl>
24  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
25  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
26  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
27  * </dl>
28  */

29 public class LocalContext extends ContextProxy implements java.rmi.Remote JavaDoc {
30   protected DomainName _domainName;
31   protected String JavaDoc _mcastAddress;
32   protected int _mcastPort;
33   protected String JavaDoc _url;
34
35   public LocalContext(String JavaDoc url, RemoteContext remote) throws NamingException JavaDoc {
36     super(remote);
37     _url = url;
38
39     DomainInfo info = remote.getDomainInfo();
40     _domainName = info.getDomainName();
41     _mcastAddress = info.getMulticastAddress();
42     _mcastPort = info.getMulticastPort();
43   }
44
45   /**
46    * @see javax.naming.Context#bind(Name, Object)
47    */

48   public void bind(Name JavaDoc n, Object JavaDoc o) throws NamingException JavaDoc {
49     rebind(n, o);
50   }
51
52   /**
53    * @see javax.naming.Context#bind(String, Object)
54    */

55   public void bind(String JavaDoc n, Object JavaDoc o) throws NamingException JavaDoc {
56     rebind(n, o);
57   }
58
59   /**
60    * @see javax.naming.Context#close()
61    */

62   public void close() throws NamingException JavaDoc {
63   }
64
65   /**
66    * @see javax.naming.Context#composeName(Name, Name)
67    */

68   public Name JavaDoc composeName(Name JavaDoc n1, Name JavaDoc n2) throws NamingException JavaDoc {
69     try {
70       return super.composeName(n1, n2);
71     } catch (UndeclaredThrowableException JavaDoc e) {
72       doFailOver(e);
73
74       return super.composeName(n1, n2);
75     }
76   }
77
78   /**
79    * @see javax.naming.Context#composeName(String, String)
80    */

81   public String JavaDoc composeName(String JavaDoc n1, String JavaDoc n2) throws NamingException JavaDoc {
82     try {
83       return super.composeName(n1, n2);
84     } catch (UndeclaredThrowableException JavaDoc e) {
85       doFailOver(e);
86
87       return super.composeName(n1, n2);
88     }
89   }
90
91   /**
92    * @see javax.naming.Context#createSubcontext(Name)
93    */

94   public Context JavaDoc createSubcontext(Name JavaDoc n) throws NamingException JavaDoc {
95     try {
96       return super.createSubcontext(n);
97     } catch (UndeclaredThrowableException JavaDoc e) {
98       doFailOver(e);
99
100       return super.createSubcontext(n);
101     }
102   }
103
104   /**
105    * @see javax.naming.Context#createSubcontext(String)
106    */

107   public Context JavaDoc createSubcontext(String JavaDoc name) throws NamingException JavaDoc {
108     try {
109       return super.createSubcontext(name);
110     } catch (UndeclaredThrowableException JavaDoc e) {
111       doFailOver(e);
112
113       return super.createSubcontext(name);
114     }
115   }
116
117   /**
118    * @see javax.naming.Context#destroySubcontext(Name)
119    */

120   public void destroySubcontext(Name JavaDoc n) throws NamingException JavaDoc {
121     try {
122       super.destroySubcontext(n);
123     } catch (UndeclaredThrowableException JavaDoc e) {
124       doFailOver(e);
125       super.destroySubcontext(n);
126     }
127   }
128
129   /**
130    * @see javax.naming.Context#destroySubcontext(String)
131    */

132   public void destroySubcontext(String JavaDoc name) throws NamingException JavaDoc {
133     try {
134       super.destroySubcontext(name);
135     } catch (UndeclaredThrowableException JavaDoc e) {
136       doFailOver(e);
137       super.destroySubcontext(name);
138     }
139   }
140
141   /**
142    * @see javax.naming.Context#getEnvironment()
143    */

144   public Hashtable JavaDoc getEnvironment() throws NamingException JavaDoc {
145     try {
146       return super.getEnvironment();
147     } catch (UndeclaredThrowableException JavaDoc e) {
148       doFailOver(e);
149
150       return super.getEnvironment();
151     }
152   }
153
154   /**
155    * @see javax.naming.Context#getNameInNamespace()
156    */

157   public String JavaDoc getNameInNamespace() throws NamingException JavaDoc {
158     try {
159       return super.getNameInNamespace();
160     } catch (UndeclaredThrowableException JavaDoc e) {
161       doFailOver(e);
162
163       return super.getNameInNamespace();
164     }
165   }
166
167   /**
168    * @see javax.naming.Context#getNameParser(Name)
169    */

170   public NameParser JavaDoc getNameParser(Name JavaDoc n) throws NamingException JavaDoc {
171     try {
172       return super.getNameParser(n);
173     } catch (UndeclaredThrowableException JavaDoc e) {
174       doFailOver(e);
175
176       return super.getNameParser(n);
177     }
178   }
179
180   /**
181    * @see javax.naming.Context#getNameParser(String)
182    */

183   public NameParser JavaDoc getNameParser(String JavaDoc name) throws NamingException JavaDoc {
184     try {
185       return super.getNameParser(name);
186     } catch (UndeclaredThrowableException JavaDoc e) {
187       doFailOver(e);
188
189       return super.getNameParser(name);
190     }
191   }
192
193   /**
194    * @see javax.naming.Context#list(Name)
195    */

196   public NamingEnumeration JavaDoc list(Name JavaDoc n) throws NamingException JavaDoc {
197     try {
198       return super.list(n);
199     } catch (UndeclaredThrowableException JavaDoc e) {
200       doFailOver(e);
201
202       return super.list(n);
203     }
204   }
205
206   /**
207    * @see javax.naming.Context#list(String)
208    */

209   public NamingEnumeration JavaDoc list(String JavaDoc name) throws NamingException JavaDoc {
210     try {
211       return super.list(name);
212     } catch (UndeclaredThrowableException JavaDoc e) {
213       doFailOver(e);
214
215       return super.list(name);
216     }
217   }
218
219   /**
220    * @see javax.naming.Context#listBindings(Name)
221    */

222   public NamingEnumeration JavaDoc listBindings(Name JavaDoc n) throws NamingException JavaDoc {
223     try {
224       return super.listBindings(n);
225     } catch (UndeclaredThrowableException JavaDoc e) {
226       doFailOver(e);
227
228       return super.listBindings(n);
229     }
230   }
231
232   /**
233    * @see javax.naming.Context#listBindings(String)
234    */

235   public NamingEnumeration JavaDoc listBindings(String JavaDoc name) throws NamingException JavaDoc {
236     try {
237       return super.listBindings(name);
238     } catch (UndeclaredThrowableException JavaDoc e) {
239       doFailOver(e);
240
241       return super.listBindings(name);
242     }
243   }
244
245   /**
246    * @see javax.naming.Context#lookup(Name)
247    */

248   public Object JavaDoc lookup(Name JavaDoc n) throws NamingException JavaDoc {
249     try {
250       return super.lookup(n);
251     } catch (UndeclaredThrowableException JavaDoc e) {
252       doFailOver(e);
253
254       return super.lookup(n);
255     }
256   }
257
258   /**
259    * @see javax.naming.Context#lookup(String)
260    */

261   public Object JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc {
262     try {
263       return super.lookup(name);
264     } catch (UndeclaredThrowableException JavaDoc e) {
265       doFailOver(e);
266
267       return super.lookup(name);
268     }
269   }
270
271   /**
272    * @see javax.naming.Context#lookupLink(Name)
273    */

274   public Object JavaDoc lookupLink(Name JavaDoc n) throws NamingException JavaDoc {
275     try {
276       return super.lookupLink(n);
277     } catch (UndeclaredThrowableException JavaDoc e) {
278       doFailOver(e);
279
280       return super.lookupLink(n);
281     }
282   }
283
284   /**
285    * @see javax.naming.Context#lookupLink(String)
286    */

287   public Object JavaDoc lookupLink(String JavaDoc name) throws NamingException JavaDoc {
288     try {
289       return super.lookup(name);
290     } catch (UndeclaredThrowableException JavaDoc e) {
291       doFailOver(e);
292
293       return super.lookup(name);
294     }
295   }
296
297   /**
298    * @see javax.naming.Context#rebind(Name, Object)
299    */

300   public void rebind(Name JavaDoc n, Object JavaDoc o) throws NamingException JavaDoc {
301     try {
302       super.rebind(n, o);
303     } catch (UndeclaredThrowableException JavaDoc e) {
304       doFailOver(e);
305       super.bind(n, o);
306     }
307   }
308
309   /**
310    * @see javax.naming.Context#rebind(String, Object)
311    */

312   public void rebind(String JavaDoc n, Object JavaDoc o) throws NamingException JavaDoc {
313     try {
314       super.rebind(n, o);
315     } catch (UndeclaredThrowableException JavaDoc e) {
316       doFailOver(e);
317       super.rebind(n, o);
318     }
319   }
320
321   /**
322    * @see javax.naming.Context#removeFromEnvironment(String)
323    */

324   public Object JavaDoc removeFromEnvironment(String JavaDoc name) throws NamingException JavaDoc {
325     try {
326       return super.removeFromEnvironment(name);
327     } catch (UndeclaredThrowableException JavaDoc e) {
328       doFailOver(e);
329
330       return super.removeFromEnvironment(name);
331     }
332   }
333
334   /**
335    * @see javax.naming.Context#rename(Name, Name)
336    */

337   public void rename(Name JavaDoc n1, Name JavaDoc n2) throws NamingException JavaDoc {
338     try {
339       super.rename(n1, n2);
340     } catch (UndeclaredThrowableException JavaDoc e) {
341       doFailOver(e);
342       super.rename(n1, n2);
343     }
344   }
345
346   /**
347    * @see javax.naming.Context#rename(String, String)
348    */

349   public void rename(String JavaDoc n1, String JavaDoc n2) throws NamingException JavaDoc {
350     try {
351       super.rename(n1, n2);
352     } catch (UndeclaredThrowableException JavaDoc e) {
353       doFailOver(e);
354       super.rename(n1, n2);
355     }
356   }
357
358   /**
359    * @see javax.naming.Context#unbind(Name)
360    */

361   public void unbind(Name JavaDoc n) throws NamingException JavaDoc {
362     try {
363       super.unbind(n);
364     } catch (UndeclaredThrowableException JavaDoc e) {
365       doFailOver(e);
366       super.unbind(n);
367     }
368   }
369
370   /**
371    * @see javax.naming.Context#unbind(String)
372    */

373   public void unbind(String JavaDoc name) throws NamingException JavaDoc {
374     try {
375       super.unbind(name);
376     } catch (UndeclaredThrowableException JavaDoc e) {
377       doFailOver(e);
378       super.unbind(name);
379     }
380   }
381
382   /**
383    * @see ContextProxy#onLookup(javax.naming.Name, java.lang.Object)
384    */

385   protected Object JavaDoc onLookup(Name JavaDoc name, Object JavaDoc obj) throws NamingException JavaDoc {
386     if (obj instanceof StubContainer) {
387       try {
388         return ((StubContainer) obj).toStub(Thread.currentThread()
389                                                   .getContextClassLoader());
390       } catch (RemoteException JavaDoc e) {
391         NamingException JavaDoc ne = new NamingException JavaDoc("Could not acquire stub");
392         ne.setRootCause(e);
393       }
394     }
395
396     return obj;
397   }
398
399   /**
400    * @see ContextProxy#onBind(javax.naming.Name, java.lang.Object)
401    */

402   protected Object JavaDoc onBind(Name JavaDoc n, Object JavaDoc toBind) throws NamingException JavaDoc {
403     toBind = StubTweaker.tweak(_url, n, _domainName, _mcastAddress, _mcastPort,
404              toBind);
405     return toBind;
406   }
407
408   /**
409    * @see ContextProxy#onRebind(javax.naming.Name, java.lang.Object)
410    */

411   protected Object JavaDoc onRebind(Name JavaDoc n, Object JavaDoc toBind) throws NamingException JavaDoc {
412     return onBind(n, toBind);
413   }
414
415   /**
416    * @see ContextProxy#onEnum(javax.naming.Name, javax.naming.NamingEnumeration)
417    */

418   protected NamingEnumeration JavaDoc onEnum(Name JavaDoc n, NamingEnumeration JavaDoc en) {
419     return new LocalNamingEnum(_url, n, en);
420   }
421
422   /**
423    * "see ContextProxy#onSubContext(javax.naming.Name, javax.naming.Context)
424    */

425   protected Context JavaDoc onSubContext(Name JavaDoc name, Context JavaDoc ctx)
426     throws NamingException JavaDoc {
427     return new LocalContext(_url, (RemoteContext) ctx);
428   }
429
430   protected void doFailOver(UndeclaredThrowableException JavaDoc e)
431     throws NamingException JavaDoc {
432     NamingException JavaDoc ne = new NamingException JavaDoc("Unavailable naming service for " +
433         _url);
434     ne.setRootCause(e.getUndeclaredThrowable());
435   }
436 }
437
Popular Tags