use of org.apache.sling.scripting.jsp.jasper.runtime.JspSourceDependent 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;
}
use of org.apache.sling.scripting.jsp.jasper.runtime.JspSourceDependent in project sling by apache.
the class TagFileProcessor method loadTagFile.
/**
* Compiles and loads a tagfile.
*/
private void loadTagFile(Compiler compiler, String tagFilePath, Node.CustomTag n, PageInfo parentPageInfo) throws JasperException {
JspCompilationContext ctxt = compiler.getCompilationContext();
JspRuntimeContext rctxt = ctxt.getRuntimeContext();
rctxt.lockTagFileLoading(tagFilePath);
try {
JspServletWrapper wrapper = rctxt.getWrapper(tagFilePath);
if (wrapper == null) {
wrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, n.getTagInfo(), ctxt.getRuntimeContext(), compiler.getDefaultIsSession(), ctxt.getTagFileJarUrl(tagFilePath));
wrapper = rctxt.addWrapper(tagFilePath, wrapper);
// Use same classloader and classpath for compiling tag files
//wrapper.getJspEngineContext().setClassLoader(ctxt.getClassLoader());
//wrapper.getJspEngineContext().setClassPath(ctxt.getClassPath());
} else {
// Make sure that JspCompilationContext gets the latest TagInfo
// for the tag file. TagInfo instance was created the last
// time the tag file was scanned for directives, and the tag
// file may have been modified since then.
wrapper.getJspEngineContext().setTagInfo(n.getTagInfo());
}
Class tagClazz;
int tripCount = wrapper.incTripCount();
try {
if (tripCount > 0) {
final String postfix = "_" + String.valueOf(tripCount);
// When tripCount is greater than zero, a circular
// dependency exists. The circularily dependant tag
// file is compiled in prototype mode, to avoid infinite
// recursion.
final String tempTagFilePath = tagFilePath + postfix;
final TagInfo tempTagInfo = new JasperTagInfo(n.getTagInfo().getTagName(), n.getTagInfo().getTagClassName() + postfix, n.getTagInfo().getBodyContent(), n.getTagInfo().getInfoString(), n.getTagInfo().getTagLibrary(), n.getTagInfo().getTagExtraInfo(), n.getTagInfo().getAttributes(), n.getTagInfo().getDisplayName(), n.getTagInfo().getSmallIcon(), n.getTagInfo().getLargeIcon(), n.getTagInfo().getTagVariableInfos(), ((JasperTagInfo) n.getTagInfo()).getDynamicAttributesMapName());
JspServletWrapper tempWrapper = new JspServletWrapper(ctxt.getServletContext(), ctxt.getOptions(), tagFilePath, tempTagInfo, ctxt.getRuntimeContext(), compiler.getDefaultIsSession(), ctxt.getTagFileJarUrl(tempTagFilePath));
tagClazz = tempWrapper.loadTagFilePrototype();
tempVector.add(tempWrapper.getJspEngineContext().getCompiler());
String name = JspUtil.getCanonicalName(tagClazz);
final int underscorePos = name.lastIndexOf(postfix);
if (underscorePos > -1) {
n.setTagHandlerClassName(name.substring(0, underscorePos));
}
} else {
tagClazz = wrapper.loadTagFile();
}
} finally {
wrapper.decTripCount();
}
// can only be obtained from the tag instance.
try {
Object tagIns = tagClazz.newInstance();
if (tagIns instanceof JspSourceDependent) {
Iterator iter = ((List) ((JspSourceDependent) tagIns).getDependants()).iterator();
while (iter.hasNext()) {
parentPageInfo.addDependant((String) iter.next());
}
}
} catch (Exception e) {
// ignore errors
}
n.setTagHandlerClass(tagClazz);
} finally {
rctxt.unlockTagFileLoading(tagFilePath);
}
}
Aggregations