1 package org.simantics.scl.runtime;
3 import gnu.trove.map.hash.THashMap;
5 public class SCLContext extends THashMap<String,Object> {
6 private static ThreadLocal<SCLContext> CONTEXT = new ThreadLocal<SCLContext>();
7 private static ThreadLocal<OldContextNode> OLD_CONTEXT = new ThreadLocal<OldContextNode>();
9 private static class OldContextNode {
10 final SCLContext context;
11 final OldContextNode next;
13 public OldContextNode(SCLContext context, OldContextNode next) {
14 this.context = context;
19 public static SCLContext getCurrent() {
20 SCLContext context = CONTEXT.get();
22 context = new SCLContext();
28 public static void push(SCLContext newContext) {
29 SCLContext oldContext = CONTEXT.get();
30 if(oldContext != null)
31 OLD_CONTEXT.set(new OldContextNode(oldContext, OLD_CONTEXT.get()));
32 CONTEXT.set(newContext);
35 public static void pop() {
36 OldContextNode node = OLD_CONTEXT.get();
40 CONTEXT.set(node.context);
41 OLD_CONTEXT.set(node.next);
47 public Object get(Object key) {
48 Object result = super.get(key);
49 System.out.println(this + ": " + key + " -> " + result);
54 public Object put(String key, Object value) {
55 System.out.println(this + ": " + key + " <- " + value);
56 return super.put(key, value);