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.context;
06:
07: //
08: // this class may introduce some performance troubles using java 1.2,
09: // but they are reported to be fixed in java 1.3.
10: //
11:
12: public class DesktopContextThreadLocalizer {
13: //private static InheritableThreadLocal desktopContextThreadLocal = new InheritableThreadLocal();
14: private static ThreadLocal desktopContextThreadLocal = new ThreadLocal();
15:
16: private DesktopContextThreadLocalizer() {
17: // nothing, cannot be called
18: }
19:
20: public static DesktopContext get() {
21: DesktopContext dc = (DesktopContext) desktopContextThreadLocal
22: .get();
23: if (dc == null) {
24: throw new ContextError(
25: "DesktopContextThreadLocalizer.get(): no thread local set for this thread ID="
26: + Thread.currentThread().getName());
27: }
28:
29: return dc;
30: }
31:
32: public static void set(DesktopContext dc) {
33: desktopContextThreadLocal.set(dc);
34: }
35:
36: public static boolean exists() {
37: DesktopContext dc = (DesktopContext) desktopContextThreadLocal
38: .get();
39: if (dc != null)
40: return true;
41: else
42: return false;
43: }
44: }
|