View Javadoc

1   /*
2    * @(#) RemoteContext.java Apr 7, 2004
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.rmi.RemoteException;
13  import java.rmi.server.UnicastRemoteObject;
14  import java.util.Collections;
15  import java.util.HashMap;
16  import java.util.Hashtable;
17  import java.util.Map;
18  
19  import javax.naming.Name;
20  import javax.naming.NameParser;
21  import javax.naming.NamingEnumeration;
22  import javax.naming.NamingException;
23  import javax.naming.event.EventContext;
24  import javax.naming.event.NamingListener;
25  
26  import nl.tudelft.simulation.naming.listener.RemoteContextListenerClient;
27  import nl.tudelft.simulation.naming.listener.RemoteContextListenerInterface;
28  
29  /***
30   * <p>
31   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
32   * University of Technology </a>, the Netherlands. <br>
33   * See for project information <a
34   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
35   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
36   * License (GPL) </a>, no warranty <br>
37   * 
38   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
39   *         Jacobs </a>
40   * @version 1.1 Apr 7, 2004
41   * @since 1.4
42   */
43  public class RemoteContext extends UnicastRemoteObject implements
44  		RemoteContextInterface
45  {
46  	/*** the underlying eventcontext */
47  	private EventContext eventContext = null;
48  
49  	/*** the listeners */
50  	private Map listeners = Collections.synchronizedMap(new HashMap());
51  
52  	/***
53  	 * constructs a new RemoteContext
54  	 * 
55  	 * @param eventContext the underlying context
56  	 * @throws RemoteException on network failure
57  	 */
58  	public RemoteContext(final EventContext eventContext)
59  			throws RemoteException
60  	{
61  		super();
62  		this.eventContext = eventContext;
63  	}
64  
65  	/***
66  	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#addNamingListener(javax.naming.Name,
67  	 *      int,
68  	 *      nl.tudelft.simulation.naming.listener.RemoteContextListenerInterface)
69  	 */
70  	public void addNamingListener(Name target, int scope,
71  			RemoteContextListenerInterface l) throws NamingException
72  	{
73  		RemoteContextListenerClient client = new RemoteContextListenerClient(l);
74  		this.listeners.put(l, client);
75  		this.eventContext.addNamingListener(target, scope, client);
76  	}
77  
78  	/***
79  	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#addNamingListener(java.lang.String,
80  	 *      int,
81  	 *      nl.tudelft.simulation.naming.listener.RemoteContextListenerInterface)
82  	 */
83  	public void addNamingListener(String target, int scope,
84  			RemoteContextListenerInterface l) throws NamingException
85  	{
86  		RemoteContextListenerClient client = new RemoteContextListenerClient(l);
87  		this.listeners.put(l, client);
88  		this.eventContext.addNamingListener(target, scope, client);
89  	}
90  
91  
92  	/***
93  	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#removeNamingListener(nl.tudelft.simulation.naming.listener.RemoteContextListenerInterface)
94  	 */
95  	public void removeNamingListener(RemoteContextListenerInterface l)
96  			throws NamingException
97  	{
98  		this.eventContext.removeNamingListener((NamingListener) this.listeners
99  				.remove(l));
100 	}
101 
102 	/***
103 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#targetMustExist()
104 	 */
105 	public boolean targetMustExist() throws NamingException
106 	{
107 		return this.eventContext.targetMustExist();
108 	}
109 
110 	/***
111 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#lookup(javax.naming.Name)
112 	 */
113 	public Object lookup(Name name) throws NamingException
114 	{
115 		return this.eventContext.lookup(name);
116 	}
117 
118 	/***
119 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#lookup(java.lang.String)
120 	 */
121 	public Object lookup(String name) throws NamingException
122 	{
123 		return this.eventContext.lookup(name);
124 	}
125 
126 	/***
127 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#bind(javax.naming.Name,
128 	 *      java.lang.Object)
129 	 */
130 	public void bind(Name name, Object obj) throws NamingException
131 	{
132 		this.eventContext.bind(name, obj);
133 	}
134 
135 	/***
136 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#bind(java.lang.String,
137 	 *      java.lang.Object)
138 	 */
139 	public void bind(String name, Object obj) throws NamingException
140 	{
141 		this.eventContext.bind(name, obj);
142 	}
143 
144 	/***
145 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#rebind(javax.naming.Name,
146 	 *      java.lang.Object)
147 	 */
148 	public void rebind(Name name, Object obj) throws NamingException
149 	{
150 		this.eventContext.rebind(name, obj);
151 	}
152 
153 	/***
154 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#rebind(java.lang.String,
155 	 *      java.lang.Object)
156 	 */
157 	public void rebind(String name, Object obj) throws NamingException
158 	{
159 		this.eventContext.rebind(name, obj);
160 	}
161 
162 	/***
163 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#unbind(javax.naming.Name)
164 	 */
165 	public void unbind(Name name) throws NamingException
166 	{
167 		this.eventContext.unbind(name);
168 	}
169 
170 	/***
171 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#unbind(java.lang.String)
172 	 */
173 	public void unbind(String name) throws NamingException
174 	{
175 		this.eventContext.unbind(name);
176 	}
177 
178 	/***
179 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#rename(javax.naming.Name,
180 	 *      javax.naming.Name)
181 	 */
182 	public void rename(Name oldName, Name newName) throws NamingException
183 	{
184 		this.eventContext.rename(oldName, newName);
185 	}
186 
187 	/***
188 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#rename(java.lang.String,
189 	 *      java.lang.String)
190 	 */
191 	public void rename(String oldName, String newName) throws NamingException
192 	{
193 		this.eventContext.rename(oldName, newName);
194 	}
195 
196 	/***
197 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#list(javax.naming.Name)
198 	 */
199 	public NamingEnumeration list(Name name) throws NamingException
200 	{
201 		return this.eventContext.list(name);
202 	}
203 
204 	/***
205 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#list(java.lang.String)
206 	 */
207 	public NamingEnumeration list(String name) throws NamingException
208 	{
209 		return this.eventContext.list(name);
210 	}
211 
212 	/***
213 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#listBindings(javax.naming.Name)
214 	 */
215 	public NamingEnumeration listBindings(Name name) throws NamingException
216 	{
217 		return this.eventContext.listBindings(name);
218 	}
219 
220 	/***
221 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#listBindings(java.lang.String)
222 	 */
223 	public NamingEnumeration listBindings(String name) throws NamingException
224 	{
225 		return this.eventContext.listBindings(name);
226 	}
227 
228 	/***
229 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#destroySubcontext(javax.naming.Name)
230 	 */
231 	public void destroySubcontext(Name name) throws NamingException
232 	{
233 		this.eventContext.destroySubcontext(name);
234 	}
235 
236 	/***
237 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#destroySubcontext(java.lang.String)
238 	 */
239 	public void destroySubcontext(String name) throws NamingException
240 	{
241 		this.eventContext.destroySubcontext(name);
242 	}
243 
244 	/***
245 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#createSubcontext(javax.naming.Name)
246 	 */
247 	public RemoteContextInterface createSubcontext(Name name)
248 			throws NamingException, RemoteException
249 	{
250 		EventContext child = (EventContext) this.eventContext
251 				.createSubcontext(name);
252 		return new RemoteContext(child);
253 	}
254 
255 	/***
256 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#createSubcontext(java.lang.String)
257 	 */
258 	public RemoteContextInterface createSubcontext(String name)
259 			throws NamingException, RemoteException
260 	{
261 		EventContext child = (EventContext) this.eventContext
262 				.createSubcontext(name);
263 		return new RemoteContext(child);
264 	}
265 
266 	/***
267 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#lookupLink(javax.naming.Name)
268 	 */
269 	public Object lookupLink(Name name) throws NamingException
270 	{
271 		return this.eventContext.lookupLink(name);
272 	}
273 
274 	/***
275 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#lookupLink(java.lang.String)
276 	 */
277 	public Object lookupLink(String name) throws NamingException
278 	{
279 		return this.eventContext.lookupLink(name);
280 	}
281 
282 	/***
283 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#getNameParser(javax.naming.Name)
284 	 */
285 	public NameParser getNameParser(Name name) throws NamingException
286 	{
287 		return this.eventContext.getNameParser(name);
288 	}
289 
290 	/***
291 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#getNameParser(java.lang.String)
292 	 */
293 	public NameParser getNameParser(String name) throws NamingException
294 	{
295 		return this.eventContext.getNameParser(name);
296 	}
297 
298 	/***
299 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#composeName(javax.naming.Name,
300 	 *      javax.naming.Name)
301 	 */
302 	public Name composeName(Name name, Name prefix) throws NamingException
303 	{
304 		return this.eventContext.composeName(name, prefix);
305 	}
306 
307 	/***
308 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#composeName(java.lang.String,
309 	 *      java.lang.String)
310 	 */
311 	public String composeName(String name, String prefix)
312 			throws NamingException
313 	{
314 		return this.eventContext.composeName(name, prefix);
315 	}
316 
317 	/***
318 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#addToEnvironment(java.lang.String,
319 	 *      java.lang.Object)
320 	 */
321 	public Object addToEnvironment(String propName, Object propVal)
322 			throws NamingException
323 	{
324 		return this.eventContext.addToEnvironment(propName, propVal);
325 	}
326 
327 	/***
328 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#removeFromEnvironment(java.lang.String)
329 	 */
330 	public Object removeFromEnvironment(String propName) throws NamingException
331 	{
332 		return this.eventContext.removeFromEnvironment(propName);
333 	}
334 
335 	/***
336 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#getEnvironment()
337 	 */
338 	public Hashtable getEnvironment() throws NamingException
339 	{
340 		return this.eventContext.getEnvironment();
341 	}
342 
343 	/***
344 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#close()
345 	 */
346 	public void close() throws NamingException
347 	{
348 		this.eventContext.close();
349 	}
350 
351 	/***
352 	 * @see nl.tudelft.simulation.naming.RemoteContextInterface#getNameInNamespace()
353 	 */
354 	public String getNameInNamespace() throws NamingException
355 	{
356 		return this.eventContext.getNameInNamespace();
357 	}
358 }