FileDocCategorySizeDatePackage
SmapUtil.javaAPI DocGlassfish v2 API24353Fri May 04 22:32:52 BST 2007org.apache.jasper.compiler

SmapUtil

public class SmapUtil extends Object
Contains static utilities for generating SMAP data based on the current version of Jasper.
author
Jayson Falkner
author
Shawn Bayern
author
Robert Field (inner SDEInstaller class)
author
Mark Roth
author
Kin-man Chung

Fields Summary
private org.apache.jasper.JspCompilationContext
ctxt
private List
classInfos
public static final String
SMAP_ENCODING
Constructors Summary
SmapUtil(org.apache.jasper.JspCompilationContext ctxt)


    //*********************************************************************
    // Public entry points

      
        this.ctxt = ctxt;
    
Methods Summary
private voidevaluateNodes(Node.Nodes nodes, SmapStratum s, boolean breakAtLF)

        try {
            nodes.visit(new SmapGenVisitor(s, breakAtLF, classInfos));
        } catch (JasperException ex) {
        }
    
public voidgenerateSmap(Node.Nodes pageNodes)
Generates an appropriate SMAP representing the current compilation context. (JSR-045.)

param
ctxt Current compilation context
param
pageNodes The current JSP page
return
a SMAP for the page


        classInfos = new ArrayList<ClassInfo>();
        String className = ctxt.getFullClassName();

        // Instantiate a SmapStratum for the main JSP page.
        SmapStratum s = new SmapStratum("JSP");
        classInfos.add(new ClassInfo(className, s));

        // Map out Node.Nodes and putting LineInfo into SmapStratum
        evaluateNodes(pageNodes, s, ctxt.getOptions().getMappedFile());

        String classFileName = ctxt.getClassFileName();
        for (ClassInfo entry: classInfos) {
            // Get SmapStratum
            s = entry.getSmapStratum();
            s.optimizeLineSection();

            // Set up our SMAP generator
            SmapGenerator g = new SmapGenerator();
            g.setOutputFileName(unqualify(ctxt.getServletJavaFileName()));
            g.addStratum(s, true);
 
            String name = entry.getClassName();  // class name
            // Compute the class name and output file name for inner classes
            if (!className.equals(name)) {
                classFileName = ctxt.getOutputDir() + 
                    name.substring(name.lastIndexOf('.")+1) + ".class";
            }
            entry.setClassFileName(classFileName);
            entry.setSmap(g.getString());

            if (ctxt.getOptions().isSmapDumped()) {
                File outSmap = new File(classFileName + ".smap");
                PrintWriter so =
                    new PrintWriter(
                        new OutputStreamWriter(
                            new FileOutputStream(outSmap),
                            SMAP_ENCODING));
                so.print(g.getString());
                so.close();
            }
        }
    
public voidinstallSmap()


        for (ClassInfo ci: classInfos) {
            String className = ci.getClassName();
            byte[] classfile = ctxt.getRuntimeContext().getBytecode(className);
            if (classfile == null) {
                SDEInstaller.install(new File(ci.getClassFileName()),
                                     ci.getSmap().getBytes());
            }
            else {
                classfile = SDEInstaller.install(classfile,
                                                 ci.getSmap().getBytes());
                ctxt.getRuntimeContext().setBytecode(className, classfile);
            }
        }
    
private static java.lang.Stringunqualify(java.lang.String path)
Returns an unqualified version of the given file path.

        path = path.replace('\\", '/");
        return path.substring(path.lastIndexOf('/") + 1);