1 7 package org.jboss.jms.serverless.jndi; 8 9 import java.net.URL ; 10 import java.util.Enumeration ; 11 import java.util.HashMap ; 12 import java.util.HashSet ; 13 import java.util.Hashtable ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 import java.util.Set ; 17 import javax.jms.ConnectionFactory ; 18 import javax.jms.Destination ; 19 import javax.naming.Context ; 20 import javax.naming.Name ; 21 import javax.naming.NameNotFoundException ; 22 import javax.naming.NameParser ; 23 import javax.naming.NamingEnumeration ; 24 import javax.naming.NamingException ; 25 import org.jboss.jms.serverless.GroupConnectionFactory; 26 import org.jboss.jms.serverless.GroupQueue; 27 import org.jboss.jms.serverless.GroupTopic; 28 import org.jboss.jms.serverless.NotImplementedException; 29 import org.jboss.logging.Logger; 30 31 39 class GroupContext implements Context { 40 41 private static final Logger log = Logger.getLogger(GroupContext.class); 42 43 public static final String PROPERTY_NAME_PREFIX = "jms.serverless.jndi."; 44 public static final String CONNECTION_FACTORY_TOKEN = "connectionFactory."; 45 public static final String DESTINATION_TOKEN = "destination."; 46 47 private Map connFactoryInfo; private Set topicInfo; private Set queueInfo; 55 59 private Map connFactories; private Map topics; private Map queues; 64 68 GroupContext(Hashtable environment) { 69 70 connFactoryInfo = new HashMap (); 71 topicInfo = new HashSet (); 72 queueInfo = new HashSet (); 73 cacheAdministeredObjectInfo(environment); 74 connFactories = new HashMap (); 75 topics = new HashMap (); 76 queues = new HashMap (); 77 } 78 79 80 83 private void cacheAdministeredObjectInfo(Hashtable environment) { 84 85 if (environment == null) { 86 return; 87 } 88 89 for(Enumeration e = environment.keys(); e.hasMoreElements(); ) { 90 String prop = (String )e.nextElement(); 91 if (!prop.startsWith(PROPERTY_NAME_PREFIX)) { 92 continue; 93 } 94 String key = prop.substring(PROPERTY_NAME_PREFIX.length()); 95 if (key.startsWith(CONNECTION_FACTORY_TOKEN)) { 96 connFactoryInfo.put(key.substring(CONNECTION_FACTORY_TOKEN.length()), 97 environment.get(prop)); 98 } 99 else if (key.startsWith(DESTINATION_TOKEN)) { 100 String destJNDIName = key.substring(DESTINATION_TOKEN.length()); 101 String destType = ((String )environment.get(prop)).toLowerCase(); 102 if ("topic".equals(destType)) { 103 topicInfo.add(destJNDIName); 104 } 105 else if ("queue".equals(destType)) { 106 queueInfo.add(destJNDIName); 107 } 108 } 109 } 110 } 111 112 public Object lookup(Name name) throws NamingException { 113 throw new NotImplementedException(); 114 } 115 116 public Object lookup(String name) throws NamingException { 117 118 120 Object o = null; 121 if ((o = connFactories.get(name)) != null) { 122 return o; 123 } 124 if ((o = topics.get(name)) != null) { 125 return o; 126 } 127 if ((o = queues.get(name)) != null) { 128 return o; 129 } 130 131 133 String stackConfigFileName = (String )connFactoryInfo.get(name); 134 135 if (stackConfigFileName != null) { 136 ConnectionFactory cf = new GroupConnectionFactory(stackConfigFileName); 137 connFactories.put(name, cf); 138 return cf; 139 } 140 if (topicInfo.contains(name)) { 141 Destination t = new GroupTopic(name); 142 topics.put(name, t); 143 return t; 144 } 145 if (queueInfo.contains(name)) { 146 Destination q = new GroupQueue(name); 147 queues.put(name, q); 148 return q; 149 } 150 throw new NameNotFoundException (name+" not found"); 151 } 152 153 public void bind(Name name, Object obj) throws NamingException { 154 throw new NotImplementedException(); 155 } 156 157 public void bind(String name, Object obj) throws NamingException { 158 throw new NotImplementedException(); 159 } 160 161 public void rebind(Name name, Object obj) throws NamingException { 162 throw new NotImplementedException(); 163 } 164 165 public void rebind(String name, Object obj) throws NamingException { 166 throw new NotImplementedException(); 167 } 168 169 public void unbind(Name name) throws NamingException { 170 throw new NotImplementedException(); 171 } 172 173 public void unbind(String name) throws NamingException { 174 throw new NotImplementedException(); 175 } 176 177 public void rename(Name oldName, Name newName) throws NamingException { 178 throw new NotImplementedException(); 179 } 180 181 public void rename(String oldName, String newName) throws NamingException { 182 throw new NotImplementedException(); 183 } 184 185 public NamingEnumeration list(Name name) throws NamingException { 186 throw new NotImplementedException(); 187 } 188 189 public NamingEnumeration list(String name) throws NamingException { 190 throw new NotImplementedException(); 191 } 192 193 public NamingEnumeration listBindings(Name name) throws NamingException { 194 throw new NotImplementedException(); 195 } 196 197 public NamingEnumeration listBindings(String name) throws NamingException { 198 throw new NotImplementedException(); 199 } 200 201 public void destroySubcontext(Name name) throws NamingException { 202 throw new NotImplementedException(); 203 } 204 205 public void destroySubcontext(String name) throws NamingException { 206 throw new NotImplementedException(); 207 } 208 209 public Context createSubcontext(Name name) throws NamingException { 210 throw new NotImplementedException(); 211 } 212 213 public Context createSubcontext(String name) throws NamingException { 214 throw new NotImplementedException(); 215 } 216 217 public Object lookupLink(Name name) throws NamingException { 218 throw new NotImplementedException(); 219 } 220 221 public Object lookupLink(String name) throws NamingException { 222 throw new NotImplementedException(); 223 } 224 225 public NameParser getNameParser(Name name) throws NamingException { 226 throw new NotImplementedException(); 227 } 228 229 public NameParser getNameParser(String name) throws NamingException { 230 throw new NotImplementedException(); 231 } 232 233 public Name composeName(Name name, Name prefix) throws NamingException { 234 throw new NotImplementedException(); 235 } 236 237 public String composeName(String name, String prefix) throws NamingException { 238 throw new NotImplementedException(); 239 } 240 241 public Object addToEnvironment(String propName, Object propVal) throws NamingException { 242 throw new NotImplementedException(); 243 } 244 245 public Object removeFromEnvironment(String propName) throws NamingException { 246 throw new NotImplementedException(); 247 } 248 249 public Hashtable getEnvironment() throws NamingException { 250 throw new NotImplementedException(); 251 } 252 253 public void close() throws NamingException { 254 throw new NotImplementedException(); 255 } 256 257 public String getNameInNamespace() throws NamingException { 258 throw new NotImplementedException(); 259 } 260 261 } 262 | Popular Tags |