|
1 package ru.indvdum.jpa.jndi; |
|
2 |
|
3 import java.util.HashMap; |
|
4 import java.util.Hashtable; |
|
5 import java.util.Map; |
|
6 |
|
7 import javax.naming.Binding; |
|
8 import javax.naming.Context; |
|
9 import javax.naming.Name; |
|
10 import javax.naming.NameClassPair; |
|
11 import javax.naming.NameParser; |
|
12 import javax.naming.NamingEnumeration; |
|
13 import javax.naming.NamingException; |
|
14 |
|
15 /** |
|
16 * @author indvdum (gotoindvdum[at]gmail[dot]com) |
|
17 * @since 03.11.2011 16:37:15 |
|
18 * |
|
19 */ |
|
20 public class SimpleContext implements Context { |
|
21 private Map<String, Object> _bind_map = new HashMap<String, Object>(); |
|
22 |
|
23 public SimpleContext(Hashtable<?, ?> environment) { |
|
24 } |
|
25 |
|
26 @Override |
|
27 public Object addToEnvironment(String propName, Object propVal) throws NamingException { |
|
28 throw new UnsupportedOperationException(); |
|
29 } |
|
30 |
|
31 @Override |
|
32 public void bind(Name name, Object obj) throws NamingException { |
|
33 bind(String.valueOf(name), obj); |
|
34 } |
|
35 |
|
36 @Override |
|
37 public void bind(String name, Object obj) throws NamingException { |
|
38 if (_bind_map.get(name) == null) { |
|
39 _bind_map.put(name, obj); |
|
40 } else { |
|
41 throw new NamingException("Already bond."); |
|
42 } |
|
43 } |
|
44 |
|
45 @Override |
|
46 public void close() throws NamingException { |
|
47 } |
|
48 |
|
49 @Override |
|
50 public Name composeName(Name name, Name prefix) throws NamingException { |
|
51 throw new UnsupportedOperationException(); |
|
52 } |
|
53 |
|
54 @Override |
|
55 public String composeName(String name, String prefix) throws NamingException { |
|
56 throw new UnsupportedOperationException(); |
|
57 } |
|
58 |
|
59 @Override |
|
60 public Context createSubcontext(Name name) throws NamingException { |
|
61 throw new UnsupportedOperationException(); |
|
62 } |
|
63 |
|
64 @Override |
|
65 public Context createSubcontext(String name) throws NamingException { |
|
66 throw new UnsupportedOperationException(); |
|
67 } |
|
68 |
|
69 @Override |
|
70 public void destroySubcontext(Name name) throws NamingException { |
|
71 throw new UnsupportedOperationException(); |
|
72 } |
|
73 |
|
74 @Override |
|
75 public void destroySubcontext(String name) throws NamingException { |
|
76 throw new UnsupportedOperationException(); |
|
77 } |
|
78 |
|
79 @Override |
|
80 public Hashtable<?, ?> getEnvironment() throws NamingException { |
|
81 throw new UnsupportedOperationException(); |
|
82 } |
|
83 |
|
84 @Override |
|
85 public String getNameInNamespace() throws NamingException { |
|
86 throw new UnsupportedOperationException(); |
|
87 } |
|
88 |
|
89 @Override |
|
90 public NameParser getNameParser(Name name) throws NamingException { |
|
91 throw new UnsupportedOperationException(); |
|
92 } |
|
93 |
|
94 @Override |
|
95 public NameParser getNameParser(String name) throws NamingException { |
|
96 throw new UnsupportedOperationException(); |
|
97 } |
|
98 |
|
99 @Override |
|
100 public NamingEnumeration<NameClassPair> list(Name name) throws NamingException { |
|
101 throw new UnsupportedOperationException(); |
|
102 } |
|
103 |
|
104 @Override |
|
105 public NamingEnumeration<NameClassPair> list(String name) throws NamingException { |
|
106 throw new UnsupportedOperationException(); |
|
107 } |
|
108 |
|
109 @Override |
|
110 public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { |
|
111 throw new UnsupportedOperationException(); |
|
112 } |
|
113 |
|
114 @Override |
|
115 public NamingEnumeration<Binding> listBindings(String name) throws NamingException { |
|
116 throw new UnsupportedOperationException(); |
|
117 } |
|
118 |
|
119 @Override |
|
120 public Object lookup(Name name) throws NamingException { |
|
121 return lookup(String.valueOf(name)); |
|
122 } |
|
123 |
|
124 @Override |
|
125 public Object lookup(String name) throws NamingException { |
|
126 return _bind_map.get(name); |
|
127 } |
|
128 |
|
129 @Override |
|
130 public Object lookupLink(Name name) throws NamingException { |
|
131 throw new UnsupportedOperationException(); |
|
132 } |
|
133 |
|
134 @Override |
|
135 public Object lookupLink(String name) throws NamingException { |
|
136 throw new UnsupportedOperationException(); |
|
137 } |
|
138 |
|
139 @Override |
|
140 public void rebind(Name name, Object obj) throws NamingException { |
|
141 rebind(String.valueOf(name), obj); |
|
142 } |
|
143 |
|
144 @Override |
|
145 public void rebind(String name, Object obj) throws NamingException { |
|
146 _bind_map.put(name, obj); |
|
147 } |
|
148 |
|
149 @Override |
|
150 public Object removeFromEnvironment(String propName) throws NamingException { |
|
151 throw new UnsupportedOperationException(); |
|
152 } |
|
153 |
|
154 @Override |
|
155 public void rename(Name oldName, Name newName) throws NamingException { |
|
156 throw new UnsupportedOperationException(); |
|
157 } |
|
158 |
|
159 @Override |
|
160 public void rename(String oldName, String newName) throws NamingException { |
|
161 throw new UnsupportedOperationException(); |
|
162 } |
|
163 |
|
164 @Override |
|
165 public void unbind(Name name) throws NamingException { |
|
166 unbind(String.valueOf(name)); |
|
167 } |
|
168 |
|
169 @Override |
|
170 public void unbind(String name) throws NamingException { |
|
171 _bind_map.remove(name); |
|
172 } |
|
173 } |