1.1 --- a/context/src/main/java/net/java/html/BrwsrCtx.java Fri Sep 13 11:49:26 2013 +0200
1.2 +++ b/context/src/main/java/net/java/html/BrwsrCtx.java Fri Sep 13 11:50:42 2013 +0200
1.3 @@ -20,6 +20,8 @@
1.4 */
1.5 package net.java.html;
1.6
1.7 +import java.util.HashMap;
1.8 +import java.util.Map;
1.9 import java.util.ServiceLoader;
1.10 import org.apidesign.html.context.impl.CtxAccssr;
1.11 import org.apidesign.html.context.impl.CtxImpl;
1.12 @@ -58,6 +60,8 @@
1.13 * code.
1.14 */
1.15 public static final BrwsrCtx EMPTY = Contexts.newBuilder().build();
1.16 + /** map of known classloaders and their contexts */
1.17 + private static final Map<ClassLoader,BrwsrCtx> CTXS = new HashMap<ClassLoader, BrwsrCtx>();
1.18
1.19 /** Seeks for the default context that is associated with the requesting
1.20 * class. If no suitable context is found, a warning message is
1.21 @@ -77,6 +81,13 @@
1.22 l = null;
1.23 }
1.24
1.25 + synchronized (CTXS) {
1.26 + BrwsrCtx c = CTXS.get(l);
1.27 + if (c != null) {
1.28 + return c;
1.29 + }
1.30 + }
1.31 +
1.32 for (org.apidesign.html.context.spi.Contexts.Provider cp : ServiceLoader.load(
1.33 org.apidesign.html.context.spi.Contexts.Provider.class, l
1.34 )) {
1.35 @@ -98,7 +109,12 @@
1.36 // XXX: print out a warning
1.37 return EMPTY;
1.38 }
1.39 - return cb.build();
1.40 + BrwsrCtx c = cb.build();
1.41 +
1.42 + synchronized (CTXS) {
1.43 + CTXS.put(l, c);
1.44 + }
1.45 + return c;
1.46 }
1.47
1.48 }