private void loadTagFile()

in src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/TagFileProcessor.java [534:630]


    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(),
                      ctxt.getTagFileJarUrl(tagFilePath));
                wrapper.getJspEngineContext().setTagFileUrls(ctxt);
                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(),
                          ctxt.getTagFileJarUrl(tempTagFilePath));
                    tempWrapper.getJspEngineContext().setTagFileUrls(ctxt);
                    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();
            }

            // Add the dependants for this tag file to its parent's
            // dependant list. The only reliable dependency information
            // 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);
        }
    }