View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.tck.jndi;
8   
9   import java.util.HashMap;
10  import java.util.Hashtable;
11  import java.util.Map;
12  
13  import javax.naming.Context;
14  import javax.naming.Name;
15  import javax.naming.NameParser;
16  import javax.naming.NamingEnumeration;
17  import javax.naming.NamingException;
18  
19  /**
20   * Simple in-memory JNDI context for unit testing.
21   */
22  public class InMemoryContext implements Context
23  {
24      private Map context = new HashMap();
25  
26      public Object lookup(Name name) throws NamingException
27      {
28          return context.get(name);
29      }
30  
31      public Object lookup(String name) throws NamingException
32      {
33          return context.get(name);
34      }
35  
36      public void bind(Name name, Object obj) throws NamingException
37      {
38          context.put(name, obj);
39      }
40  
41      public void bind(String name, Object obj) throws NamingException
42      {
43          context.put(name, obj);
44      }
45  
46      public void unbind(Name name) throws NamingException
47      {
48          context.remove(name);
49      }
50  
51      public void unbind(String name) throws NamingException
52      {
53          context.remove(name);
54      }
55  
56      public void rebind(Name name, Object obj) throws NamingException
57      {
58          unbind(name);
59          bind(name, obj);
60      }
61  
62      public void rebind(String name, Object obj) throws NamingException
63      {
64          unbind(name);
65          bind(name, obj);
66      }
67  
68      //////////////////////////////////////////////////////////////////////
69      // The remaining methods are not implemented.
70      //////////////////////////////////////////////////////////////////////
71      
72      public Object addToEnvironment(String propName, Object propVal) throws NamingException
73      {
74          return null;
75      }
76  
77      public void close() throws NamingException
78      {
79          // nop
80      }
81  
82      public Name composeName(Name name, Name prefix) throws NamingException
83      {
84          return null;
85      }
86  
87      public String composeName(String name, String prefix) throws NamingException
88      {
89          return null;
90      }
91  
92      public Context createSubcontext(Name name) throws NamingException
93      {
94          return null;
95      }
96  
97      public Context createSubcontext(String name) throws NamingException
98      {
99          return null;
100     }
101 
102     public void destroySubcontext(Name name) throws NamingException
103     {
104         // nop
105     }
106 
107     public void destroySubcontext(String name) throws NamingException
108     {
109         // nop
110     }
111 
112     public Hashtable getEnvironment() throws NamingException
113     {
114         return null;
115     }
116 
117     public String getNameInNamespace() throws NamingException
118     {
119         return null;
120     }
121 
122     public NameParser getNameParser(Name name) throws NamingException
123     {
124         return null;
125     }
126 
127     public NameParser getNameParser(String name) throws NamingException
128     {
129         return null;
130     }
131 
132     public NamingEnumeration list(Name name) throws NamingException
133     {
134         return null;
135     }
136 
137     public NamingEnumeration list(String name) throws NamingException
138     {
139         return null;
140     }
141 
142     public NamingEnumeration listBindings(Name name) throws NamingException
143     {
144         return null;
145     }
146 
147     public NamingEnumeration listBindings(String name) throws NamingException
148     {
149         return null;
150     }
151 
152     public Object lookupLink(Name name) throws NamingException
153     {
154         return null;
155     }
156 
157     public Object lookupLink(String name) throws NamingException
158     {
159         return null;
160     }
161 
162     public Object removeFromEnvironment(String propName) throws NamingException
163     {
164         return null;
165     }
166 
167     public void rename(Name oldName, Name newName) throws NamingException
168     {
169         // nop
170     }
171 
172     public void rename(String oldName, String newName) throws NamingException
173     {
174         // nop
175     }
176 }
177 
178