context =new JspCServletContext
(new PrintWriter(System.out),
new URL("file:" + uriRoot.replace('\\','/') + '/'));
- tldLocationsCache = new TldLocationsCache(context);
+ tldLocationsCache = TldLocationsCache.getInstance(context);
} catch (MalformedURLException me) {
System.out.println("**" + me);
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.jasper.compiler;
import java.io.File;
import org.apache.tomcat.JarScanner;
import org.apache.tomcat.JarScannerCallback;
+
/**
* A container for all tag libraries that are defined "globally"
* for the web application.
public class TldLocationsCache {
- private final Log log = LogFactory.getLog(TldLocationsCache.class);
+ private static final Log log = LogFactory.getLog(TldLocationsCache.class);
+
+ private static final String KEY = TldLocationsCache.class.getName();
/**
* The types of URI one may specify for a tag library
*/
private Hashtable<String, TldLocation> mappings;
- private boolean initialized;
+ private volatile boolean initialized;
private ServletContext ctxt;
/** Constructor.
}
}
+
+ /**
+ * Obtains the TLD location cache for the given {@link ServletContext} and
+ * creates one if one does not currently exist.
+ */
+ public static synchronized TldLocationsCache getInstance(
+ ServletContext ctxt) {
+ if (ctxt == null) {
+ throw new IllegalArgumentException("ServletContext was null");
+ }
+ TldLocationsCache cache = (TldLocationsCache) ctxt.getAttribute(KEY);
+ if (cache == null) {
+ cache = new TldLocationsCache(ctxt);
+ ctxt.setAttribute(KEY, cache);
+ }
+ return cache;
+ }
+
/**
* Gets the 'location' of the TLD associated with the given taglib 'uri'.
*
* wonderful arrangements present when Tomcat gets embedded.
*
*/
- private void init() throws JasperException {
+ private synchronized void init() throws JasperException {
if (initialized) return;
try {
tldScanWebXml();