# HG changeset patch # User Jaroslav Tulach # Date 1379065842 -7200 # Node ID 74e862ea824eb59996830f82185633cfcdf118bf # Parent aee69a14a859788ac7c88ddd4ca740e415ba4a17 Context should be shared per classloader diff -r aee69a14a859 -r 74e862ea824e context/src/main/java/net/java/html/BrwsrCtx.java --- a/context/src/main/java/net/java/html/BrwsrCtx.java Fri Sep 13 11:49:26 2013 +0200 +++ b/context/src/main/java/net/java/html/BrwsrCtx.java Fri Sep 13 11:50:42 2013 +0200 @@ -20,6 +20,8 @@ */ package net.java.html; +import java.util.HashMap; +import java.util.Map; import java.util.ServiceLoader; import org.apidesign.html.context.impl.CtxAccssr; import org.apidesign.html.context.impl.CtxImpl; @@ -58,6 +60,8 @@ * code. */ public static final BrwsrCtx EMPTY = Contexts.newBuilder().build(); + /** map of known classloaders and their contexts */ + private static final Map CTXS = new HashMap(); /** Seeks for the default context that is associated with the requesting * class. If no suitable context is found, a warning message is @@ -77,6 +81,13 @@ l = null; } + synchronized (CTXS) { + BrwsrCtx c = CTXS.get(l); + if (c != null) { + return c; + } + } + for (org.apidesign.html.context.spi.Contexts.Provider cp : ServiceLoader.load( org.apidesign.html.context.spi.Contexts.Provider.class, l )) { @@ -98,7 +109,12 @@ // XXX: print out a warning return EMPTY; } - return cb.build(); + BrwsrCtx c = cb.build(); + + synchronized (CTXS) { + CTXS.put(l, c); + } + return c; } }