Search in sources :

Example 1 with AnnotationProcessor

use of org.apache.sling.scripting.jsp.jasper.runtime.AnnotationProcessor in project sling by apache.

the class JspServletWrapper method destroy.

/**
     * Destroy this wrapper
     * @param deleteGeneratedFiles Should generated files be deleted as well?
     */
public void destroy(final boolean deleteGeneratedFiles) {
    if (this.isTagFile) {
        if (log.isDebugEnabled()) {
            log.debug("Destroying tagfile " + jspUri);
        }
        this.tagFileClass = null;
        if (deleteGeneratedFiles) {
            if (log.isDebugEnabled()) {
                log.debug("Deleting generated files for tagfile " + jspUri);
            }
            this.ctxt.getRuntimeContext().getIOProvider().delete(this.getDependencyFilePath());
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Destroying servlet " + jspUri);
        }
        if (theServlet != null) {
            if (deleteGeneratedFiles) {
                if (log.isDebugEnabled()) {
                    log.debug("Deleting generated files for servlet " + jspUri);
                }
                final String name;
                if (isTagFile) {
                    name = this.ctxt.getTagInfo().getTagClassName();
                } else {
                    name = this.ctxt.getServletPackageName() + "." + this.ctxt.getServletClassName();
                }
                final String path = ":/" + name.replace('.', '/') + ".class";
                this.ctxt.getRuntimeContext().getIOProvider().delete(path);
                this.ctxt.getRuntimeContext().getIOProvider().delete(this.getDependencyFilePath());
                final org.apache.sling.scripting.jsp.jasper.compiler.Compiler c = this.ctxt.getCompiler();
                if (c != null) {
                    c.removeGeneratedFiles();
                }
            }
            theServlet.destroy();
            AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
            if (annotationProcessor != null) {
                try {
                    annotationProcessor.preDestroy(theServlet);
                } catch (Exception e) {
                    // Log any exception, since it can't be passed along
                    log.error(Localizer.getMessage("jsp.error.file.not.found", e.getMessage()), e);
                }
            }
            theServlet = null;
        }
    }
}
Also used : AnnotationProcessor(org.apache.sling.scripting.jsp.jasper.runtime.AnnotationProcessor) ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingException(org.apache.sling.api.SlingException) IOException(java.io.IOException) SlingIOException(org.apache.sling.api.SlingIOException) UnavailableException(javax.servlet.UnavailableException) ScriptEvaluationException(org.apache.sling.api.scripting.ScriptEvaluationException) SlingPageException(org.apache.sling.scripting.jsp.SlingPageException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Example 2 with AnnotationProcessor

use of org.apache.sling.scripting.jsp.jasper.runtime.AnnotationProcessor in project sling by apache.

the class JspServletWrapper method loadServlet.

@SuppressWarnings("unchecked")
private Servlet loadServlet() throws ServletException, IOException {
    Servlet servlet = null;
    try {
        if (log.isDebugEnabled()) {
            log.debug("Loading servlet " + jspUri);
        }
        servlet = (Servlet) ctxt.load().newInstance();
        AnnotationProcessor annotationProcessor = (AnnotationProcessor) config.getServletContext().getAttribute(AnnotationProcessor.class.getName());
        if (annotationProcessor != null) {
            annotationProcessor.processAnnotations(servlet);
            annotationProcessor.postConstruct(servlet);
        }
        // update dependents
        final List<String> oldDeps = this.dependents;
        if (servlet != null && servlet instanceof JspSourceDependent) {
            this.dependents = (List<String>) ((JspSourceDependent) servlet).getDependants();
            if (this.dependents == null) {
                this.dependents = Collections.EMPTY_LIST;
            }
            this.ctxt.getRuntimeContext().addJspDependencies(this, this.dependents);
        }
        if (!equals(oldDeps, this.dependents)) {
            this.persistDependencies();
        }
    } catch (final IllegalAccessException e) {
        throw new JasperException(e);
    } catch (final InstantiationException e) {
        throw new JasperException(e);
    } catch (final Exception e) {
        throw new JasperException(e);
    }
    servlet.init(config);
    return servlet;
}
Also used : JasperException(org.apache.sling.scripting.jsp.jasper.JasperException) Servlet(javax.servlet.Servlet) AnnotationProcessor(org.apache.sling.scripting.jsp.jasper.runtime.AnnotationProcessor) JspSourceDependent(org.apache.sling.scripting.jsp.jasper.runtime.JspSourceDependent) ServletException(javax.servlet.ServletException) SlingServletException(org.apache.sling.api.SlingServletException) SlingException(org.apache.sling.api.SlingException) IOException(java.io.IOException) SlingIOException(org.apache.sling.api.SlingIOException) UnavailableException(javax.servlet.UnavailableException) ScriptEvaluationException(org.apache.sling.api.scripting.ScriptEvaluationException) SlingPageException(org.apache.sling.scripting.jsp.SlingPageException) JasperException(org.apache.sling.scripting.jsp.jasper.JasperException)

Aggregations

IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 UnavailableException (javax.servlet.UnavailableException)2 SlingException (org.apache.sling.api.SlingException)2 SlingIOException (org.apache.sling.api.SlingIOException)2 SlingServletException (org.apache.sling.api.SlingServletException)2 ScriptEvaluationException (org.apache.sling.api.scripting.ScriptEvaluationException)2 SlingPageException (org.apache.sling.scripting.jsp.SlingPageException)2 JasperException (org.apache.sling.scripting.jsp.jasper.JasperException)2 AnnotationProcessor (org.apache.sling.scripting.jsp.jasper.runtime.AnnotationProcessor)2 Servlet (javax.servlet.Servlet)1 JspSourceDependent (org.apache.sling.scripting.jsp.jasper.runtime.JspSourceDependent)1