001: package net.sf.saxon.trace;
002:
003: import net.sf.saxon.expr.XPathContext;
004: import net.sf.saxon.om.Item;
005: import net.sf.saxon.style.StandardNames;
006:
007: /**
008: * A Simple trace listener that writes messages to System.err
009: */
010:
011: public class TimedTraceListener implements TraceListener {
012:
013: /**
014: * Called at start
015: */
016:
017: public void open() {
018: System.err.println("<trace time=\""
019: + System.currentTimeMillis() + "\">");
020: }
021:
022: /**
023: * Called at end
024: */
025:
026: public void close() {
027: System.err.println("<end time=\"" + System.currentTimeMillis()
028: + "\"/></trace>");
029: }
030:
031: /**
032: * Called when an instruction in the stylesheet gets processed
033: */
034:
035: public void enter(InstructionInfo instruction, XPathContext context) {
036: int loc = instruction.getConstructType();
037: if (loc == StandardNames.XSL_FUNCTION
038: || loc == StandardNames.XSL_TEMPLATE) {
039: String tag = "<";
040: tag += (loc == StandardNames.XSL_FUNCTION ? "function"
041: : "template");
042: String name = null;
043: if (instruction.getObjectNameCode() != -1) {
044: name = context.getNamePool().getDisplayName(
045: instruction.getObjectNameCode());
046: } else if (instruction.getProperty("name") != null) {
047: name = instruction.getProperty("name").toString();
048: }
049: if (name != null) {
050: tag += " name=\"" + name + "\"";
051: }
052: if (instruction.getProperty("match") != null) {
053: tag += " match=\"" + instruction.getProperty("match")
054: + "\"";
055: }
056: String file = instruction.getSystemId();
057: if (file != null) {
058: if (file.length() > 15) {
059: file = "*" + file.substring(file.length() - 14);
060: }
061: tag += " file=\"" + file + "\"";
062: }
063: tag += " line=\"" + instruction.getLineNumber() + "\"";
064: tag += " time=\"" + System.currentTimeMillis() + "\"";
065: tag += ">";
066: System.err.println(tag);
067: }
068: }
069:
070: /**
071: * Called after an instruction of the stylesheet got processed
072: */
073:
074: public void leave(InstructionInfo instruction) {
075: int loc = instruction.getConstructType();
076: if (loc == StandardNames.XSL_FUNCTION
077: || loc == StandardNames.XSL_TEMPLATE) {
078: String tag = "<end time=\"" + System.currentTimeMillis()
079: + "\"/></";
080: tag += (loc == StandardNames.XSL_FUNCTION ? "function>"
081: : "template>");
082: System.err.println(tag);
083: }
084: }
085:
086: /**
087: * Called when an item becomes current
088: */
089:
090: public void startCurrentItem(Item item) {
091: }
092:
093: /**
094: * Called after a node of the source tree got processed
095: */
096:
097: public void endCurrentItem(Item item) {
098: }
099:
100: }
101:
102: //
103: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
104: // you may not use this file except in compliance with the License. You may obtain a copy of the
105: // License at http://www.mozilla.org/MPL/
106: //
107: // Software distributed under the License is distributed on an "AS IS" basis,
108: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
109: // See the License for the specific language governing rights and limitations under the License.
110: //
111: // The Original Code is: all this file.
112: //
113: // The Initial Developer of the Original Code is Michael H. Kay
114: //
115: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
116: //
117: // Contributor(s): none
118: //
|