1   package nl.tudelft.simulation.dsol.naming;
2   
3   import javax.naming.NamingException;
4   import javax.naming.event.EventContext;
5   import javax.naming.event.NamingEvent;
6   import javax.naming.event.NamingExceptionEvent;
7   
8   import nl.tudelft.simulation.naming.InitialEventContext;
9   import nl.tudelft.simulation.naming.listener.ContextListenerInterface;
10  
11  /*
12   * @(#) ServerTest.java Apr 16, 2004
13   * 
14   * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
15   * the Netherlands All rights reserved.
16   * 
17   * This software is proprietary information of Delft University of Technology
18   * The code is published under the General Public License
19   */
20  
21  
22  /***
23   * The ServerTest.
24   * <p>
25   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
26   * University of Technology </a>, the Netherlands. <br>
27   * See for project information <a
28   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
29   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
30   * License (GPL) </a>, no warranty <br>
31   * 
32   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
33   *         Jacobs </a>
34   * @version 1.2 Apr 16, 2004
35   * @since 1.4
36   */
37  public class ServerTest implements ContextListenerInterface
38  {
39  	/***
40  	 * constructs a new ServerTest
41  	 * 
42  	 * @param context the context to use.
43  	 * @throws NamingException on subscription
44  	 */
45  	public ServerTest(final InitialEventContext context) throws NamingException
46  	{
47  		super();
48  		context.addNamingListener("/test", EventContext.OBJECT_SCOPE, this);
49  	}
50  
51  	/***
52  	 * executes the ServerTest
53  	 * 
54  	 * @param args the commandline arguments
55  	 */
56  	public static void main(String[] args)
57  	{
58  		try
59  		{
60  			InitialEventContext context = new InitialEventContext();
61  			context.bind("/test", "test");
62  			new ServerTest(context);
63  		} catch (NamingException e)
64  		{
65  			e.printStackTrace();
66  		}
67  	}
68  
69  	/***
70  	 * @see javax.naming.event.ObjectChangeListener#objectChanged(javax.naming.event.NamingEvent)
71  	 */
72  	public void objectChanged(NamingEvent evt)
73  	{
74  		System.out.println("changed " + evt);
75  	}
76  
77  	/***
78  	 * @see javax.naming.event.NamingListener#namingExceptionThrown(javax.naming.event.NamingExceptionEvent)
79  	 */
80  	public void namingExceptionThrown(NamingExceptionEvent evt)
81  	{
82  		System.out.println("exception " + evt);
83  	}
84  
85  	/***
86  	 * @see javax.naming.event.NamespaceChangeListener#objectAdded(javax.naming.event.NamingEvent)
87  	 */
88  	public void objectAdded(NamingEvent evt)
89  	{
90  		System.out.println("added" + evt);
91  	}
92  
93  	/***
94  	 * @see javax.naming.event.NamespaceChangeListener#objectRemoved(javax.naming.event.NamingEvent)
95  	 */
96  	public void objectRemoved(NamingEvent evt)
97  	{
98  		System.out.println("removed" + evt);
99  	}
100 
101 	/***
102 	 * @see javax.naming.event.NamespaceChangeListener#objectRenamed(javax.naming.event.NamingEvent)
103 	 */
104 	public void objectRenamed(NamingEvent evt)
105 	{
106 		System.out.println("renamed : " + evt);
107 	}
108 }