01: /*
02: * @(#)threadLocal.java 1.2 04/12/06
03: *
04: * Copyright (c) 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.multithread;
10:
11: import pnuts.lang.Context;
12: import pnuts.lang.PnutsFunction;
13: import pnuts.lang.Property;
14: import pnuts.lang.Package;
15:
16: public class threadLocal extends PnutsFunction {
17:
18: final static ThreadLocalPackage instance = new ThreadLocalPackage();
19:
20: public threadLocal() {
21: super ("threadLocal");
22: }
23:
24: public boolean defined(int nargs) {
25: return nargs == 0;
26: }
27:
28: protected Object exec(Object[] args, Context context) {
29: if (args.length != 0) {
30: undefined(args, context);
31: return null;
32: }
33: return instance;
34: }
35:
36: static class ThreadLocalPackage extends ThreadLocal implements
37: Property {
38:
39: protected Object initialValue() {
40: return new Package(null, null);
41: }
42:
43: public Object get(String symbol, Context context) {
44: return ((Package) super .get()).get(symbol);
45: }
46:
47: public void set(String symbol, Object value, Context context) {
48: ((Package) super .get()).set(symbol, value);
49: }
50: }
51:
52: public String toString() {
53: return "function threadLocal()";
54: }
55: }
|