Author: fmeschbe
Date: Wed Aug 11 18:30:51 2010
New Revision: 984520
URL: http://svn.apache.org/viewvc?rev=984520&view=rev
Log:
Move removing servlet context attributes to when the servlet context is unbound
and add the AnnotationProcessor class
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=984520&r1=984519&r2=984520&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Wed Aug 11 18:30:51 2010
@@ -37,7 +37,6 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingConstants;
import org.apache.sling.api.SlingException;
-import org.apache.sling.api.SlingIOException;
import org.apache.sling.api.SlingServletException;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.scripting.SlingBindings;
@@ -51,6 +50,7 @@ import org.apache.sling.scripting.api.Ab
import org.apache.sling.scripting.jsp.jasper.JasperException;
import org.apache.sling.scripting.jsp.jasper.Options;
import org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext;
+import org.apache.sling.scripting.jsp.jasper.runtime.AnnotationProcessor;
import org.apache.sling.scripting.jsp.jasper.runtime.JspApplicationContextImpl;
import org.apache.sling.scripting.jsp.util.TagUtil;
import org.osgi.framework.ServiceRegistration;
@@ -87,7 +87,7 @@ public class JspScriptEngineFactory
/** Default logger */
private final Logger logger =
LoggerFactory.getLogger(JspScriptEngineFactory.class);
- @Reference
+ @Reference(unbind="unbindSlingServletContext")
private ServletContext slingServletContext;
@Reference
@@ -277,22 +277,44 @@ public class JspScriptEngineFactory
}
ioProvider = null;
+ }
+
+ /**
+ * Unbinds the Sling ServletContext and removes any known servlet context
+ * attributes preventing the bundles's class loader from being collected.
+ *
+ * @param slingServletContext The <code>ServletContext</code> to be unbound
+ */
+ protected void unbindSlingServletContext(
+ final ServletContext slingServletContext) {
- // remove JspApplicationContextImpl from the servlet context, otherwise
- // a ClassCastException may be caused after this component is recreated
- // because the class loader of the JspApplicationContextImpl class
- // object is different from the one stored in the servlet context
+ // remove JspApplicationContextImpl from the servlet context,
+ // otherwise a ClassCastException may be caused after this component
+ // is recreated because the class loader of the
+ // JspApplicationContextImpl class object is different from the one
+ // stored in the servlet context same for the AnnotationProcessor
+ // (which generally does not exist here)
try {
-
slingServletContext.removeAttribute(JspApplicationContextImpl.class.getName());
+ if (slingServletContext != null) {
+
slingServletContext.removeAttribute(JspApplicationContextImpl.class.getName());
+
slingServletContext.removeAttribute(AnnotationProcessor.class.getName());
+ }
} catch (NullPointerException npe) {
// SLING-530, might be thrown on system shutdown in a servlet
// container when using the Equinox servlet container bridge
- logger.debug("deactivate: ServletContext might already be
unavailable", npe);
+ logger.debug(
+ "unbindSlingServletContext: ServletContext might already be
unavailable",
+ npe);
+ }
+
+ if (this.slingServletContext == slingServletContext) {
+ this.slingServletContext = null;
}
}
/**
* Bind the class load provider.
+ *
* @param repositoryClassLoaderProvider the new provider
*/
protected void bindDynamicClassLoaderManager(final
DynamicClassLoaderManager rclp) {