KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > spice > jndikit > rmi > test > RMIContextTestCase


1 /*
2  * Copyright (C) The Spice Group. All rights reserved.
3  *
4  * This software is published under the terms of the Spice
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.spice.jndikit.rmi.test;
9
10 import java.util.Hashtable JavaDoc;
11 import javax.naming.Context JavaDoc;
12 import javax.naming.NamingException JavaDoc;
13 import javax.naming.ServiceUnavailableException JavaDoc;
14
15 import org.codehaus.spice.jndikit.Namespace;
16 import org.codehaus.spice.jndikit.NamingProvider;
17 import org.codehaus.spice.jndikit.RemoteContext;
18 import org.codehaus.spice.jndikit.StandardNamespace;
19 import org.codehaus.spice.jndikit.rmi.RMIInitialContextFactory;
20 import org.codehaus.spice.jndikit.test.TestStateFactory;
21
22 /**
23  * Unit test for RMI context.
24  *
25  * @author Tim Anderson
26  * @version $Revision: 1.2 $
27  */

28 public class RMIContextTestCase
29     extends AbstractRMIContextTestCase
30 {
31     public RMIContextTestCase()
32     {
33         super( new StandardNamespaceICF() );
34     }
35
36     static class StandardNamespaceICF extends RMIInitialContextFactory
37     {
38
39         public Context JavaDoc getInitialContext( Hashtable JavaDoc environment )
40             throws NamingException JavaDoc
41         {
42             environment.put( Context.STATE_FACTORIES,
43                              TestStateFactory.class.getName() );
44             return super.getInitialContext( environment );
45         }
46
47         protected Namespace newNamespace( final Hashtable JavaDoc environment )
48             throws NamingException JavaDoc
49         {
50             try
51             {
52                 final NamingProvider provider =
53                     ( NamingProvider ) environment.get(
54                         RemoteContext.NAMING_PROVIDER );
55
56                 return new StandardNamespace( provider.getNameParser() );
57             }
58             catch( final Exception JavaDoc e )
59             {
60                 if( e instanceof NamingException JavaDoc )
61                 {
62                     throw ( NamingException JavaDoc ) e;
63                 }
64                 else
65                 {
66                     final ServiceUnavailableException JavaDoc sue =
67                         new ServiceUnavailableException JavaDoc( e.getMessage() );
68                     sue.setRootCause( e );
69                     throw sue;
70                 }
71             }
72         }
73     }
74 }
75
Popular Tags