View Javadoc

1   /*
2    * @(#) FileContext.java Oct 23, 2003
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  package nl.tudelft.simulation.naming;
11  
12  import java.io.Serializable;
13  import java.rmi.RemoteException;
14  import java.util.Hashtable;
15  
16  import javax.naming.Context;
17  import javax.naming.Name;
18  import javax.naming.NameParser;
19  import javax.naming.NamingEnumeration;
20  import javax.naming.NamingException;
21  import javax.naming.event.EventContext;
22  import javax.naming.event.NamingListener;
23  
24  import nl.tudelft.simulation.naming.listener.ContextListenerInterface;
25  import nl.tudelft.simulation.naming.listener.RemoteContextListener;
26  
27  /***
28   * The FileContext as implementation of the Context interface.
29   * <p>
30   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
31   * University of Technology </a>, the Netherlands. <br>
32   * See for project information <a href="http://www.simulation.tudelft.nl">
33   * www.simulation.tudelft.nl </a> <br>
34   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
35   * License (GPL) </a>, no warranty <br>
36   * 
37   * @author <a href="http://www.simulation.tudelft.nl/people/jacobs.html">Peter
38   *         Jacobs </a>
39   * @version 1.1 2004-03-24
40   * @since 1.0
41   */
42  public class RemoteContextClient implements EventContext, Serializable
43  {
44  	/*** the remoteContext on which all calls are passed */
45  	private RemoteContextInterface remoteContext = null;
46  
47  	/***
48  	 * constructs a new RemoteContextClient
49  	 * 
50  	 * @param remoteContext the remoteContext on which all calls are passed.
51  	 */
52  	public RemoteContextClient(final RemoteContextInterface remoteContext)
53  	{
54  		super();
55  		this.remoteContext = remoteContext;
56  	}
57  
58  	/***
59  	 * @see javax.naming.event.EventContext#addNamingListener(javax.naming.Name,
60  	 *      int, javax.naming.event.NamingListener)
61  	 */
62  	public void addNamingListener(Name target, int scope, NamingListener l)
63  			throws NamingException
64  	{
65  		try
66  		{
67  			this.remoteContext.addNamingListener(target, scope,
68  					new RemoteContextListener((ContextListenerInterface) l));
69  		} catch (RemoteException remoteException)
70  		{
71  			throw new NamingException(remoteException.getMessage());
72  		}
73  	}
74  
75  	/***
76  	 * @see javax.naming.event.EventContext #addNamingListener(java.lang.String,
77  	 *      int, javax.naming.event.NamingListener)
78  	 */
79  	public void addNamingListener(String target, int scope, NamingListener l)
80  			throws NamingException
81  	{
82  		try
83  		{
84  			this.remoteContext.addNamingListener(target, scope,
85  					new RemoteContextListener((ContextListenerInterface) l));
86  		} catch (RemoteException remoteException)
87  		{
88  			throw new NamingException(remoteException.getMessage());
89  		}
90  	}
91  
92  	/***
93  	 * @see javax.naming.event.EventContext
94  	 *      #removeNamingListener(javax.naming.event.NamingListener)
95  	 */
96  	public void removeNamingListener(NamingListener l) throws NamingException
97  	{
98  		try
99  		{
100 			this.remoteContext.removeNamingListener(new RemoteContextListener(
101 					(ContextListenerInterface) l));
102 		} catch (RemoteException remoteException)
103 		{
104 			throw new NamingException(remoteException.getMessage());
105 		}
106 	}
107 
108 	/***
109 	 * @see javax.naming.event.EventContext#targetMustExist()
110 	 */
111 	public boolean targetMustExist() throws NamingException
112 	{
113 		try
114 		{
115 			return this.remoteContext.targetMustExist();
116 		} catch (RemoteException remoteException)
117 		{
118 			throw new NamingException(remoteException.getMessage());
119 		}
120 	}
121 
122 	/***
123 	 * @see javax.naming.Context#addToEnvironment(java.lang.String,
124 	 *      java.lang.Object)
125 	 */
126 	public Object addToEnvironment(String propName, Object propVal)
127 			throws NamingException
128 	{
129 		try
130 		{
131 			return this.remoteContext.addToEnvironment(propName, propVal);
132 		} catch (RemoteException remoteException)
133 		{
134 			throw new NamingException(remoteException.getMessage());
135 		}
136 	}
137 
138 	/***
139 	 * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
140 	 */
141 	public void bind(Name name, Object obj) throws NamingException
142 	{
143 		try
144 		{
145 			this.remoteContext.bind(name, obj);
146 		} catch (RemoteException remoteException)
147 		{
148 			throw new NamingException(remoteException.getMessage());
149 		}
150 	}
151 
152 	/***
153 	 * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
154 	 */
155 	public void bind(String name, Object obj) throws NamingException
156 	{
157 		try
158 		{
159 			this.remoteContext.bind(name, obj);
160 		} catch (RemoteException remoteException)
161 		{
162 			throw new NamingException(remoteException.getMessage());
163 		}
164 	}
165 
166 	/***
167 	 * @see javax.naming.Context#close()
168 	 */
169 	public void close() throws NamingException
170 	{
171 		try
172 		{
173 			this.remoteContext.close();
174 		} catch (RemoteException remoteException)
175 		{
176 			throw new NamingException(remoteException.getMessage());
177 		}
178 	}
179 
180 	/***
181 	 * @see javax.naming.Context#composeName(javax.naming.Name,
182 	 *      javax.naming.Name)
183 	 */
184 	public Name composeName(Name name, Name prefix) throws NamingException
185 	{
186 		try
187 		{
188 			return this.remoteContext.composeName(name, prefix);
189 		} catch (RemoteException remoteException)
190 		{
191 			throw new NamingException(remoteException.getMessage());
192 		}
193 	}
194 
195 	/***
196 	 * @see javax.naming.Context#composeName(java.lang.String, java.lang.String)
197 	 */
198 	public String composeName(String name, String prefix)
199 			throws NamingException
200 	{
201 		try
202 		{
203 			return this.remoteContext.composeName(name, prefix);
204 		} catch (RemoteException remoteException)
205 		{
206 			throw new NamingException(remoteException.getMessage());
207 		}
208 	}
209 
210 	/***
211 	 * @see javax.naming.Context#createSubcontext(javax.naming.Name)
212 	 */
213 	public Context createSubcontext(Name name) throws NamingException
214 	{
215 		try
216 		{
217 			return new RemoteContextClient(this.remoteContext
218 					.createSubcontext(name));
219 		} catch (RemoteException remoteException)
220 		{
221 			throw new NamingException(remoteException.getMessage());
222 		}
223 
224 	}
225 
226 	/***
227 	 * @see javax.naming.Context#createSubcontext(java.lang.String)
228 	 */
229 	public Context createSubcontext(String name) throws NamingException
230 	{
231 		try
232 		{
233 			return new RemoteContextClient(this.remoteContext
234 					.createSubcontext(name));
235 		} catch (RemoteException remoteException)
236 		{
237 			throw new NamingException(remoteException.getMessage());
238 		}
239 	}
240 
241 	/***
242 	 * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
243 	 */
244 	public void destroySubcontext(Name name) throws NamingException
245 	{
246 		try
247 		{
248 			this.remoteContext.destroySubcontext(name);
249 		} catch (RemoteException remoteException)
250 		{
251 			throw new NamingException(remoteException.getMessage());
252 		}
253 	}
254 
255 	/***
256 	 * @see javax.naming.Context#destroySubcontext(java.lang.String)
257 	 */
258 	public void destroySubcontext(String name) throws NamingException
259 	{
260 		try
261 		{
262 			this.remoteContext.destroySubcontext(name);
263 		} catch (RemoteException remoteException)
264 		{
265 			throw new NamingException(remoteException.getMessage());
266 		}
267 	}
268 
269 	/***
270 	 * @see javax.naming.Context#getEnvironment()
271 	 */
272 	public Hashtable getEnvironment() throws NamingException
273 	{
274 		try
275 		{
276 			return this.remoteContext.getEnvironment();
277 		} catch (RemoteException remoteException)
278 		{
279 			throw new NamingException(remoteException.getMessage());
280 		}
281 
282 	}
283 
284 	/***
285 	 * @see javax.naming.Context#getNameInNamespace()
286 	 */
287 	public String getNameInNamespace() throws NamingException
288 	{
289 		try
290 		{
291 			return this.remoteContext.getNameInNamespace();
292 		} catch (RemoteException remoteException)
293 		{
294 			throw new NamingException(remoteException.getMessage());
295 		}
296 	}
297 
298 	/***
299 	 * @see javax.naming.Context#getNameParser(javax.naming.Name)
300 	 */
301 	public NameParser getNameParser(Name name) throws NamingException
302 	{
303 		try
304 		{
305 			return this.remoteContext.getNameParser(name);
306 		} catch (RemoteException remoteException)
307 		{
308 			throw new NamingException(remoteException.getMessage());
309 		}
310 
311 	}
312 
313 	/***
314 	 * @see javax.naming.Context#getNameParser(java.lang.String)
315 	 */
316 	public NameParser getNameParser(String name) throws NamingException
317 	{
318 		try
319 		{
320 			return this.remoteContext.getNameParser(name);
321 		} catch (RemoteException remoteException)
322 		{
323 			throw new NamingException(remoteException.getMessage());
324 		}
325 
326 	}
327 
328 	/***
329 	 * @see javax.naming.Context#list(javax.naming.Name)
330 	 */
331 	public NamingEnumeration list(Name name) throws NamingException
332 	{
333 		try
334 		{
335 			return this.remoteContext.list(name);
336 		} catch (RemoteException remoteException)
337 		{
338 			throw new NamingException(remoteException.getMessage());
339 		}
340 
341 	}
342 
343 	/***
344 	 * @see javax.naming.Context#list(java.lang.String)
345 	 */
346 	public NamingEnumeration list(String name) throws NamingException
347 	{
348 		try
349 		{
350 			return this.remoteContext.list(name);
351 		} catch (RemoteException remoteException)
352 		{
353 			throw new NamingException(remoteException.getMessage());
354 		}
355 
356 	}
357 
358 	/***
359 	 * @see javax.naming.Context#listBindings(javax.naming.Name)
360 	 */
361 	public NamingEnumeration listBindings(Name name) throws NamingException
362 	{
363 		try
364 		{
365 			return this.remoteContext.listBindings(name);
366 		} catch (RemoteException remoteException)
367 		{
368 			throw new NamingException(remoteException.getMessage());
369 		}
370 
371 	}
372 
373 	/***
374 	 * @see javax.naming.Context#listBindings(java.lang.String)
375 	 */
376 	public NamingEnumeration listBindings(String name) throws NamingException
377 	{
378 		try
379 		{
380 			return this.remoteContext.listBindings(name);
381 		} catch (RemoteException remoteException)
382 		{
383 			throw new NamingException(remoteException.getMessage());
384 		}
385 
386 	}
387 
388 	/***
389 	 * @see javax.naming.Context#lookup(javax.naming.Name)
390 	 */
391 	public Object lookup(Name name) throws NamingException
392 	{
393 		try
394 		{
395 			return this.remoteContext.lookup(name);
396 		} catch (RemoteException remoteException)
397 		{
398 			throw new NamingException(remoteException.getMessage());
399 		}
400 
401 	}
402 
403 	/***
404 	 * @see javax.naming.Context#lookup(java.lang.String)
405 	 */
406 	public Object lookup(String name) throws NamingException
407 	{
408 		try
409 		{
410 			return this.remoteContext.lookup(name);
411 		} catch (RemoteException remoteException)
412 		{
413 			throw new NamingException(remoteException.getMessage());
414 		}
415 
416 	}
417 
418 	/***
419 	 * @see javax.naming.Context#lookupLink(javax.naming.Name)
420 	 */
421 	public Object lookupLink(Name name) throws NamingException
422 	{
423 		try
424 		{
425 			return this.remoteContext.lookupLink(name);
426 		} catch (RemoteException remoteException)
427 		{
428 			throw new NamingException(remoteException.getMessage());
429 		}
430 
431 	}
432 
433 	/***
434 	 * @see javax.naming.Context#lookupLink(java.lang.String)
435 	 */
436 	public Object lookupLink(String name) throws NamingException
437 	{
438 		try
439 		{
440 			return this.remoteContext.lookupLink(name);
441 		} catch (RemoteException remoteException)
442 		{
443 			throw new NamingException(remoteException.getMessage());
444 		}
445 
446 	}
447 
448 	/***
449 	 * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
450 	 */
451 	public void rebind(Name name, Object obj) throws NamingException
452 	{
453 		try
454 		{
455 			this.remoteContext.rebind(name, obj);
456 		} catch (RemoteException remoteException)
457 		{
458 			throw new NamingException(remoteException.getMessage());
459 		}
460 
461 	}
462 
463 	/***
464 	 * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
465 	 */
466 	public void rebind(String name, Object obj) throws NamingException
467 	{
468 		try
469 		{
470 			this.remoteContext.rebind(name, obj);
471 		} catch (RemoteException remoteException)
472 		{
473 			throw new NamingException(remoteException.getMessage());
474 		}
475 	}
476 
477 	/***
478 	 * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
479 	 */
480 	public Object removeFromEnvironment(String propName) throws NamingException
481 	{
482 		try
483 		{
484 			return this.remoteContext.removeFromEnvironment(propName);
485 		} catch (RemoteException remoteException)
486 		{
487 			throw new NamingException(remoteException.getMessage());
488 		}
489 
490 	}
491 
492 	/***
493 	 * @see javax.naming.Context#rename(javax.naming.Name, javax.naming.Name)
494 	 */
495 	public void rename(Name oldName, Name newName) throws NamingException
496 	{
497 		try
498 		{
499 			this.remoteContext.rename(oldName, newName);
500 		} catch (RemoteException remoteException)
501 		{
502 			throw new NamingException(remoteException.getMessage());
503 		}
504 	}
505 
506 	/***
507 	 * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
508 	 */
509 	public void rename(String oldName, String newName) throws NamingException
510 	{
511 		try
512 		{
513 			this.remoteContext.rename(oldName, newName);
514 		} catch (RemoteException remoteException)
515 		{
516 			throw new NamingException(remoteException.getMessage());
517 		}
518 	}
519 
520 	/***
521 	 * @see javax.naming.Context#unbind(javax.naming.Name)
522 	 */
523 	public void unbind(Name name) throws NamingException
524 	{
525 		try
526 		{
527 			this.remoteContext.unbind(name);
528 		} catch (RemoteException remoteException)
529 		{
530 			throw new NamingException(remoteException.getMessage());
531 		}
532 
533 	}
534 
535 	/***
536 	 * @see javax.naming.Context#unbind(java.lang.String)
537 	 */
538 	public void unbind(String name) throws NamingException
539 	{
540 		try
541 		{
542 			this.remoteContext.unbind(name);
543 		} catch (RemoteException remoteException)
544 		{
545 			throw new NamingException(remoteException.getMessage());
546 		}
547 	}
548 }