1 25 26 package org.objectweb.easybeans.component.smartclient.spi; 27 28 import java.util.Hashtable ; 29 30 import javax.naming.Binding ; 31 import javax.naming.Context ; 32 import javax.naming.Name ; 33 import javax.naming.NameClassPair ; 34 import javax.naming.NameParser ; 35 import javax.naming.NamingEnumeration ; 36 import javax.naming.NamingException ; 37 38 42 public class SmartContext implements Context { 43 44 47 private Context wrapped; 48 49 52 private ClassLoader classLoader; 53 54 60 public SmartContext(final Context wrapped, final ClassLoader classLoader) { 61 this.wrapped = wrapped; 62 this.classLoader = classLoader; 63 } 64 65 75 public Object addToEnvironment(final String propName, final Object propVal) throws NamingException { 76 ClassLoader old = Thread.currentThread().getContextClassLoader(); 77 Thread.currentThread().setContextClassLoader(classLoader); 78 try { 79 return wrapped.addToEnvironment(propName, propVal); 80 } finally { 81 Thread.currentThread().setContextClassLoader(old); 82 } 83 } 84 85 92 public void bind(final Name name, final Object obj) throws NamingException { 93 ClassLoader old = Thread.currentThread().getContextClassLoader(); 94 Thread.currentThread().setContextClassLoader(classLoader); 95 try { 96 wrapped.bind(name, obj); 97 } finally { 98 Thread.currentThread().setContextClassLoader(old); 99 } 100 } 101 102 109 public void bind(final String name, final Object obj) throws NamingException { 110 ClassLoader old = Thread.currentThread().getContextClassLoader(); 111 Thread.currentThread().setContextClassLoader(classLoader); 112 try { 113 wrapped.bind(name, obj); 114 } finally { 115 Thread.currentThread().setContextClassLoader(old); 116 } 117 } 118 119 123 public void close() throws NamingException { 124 ClassLoader old = Thread.currentThread().getContextClassLoader(); 125 Thread.currentThread().setContextClassLoader(classLoader); 126 try { 127 wrapped.close(); 128 } finally { 129 Thread.currentThread().setContextClassLoader(old); 130 } 131 } 132 133 140 public Name composeName(final Name name, final Name prefix) throws NamingException { 141 ClassLoader old = Thread.currentThread().getContextClassLoader(); 142 Thread.currentThread().setContextClassLoader(classLoader); 143 try { 144 return wrapped.composeName(name, prefix); 145 } finally { 146 Thread.currentThread().setContextClassLoader(old); 147 } 148 } 149 150 158 public String composeName(final String name, final String prefix) throws NamingException { 159 ClassLoader old = Thread.currentThread().getContextClassLoader(); 160 Thread.currentThread().setContextClassLoader(classLoader); 161 try { 162 return wrapped.composeName(name, prefix); 163 } finally { 164 Thread.currentThread().setContextClassLoader(old); 165 } 166 } 167 168 176 public Context createSubcontext(final Name name) throws NamingException { 177 ClassLoader old = Thread.currentThread().getContextClassLoader(); 178 Thread.currentThread().setContextClassLoader(classLoader); 179 try { 180 return wrapped.createSubcontext(name); 181 } finally { 182 Thread.currentThread().setContextClassLoader(old); 183 } 184 } 185 186 193 public Context createSubcontext(final String name) throws NamingException { 194 ClassLoader old = Thread.currentThread().getContextClassLoader(); 195 Thread.currentThread().setContextClassLoader(classLoader); 196 try { 197 return wrapped.createSubcontext(name); 198 } finally { 199 Thread.currentThread().setContextClassLoader(old); 200 } 201 202 } 203 204 210 public void destroySubcontext(final Name name) throws NamingException { 211 ClassLoader old = Thread.currentThread().getContextClassLoader(); 212 Thread.currentThread().setContextClassLoader(classLoader); 213 try { 214 wrapped.destroySubcontext(name); 215 } finally { 216 Thread.currentThread().setContextClassLoader(old); 217 } 218 } 219 220 226 public void destroySubcontext(final String name) throws NamingException { 227 ClassLoader old = Thread.currentThread().getContextClassLoader(); 228 Thread.currentThread().setContextClassLoader(classLoader); 229 try { 230 wrapped.destroySubcontext(name); 231 } finally { 232 Thread.currentThread().setContextClassLoader(old); 233 } 234 } 235 236 241 public Hashtable <?, ?> getEnvironment() throws NamingException { 242 ClassLoader old = Thread.currentThread().getContextClassLoader(); 243 Thread.currentThread().setContextClassLoader(classLoader); 244 try { 245 return wrapped.getEnvironment(); 246 } finally { 247 Thread.currentThread().setContextClassLoader(old); 248 } 249 } 250 251 256 public String getNameInNamespace() throws NamingException { 257 ClassLoader old = Thread.currentThread().getContextClassLoader(); 258 Thread.currentThread().setContextClassLoader(classLoader); 259 try { 260 return wrapped.getNameInNamespace(); 261 } finally { 262 Thread.currentThread().setContextClassLoader(old); 263 } 264 } 265 266 273 public NameParser getNameParser(final Name name) throws NamingException { 274 ClassLoader old = Thread.currentThread().getContextClassLoader(); 275 Thread.currentThread().setContextClassLoader(classLoader); 276 try { 277 return wrapped.getNameParser(name); 278 } finally { 279 Thread.currentThread().setContextClassLoader(old); 280 } 281 } 282 283 290 public NameParser getNameParser(final String name) throws NamingException { 291 ClassLoader old = Thread.currentThread().getContextClassLoader(); 292 Thread.currentThread().setContextClassLoader(classLoader); 293 try { 294 return wrapped.getNameParser(name); 295 } finally { 296 Thread.currentThread().setContextClassLoader(old); 297 } 298 299 } 300 301 311 public NamingEnumeration <NameClassPair > list(final Name name) throws NamingException { 312 ClassLoader old = Thread.currentThread().getContextClassLoader(); 313 Thread.currentThread().setContextClassLoader(classLoader); 314 try { 315 return wrapped.list(name); 316 } finally { 317 Thread.currentThread().setContextClassLoader(old); 318 } 319 320 } 321 322 331 public NamingEnumeration <NameClassPair > list(final String name) throws NamingException { 332 ClassLoader old = Thread.currentThread().getContextClassLoader(); 333 Thread.currentThread().setContextClassLoader(classLoader); 334 try { 335 return wrapped.list(name); 336 } finally { 337 Thread.currentThread().setContextClassLoader(old); 338 } 339 } 340 341 351 public NamingEnumeration <Binding > listBindings(final Name name) throws NamingException { 352 ClassLoader old = Thread.currentThread().getContextClassLoader(); 353 Thread.currentThread().setContextClassLoader(classLoader); 354 try { 355 return wrapped.listBindings(name); 356 } finally { 357 Thread.currentThread().setContextClassLoader(old); 358 } 359 } 360 361 369 public NamingEnumeration <Binding > listBindings(final String name) throws NamingException { 370 ClassLoader old = Thread.currentThread().getContextClassLoader(); 371 Thread.currentThread().setContextClassLoader(classLoader); 372 try { 373 return wrapped.listBindings(name); 374 } finally { 375 Thread.currentThread().setContextClassLoader(old); 376 } 377 } 378 379 385 public Object lookup(final Name name) throws NamingException { 386 ClassLoader old = Thread.currentThread().getContextClassLoader(); 387 Thread.currentThread().setContextClassLoader(classLoader); 388 try { 389 return wrapped.lookup(name); 390 } finally { 391 Thread.currentThread().setContextClassLoader(old); 392 } 393 } 394 395 401 public Object lookup(final String name) throws NamingException { 402 ClassLoader old = Thread.currentThread().getContextClassLoader(); 403 Thread.currentThread().setContextClassLoader(classLoader); 404 try { 405 return wrapped.lookup(name); 406 } finally { 407 Thread.currentThread().setContextClassLoader(old); 408 } 409 } 410 411 420 public Object lookupLink(final Name name) throws NamingException { 421 ClassLoader old = Thread.currentThread().getContextClassLoader(); 422 Thread.currentThread().setContextClassLoader(classLoader); 423 try { 424 return wrapped.lookupLink(name); 425 } finally { 426 Thread.currentThread().setContextClassLoader(old); 427 } 428 } 429 430 439 public Object lookupLink(final String name) throws NamingException { 440 ClassLoader old = Thread.currentThread().getContextClassLoader(); 441 Thread.currentThread().setContextClassLoader(classLoader); 442 try { 443 return wrapped.lookupLink(name); 444 } finally { 445 Thread.currentThread().setContextClassLoader(old); 446 } 447 } 448 449 455 public void rebind(final Name name, final Object obj) throws NamingException { 456 ClassLoader old = Thread.currentThread().getContextClassLoader(); 457 Thread.currentThread().setContextClassLoader(classLoader); 458 try { 459 wrapped.rebind(name, obj); 460 } finally { 461 Thread.currentThread().setContextClassLoader(old); 462 } 463 464 } 465 466 473 public void rebind(final String name, final Object obj) throws NamingException { 474 ClassLoader old = Thread.currentThread().getContextClassLoader(); 475 Thread.currentThread().setContextClassLoader(classLoader); 476 try { 477 wrapped.rebind(name, obj); 478 } finally { 479 Thread.currentThread().setContextClassLoader(old); 480 } 481 } 482 483 491 public Object removeFromEnvironment(final String propName) throws NamingException { 492 ClassLoader old = Thread.currentThread().getContextClassLoader(); 493 Thread.currentThread().setContextClassLoader(classLoader); 494 try { 495 return wrapped.removeFromEnvironment(propName); 496 } finally { 497 Thread.currentThread().setContextClassLoader(old); 498 } 499 500 } 501 502 509 public void rename(final Name oldName, final Name newName) throws NamingException { 510 ClassLoader old = Thread.currentThread().getContextClassLoader(); 511 Thread.currentThread().setContextClassLoader(classLoader); 512 try { 513 wrapped.rename(oldName, newName); 514 } finally { 515 Thread.currentThread().setContextClassLoader(old); 516 } 517 } 518 519 526 public void rename(final String oldName, final String newName) throws NamingException { 527 ClassLoader old = Thread.currentThread().getContextClassLoader(); 528 Thread.currentThread().setContextClassLoader(classLoader); 529 try { 530 wrapped.rename(oldName, newName); 531 } finally { 532 Thread.currentThread().setContextClassLoader(old); 533 } 534 } 535 536 542 public void unbind(final Name name) throws NamingException { 543 ClassLoader old = Thread.currentThread().getContextClassLoader(); 544 Thread.currentThread().setContextClassLoader(classLoader); 545 try { 546 wrapped.unbind(name); 547 } finally { 548 Thread.currentThread().setContextClassLoader(old); 549 } 550 551 } 552 553 560 public void unbind(final String name) throws NamingException { 561 ClassLoader old = Thread.currentThread().getContextClassLoader(); 562 Thread.currentThread().setContextClassLoader(classLoader); 563 try { 564 wrapped.unbind(name); 565 } finally { 566 Thread.currentThread().setContextClassLoader(old); 567 } 568 569 } 570 571 } 572 | Popular Tags |