SmapGeneratorpublic class SmapGenerator extends Object Represents a source map (SMAP), which serves to associate lines
of the input JSP file(s) to lines in the generated servlet in the
final .class file, according to the JSR-045 spec. |
Fields Summary |
---|
private String | outputFileName | private String | defaultStratum | private List | strata | private List | embedded | private boolean | doEmbedded |
Methods Summary |
---|
public synchronized void | addSmap(java.lang.String smap, java.lang.String stratumName)Adds the given string as an embedded SMAP with the given stratum name.
embedded.add("*O " + stratumName + "\n"
+ smap
+ "*C " + stratumName + "\n");
| public synchronized void | addStratum(SmapStratum stratum, boolean defaultStratum)Adds the given SmapStratum object, representing a Stratum with
logically associated FileSection and LineSection blocks, to
the current SmapGenerator. If default is true, this
stratum is made the default stratum, overriding any previously
set default.
strata.add(stratum);
if (defaultStratum)
this.defaultStratum = stratum.getStratumName();
| public synchronized java.lang.String | getString()
// check state and initialize buffer
if (outputFileName == null)
throw new IllegalStateException();
StringBuffer out = new StringBuffer();
// start the SMAP
out.append("SMAP\n");
out.append(outputFileName + '\n");
out.append(defaultStratum + '\n");
// include embedded SMAPs
if (doEmbedded) {
int nEmbedded = embedded.size();
for (int i = 0; i < nEmbedded; i++) {
out.append(embedded.get(i));
}
}
// print our StratumSections, FileSections, and LineSections
int nStrata = strata.size();
for (int i = 0; i < nStrata; i++) {
SmapStratum s = (SmapStratum) strata.get(i);
out.append(s.getString());
}
// end the SMAP
out.append("*E\n");
return out.toString();
| public static void | main(java.lang.String[] args)
SmapGenerator g = new SmapGenerator();
g.setOutputFileName("foo.java");
SmapStratum s = new SmapStratum("JSP");
s.addFile("foo.jsp");
s.addFile("bar.jsp", "/foo/foo/bar.jsp");
s.addLineData(1, "foo.jsp", 1, 1, 1);
s.addLineData(2, "foo.jsp", 1, 6, 1);
s.addLineData(3, "foo.jsp", 2, 10, 5);
s.addLineData(20, "bar.jsp", 1, 30, 1);
g.addStratum(s, true);
System.out.print(g);
System.out.println("---");
SmapGenerator embedded = new SmapGenerator();
embedded.setOutputFileName("blargh.tier2");
s = new SmapStratum("Tier2");
s.addFile("1.tier2");
s.addLineData(1, "1.tier2", 1, 1, 1);
embedded.addStratum(s, true);
g.addSmap(embedded.toString(), "JSP");
System.out.println(g);
| public void | setDoEmbedded(boolean status)Instructs the SmapGenerator whether to actually print any embedded
SMAPs or not. Intended for situations without an SMAP resolver.
doEmbedded = status;
| public synchronized void | setOutputFileName(java.lang.String x)Sets the filename (without path information) for the generated
source file. E.g., "foo$jsp.java".
//*********************************************************************
// Methods for adding mapping data
outputFileName = x;
| public java.lang.String | toString() return getString();
|
|