1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/main/java/ru/indvdum/jpa/jndi/SimpleContext.java Fri Nov 09 03:00:49 2012 +0400
1.3 @@ -0,0 +1,173 @@
1.4 +package ru.indvdum.jpa.jndi;
1.5 +
1.6 +import java.util.HashMap;
1.7 +import java.util.Hashtable;
1.8 +import java.util.Map;
1.9 +
1.10 +import javax.naming.Binding;
1.11 +import javax.naming.Context;
1.12 +import javax.naming.Name;
1.13 +import javax.naming.NameClassPair;
1.14 +import javax.naming.NameParser;
1.15 +import javax.naming.NamingEnumeration;
1.16 +import javax.naming.NamingException;
1.17 +
1.18 +/**
1.19 + * @author indvdum (gotoindvdum[at]gmail[dot]com)
1.20 + * @since 03.11.2011 16:37:15
1.21 + *
1.22 + */
1.23 +public class SimpleContext implements Context {
1.24 + private Map<String, Object> _bind_map = new HashMap<String, Object>();
1.25 +
1.26 + public SimpleContext(Hashtable<?, ?> environment) {
1.27 + }
1.28 +
1.29 + @Override
1.30 + public Object addToEnvironment(String propName, Object propVal) throws NamingException {
1.31 + throw new UnsupportedOperationException();
1.32 + }
1.33 +
1.34 + @Override
1.35 + public void bind(Name name, Object obj) throws NamingException {
1.36 + bind(String.valueOf(name), obj);
1.37 + }
1.38 +
1.39 + @Override
1.40 + public void bind(String name, Object obj) throws NamingException {
1.41 + if (_bind_map.get(name) == null) {
1.42 + _bind_map.put(name, obj);
1.43 + } else {
1.44 + throw new NamingException("Already bond.");
1.45 + }
1.46 + }
1.47 +
1.48 + @Override
1.49 + public void close() throws NamingException {
1.50 + }
1.51 +
1.52 + @Override
1.53 + public Name composeName(Name name, Name prefix) throws NamingException {
1.54 + throw new UnsupportedOperationException();
1.55 + }
1.56 +
1.57 + @Override
1.58 + public String composeName(String name, String prefix) throws NamingException {
1.59 + throw new UnsupportedOperationException();
1.60 + }
1.61 +
1.62 + @Override
1.63 + public Context createSubcontext(Name name) throws NamingException {
1.64 + throw new UnsupportedOperationException();
1.65 + }
1.66 +
1.67 + @Override
1.68 + public Context createSubcontext(String name) throws NamingException {
1.69 + throw new UnsupportedOperationException();
1.70 + }
1.71 +
1.72 + @Override
1.73 + public void destroySubcontext(Name name) throws NamingException {
1.74 + throw new UnsupportedOperationException();
1.75 + }
1.76 +
1.77 + @Override
1.78 + public void destroySubcontext(String name) throws NamingException {
1.79 + throw new UnsupportedOperationException();
1.80 + }
1.81 +
1.82 + @Override
1.83 + public Hashtable<?, ?> getEnvironment() throws NamingException {
1.84 + throw new UnsupportedOperationException();
1.85 + }
1.86 +
1.87 + @Override
1.88 + public String getNameInNamespace() throws NamingException {
1.89 + throw new UnsupportedOperationException();
1.90 + }
1.91 +
1.92 + @Override
1.93 + public NameParser getNameParser(Name name) throws NamingException {
1.94 + throw new UnsupportedOperationException();
1.95 + }
1.96 +
1.97 + @Override
1.98 + public NameParser getNameParser(String name) throws NamingException {
1.99 + throw new UnsupportedOperationException();
1.100 + }
1.101 +
1.102 + @Override
1.103 + public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
1.104 + throw new UnsupportedOperationException();
1.105 + }
1.106 +
1.107 + @Override
1.108 + public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
1.109 + throw new UnsupportedOperationException();
1.110 + }
1.111 +
1.112 + @Override
1.113 + public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
1.114 + throw new UnsupportedOperationException();
1.115 + }
1.116 +
1.117 + @Override
1.118 + public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
1.119 + throw new UnsupportedOperationException();
1.120 + }
1.121 +
1.122 + @Override
1.123 + public Object lookup(Name name) throws NamingException {
1.124 + return lookup(String.valueOf(name));
1.125 + }
1.126 +
1.127 + @Override
1.128 + public Object lookup(String name) throws NamingException {
1.129 + return _bind_map.get(name);
1.130 + }
1.131 +
1.132 + @Override
1.133 + public Object lookupLink(Name name) throws NamingException {
1.134 + throw new UnsupportedOperationException();
1.135 + }
1.136 +
1.137 + @Override
1.138 + public Object lookupLink(String name) throws NamingException {
1.139 + throw new UnsupportedOperationException();
1.140 + }
1.141 +
1.142 + @Override
1.143 + public void rebind(Name name, Object obj) throws NamingException {
1.144 + rebind(String.valueOf(name), obj);
1.145 + }
1.146 +
1.147 + @Override
1.148 + public void rebind(String name, Object obj) throws NamingException {
1.149 + _bind_map.put(name, obj);
1.150 + }
1.151 +
1.152 + @Override
1.153 + public Object removeFromEnvironment(String propName) throws NamingException {
1.154 + throw new UnsupportedOperationException();
1.155 + }
1.156 +
1.157 + @Override
1.158 + public void rename(Name oldName, Name newName) throws NamingException {
1.159 + throw new UnsupportedOperationException();
1.160 + }
1.161 +
1.162 + @Override
1.163 + public void rename(String oldName, String newName) throws NamingException {
1.164 + throw new UnsupportedOperationException();
1.165 + }
1.166 +
1.167 + @Override
1.168 + public void unbind(Name name) throws NamingException {
1.169 + unbind(String.valueOf(name));
1.170 + }
1.171 +
1.172 + @Override
1.173 + public void unbind(String name) throws NamingException {
1.174 + _bind_map.remove(name);
1.175 + }
1.176 +}
1.177 \ No newline at end of file