01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.desktop;
06:
07: import javax.servlet.ServletContext;
08:
09: public class ServletContextThreadLocalizer {
10: private static ThreadLocal servletContextThreadLocal = new ThreadLocal();
11:
12: private ServletContextThreadLocalizer() {
13: // nothing, cannot be called
14: }
15:
16: public static ServletContext get() {
17: ServletContext sc = (ServletContext) servletContextThreadLocal
18: .get();
19: if (sc == null) {
20: throw new DesktopError(
21: "ServletContextThreadLocalizer.get(): no thread local set for this thread");
22: }
23:
24: return sc;
25: }
26:
27: public static void set(ServletContext sc) {
28: servletContextThreadLocal.set(sc);
29: }
30:
31: public static synchronized boolean exists() {
32: ServletContext sc = (ServletContext) servletContextThreadLocal
33: .get();
34: if (sc != null)
35: return true;
36: else
37: return false;
38: }
39: }
|