1 /**
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 *
6 * If it is not possible or desirable to put the notice in a particular
7 * file, then You may include the notice in a location (such as a LICENSE
8 * file in a relevant directory) where a recipient would be likely to look
9 * for such a notice.
10
11 *
12 */
13
14 /* ---------------------------------------------------------------------------
15 * U.S. Government, Department of the Army
16 * Army Materiel Command
17 * Research Development Engineering Command
18 * Communications Electronics Research Development and Engineering Center
19 * ---------------------------------------------------------------------------
20 */
21 package org.miloss.fgsms.test;
22
23 import java.util.HashMap;
24 import java.util.Hashtable;
25 import java.util.Map;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import javax.naming.spi.InitialContextFactory;
30
31 /**
32 *
33 * @author AO
34 */
35
36 public class InitialContextFactoryForTest implements InitialContextFactory {
37
38 private static Context context;
39
40 static {
41 try {
42 context = new InitialContext(true) {
43 Map<String, Object> bindings = new HashMap<String, Object>();
44
45 @Override
46 public void bind(String name, Object obj)
47 throws NamingException {
48 bindings.put(name, obj);
49 }
50
51 @Override
52 public Object lookup(String name) throws NamingException {
53 return bindings.get(name);
54 }
55 };
56 } catch (NamingException e) { // can't happen.
57 throw new RuntimeException(e);
58 }
59 }
60
61 public Context getInitialContext(Hashtable<?, ?> environment)
62 throws NamingException {
63 return context;
64 }
65
66 public static void bind(String name, Object obj) {
67 try {
68 context.bind(name, obj);
69 } catch (NamingException e) { // can't happen.
70 throw new RuntimeException(e);
71 }
72 }
73
74 @org.junit.Test
75 public void Test()
76 {}
77 }