1 23 package com.sun.enterprise.naming.java; 24 25 import java.util.*; 26 import java.io.*; 27 import javax.naming.*; 28 import com.sun.enterprise.Switch; 29 import com.sun.enterprise.naming.*; 30 import com.sun.enterprise.util.ORBManager; 31 import com.sun.enterprise.distributedtx.UserTransactionImpl; 32 import com.sun.enterprise.distributedtx.TransactionSynchronizationRegistryImpl; 33 34 import java.util.logging.*; 36 import com.sun.logging.*; 37 39 40 46 47 public final class javaURLContext implements Context, Cloneable { 48 49 static Logger _logger=LogDomains.getLogger(LogDomains.JNDI_LOGGER); 51 53 private static final String ORB_STRING = "java:comp/ORB"; 55 private static final String HANDLE_DELEGATE = "java:comp/HandleDelegate"; 56 private static final String USER_TX = "java:comp/UserTransaction"; 57 private static final String EJB_CONTEXT = "java:comp/EJBContext"; 58 private static final String EJB_TIMER_SERVICE = "java:comp/TimerService"; 59 private static final String TRANSACTION_SYNC_REGISTRY = 60 "java:comp/TransactionSynchronizationRegistry"; 61 private static final String TRANSACTION_MGR = "java:pm/TransactionManager"; 62 public static final String APPSERVER_TRANSACTION_MGR = "java:appserver/TransactionManager"; 63 64 65 private static final boolean debug = false; 66 67 private NamingManagerImpl namingManager; 68 private Hashtable myEnv; 69 private String myName=""; 71 72 private SerialContext serialContext = null; 73 74 77 public javaURLContext(Hashtable environment) 78 throws NamingException 79 { 80 myEnv = (environment != null) ? (Hashtable)(environment.clone()) : null; 81 if (namingManager == null ) { 82 namingManager = (NamingManagerImpl) 83 Switch.getSwitch().getNamingManager(); 84 } 85 } 86 87 91 public javaURLContext(String name, Hashtable env) 92 throws NamingException 93 { 94 this(env); 95 this.myName = name; 96 } 97 98 101 public javaURLContext(Hashtable env, SerialContext serialContext) 102 throws NamingException 103 { 104 this(env); 105 this.serialContext = serialContext; 106 } 107 108 113 public javaURLContext addStickyContext(SerialContext serialContext) 114 throws NamingException { 115 try { 116 javaURLContext jCtx = (javaURLContext)this.clone(); 117 jCtx.serialContext = serialContext; 118 return jCtx; 119 } catch (java.lang.CloneNotSupportedException ex) { 120 NamingException ne = new NamingException("problem with cloning javaURLContext instance"); 121 ne.initCause(ex); 122 throw ne; 123 } 124 } 125 126 131 public Object lookup(String name) throws NamingException { 132 if (_logger.isLoggable(Level.FINE)) 133 _logger.log(Level.FINE,"In javaURLContext.lookup, name = "+name + " serialcontext..." + serialContext); 134 135 if ( name.equals("") ) { 136 142 return new javaURLContext(myName, myEnv); 143 } 144 145 String fullName = name; 146 if ( !myName.equals("") ) { 147 if ( myName.equals("java:") ) 148 fullName = myName + name; 149 else 150 fullName = myName + "/" + name; 151 } 152 153 try { 154 if ( fullName.startsWith("java:comp/env") ) { 155 return namingManager.lookup(fullName, serialContext); 157 } 158 else { 159 if( fullName.equals(ORB_STRING) ) { 161 return ORBManager.getORB(); 163 } 164 else if ( fullName.equals(USER_TX) ) { 165 return new UserTransactionImpl(); 167 } 168 else if ( fullName.equals(EJB_TIMER_SERVICE) ) { 169 return Switch.getSwitch().getContainerFactory(). 171 getEJBContextObject("javax.ejb.TimerService"); 172 } else if ( fullName.equals(EJB_CONTEXT) ) { 173 return Switch.getSwitch().getContainerFactory(). 175 getEJBContextObject("javax.ejb.EJBContext"); 176 } else if ( fullName.equals(HANDLE_DELEGATE) ) { 177 return Switch.getSwitch().getHandleDelegate(); 178 } 179 else if ( fullName.equals(TRANSACTION_MGR) ) { 180 return Switch.getSwitch().getContainerFactory().getTransactionMgr(); 181 } 182 else if ( fullName.equals(APPSERVER_TRANSACTION_MGR) ) { 183 return com.sun.enterprise.transaction.TransactionManagerHelper.getTransactionManager(); 184 } 185 else if ( fullName.equals(TRANSACTION_SYNC_REGISTRY) ) { 186 return TransactionSynchronizationRegistryImpl.getInstance(); 187 } 188 else { 189 return namingManager.lookup(fullName, serialContext); 191 } 192 } 193 } catch ( NamingException ex ) { 194 throw ex; 195 } catch ( Exception ex ) { 196 throw (NamingException)(new NameNotFoundException("No object bound for "+fullName)).initCause(ex); 197 } 198 } 199 200 205 public Object lookup(Name name) throws NamingException { 206 return lookup(name.toString()); 208 } 209 210 215 public void bind(String name, Object obj) throws NamingException { 216 throw new NamingException("java:comp namespace cannot be modified"); 217 } 218 219 224 public void bind(Name name, Object obj) throws NamingException { 225 throw new NamingException("java:comp namespace cannot be modified"); 226 } 227 228 233 public void rebind(String name, Object obj) throws NamingException { 234 throw new NamingException("java:comp namespace cannot be modified"); 235 } 236 237 242 public void rebind(Name name, Object obj) throws NamingException { 243 throw new NamingException("java:comp namespace cannot be modified"); 244 } 245 246 250 public void unbind(String name) throws NamingException { 251 throw new NamingException("java:comp namespace cannot be modified"); 252 } 253 254 258 public void unbind(Name name) throws NamingException { 259 throw new NamingException("java:comp namespace cannot be modified"); 260 } 261 262 266 public void rename(String oldname, String newname) throws NamingException { 267 throw new NamingException("java:comp namespace cannot be modified"); 268 } 269 270 274 public void rename(Name oldname, Name newname) 275 throws NamingException { 276 throw new NamingException("java:comp namespace cannot be modified"); 277 } 278 279 283 public void destroySubcontext(String name) throws NamingException { 284 throw new NamingException("java:comp namespace cannot be modified"); 285 } 286 287 291 public void destroySubcontext(Name name) throws NamingException { 292 throw new NamingException("java:comp namespace cannot be modified"); 293 } 294 295 public Context createSubcontext(String name) throws NamingException { 296 throw new NamingException("java:comp namespace cannot be modified"); 297 } 298 299 public Context createSubcontext(Name name) throws NamingException { 300 throw new NamingException("java:comp namespace cannot be modified"); 301 } 302 303 304 310 public NamingEnumeration list(String name) 311 throws NamingException { 312 if (name.equals("")) { 313 if ( namingManager == null ) 315 throw new NamingException(); 316 return namingManager.list(myName); 317 } 318 319 Object target = lookup(name); 321 if (target instanceof Context) { 322 return ((Context)target).list(""); 323 } 324 throw new NotContextException(name + " cannot be listed"); 325 } 326 327 333 public NamingEnumeration list(Name name) 334 throws NamingException { 335 return list(name.toString()); 337 } 338 339 345 public NamingEnumeration listBindings(String name) 346 throws NamingException { 347 if (name.equals("")) { 348 if ( namingManager == null ) 350 throw new NamingException(); 351 return namingManager.listBindings(myName); 352 } 353 354 Object target = lookup(name); 356 if (target instanceof Context) { 357 return ((Context)target).listBindings(""); 358 } 359 throw new NotContextException(name + " cannot be listed"); 360 } 361 362 368 public NamingEnumeration listBindings(Name name) 369 throws NamingException { 370 return listBindings(name.toString()); 372 } 373 374 378 public Object lookupLink(String name) throws NamingException { 379 return lookup(name); 381 } 382 383 387 public Object lookupLink(Name name) throws NamingException { 388 return lookupLink(name.toString()); 390 } 391 392 397 public NameParser getNameParser(String name) 398 throws NamingException { 399 if ( namingManager == null ) 400 throw new NamingException(); 401 return namingManager.getNameParser(); 402 } 403 404 409 public NameParser getNameParser(Name name) throws NamingException { 410 return getNameParser(name.toString()); 412 } 413 414 public String composeName(String name, String prefix) 415 throws NamingException { 416 Name result = composeName(new CompositeName(name), 417 new CompositeName(prefix)); 418 return result.toString(); 419 } 420 421 public Name composeName(Name name, Name prefix) 422 throws NamingException { 423 Name result = (Name)(prefix.clone()); 424 result.addAll(name); 425 return result; 426 } 427 428 431 public Object addToEnvironment(String propName, Object propVal) 432 throws NamingException { 433 if (myEnv == null) { 434 myEnv = new Hashtable(5, 0.75f); 435 } 436 return myEnv.put(propName, propVal); 437 } 438 439 442 public Object removeFromEnvironment(String propName) 443 throws NamingException 444 { 445 if (myEnv == null) { 446 return null; 447 } 448 return myEnv.remove(propName); 449 } 450 451 454 public Hashtable getEnvironment() throws NamingException { 455 if (myEnv == null) { 456 myEnv = new Hashtable(3, 0.75f); 458 } 459 return myEnv; 460 } 461 462 465 public void close() throws NamingException { 466 myEnv = null; 467 } 468 469 474 public String getNameInNamespace() throws NamingException { 475 return myName; 476 } 477 } 478 479 480 | Popular Tags |