KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > trace > TimedTraceListener


1 package net.sf.saxon.trace;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.om.Item;
4 import net.sf.saxon.style.StandardNames;
5
6 /**
7 * A Simple trace listener that writes messages to System.err
8 */

9
10 public class TimedTraceListener implements TraceListener {
11
12     /**
13     * Called at start
14     */

15
16     public void open() {
17         System.err.println("<trace time=\"" + System.currentTimeMillis() + "\">");
18     }
19
20     /**
21     * Called at end
22     */

23
24     public void close() {
25         System.err.println("<end time=\"" + System.currentTimeMillis()
26                + "\"/></trace>");
27     }
28
29     /**
30     * Called when an instruction in the stylesheet gets processed
31     */

32
33     public void enter(InstructionInfo instruction, XPathContext context) {
34         int loc = instruction.getConstructType();
35         if (loc == StandardNames.XSL_FUNCTION || loc == StandardNames.XSL_TEMPLATE) {
36             String JavaDoc tag = "<";
37             tag += (loc==StandardNames.XSL_FUNCTION ? "function" : "template");
38             String JavaDoc name = null;
39             if (instruction.getObjectNameCode() != -1) {
40                 name = context.getController().getNamePool().getDisplayName(instruction.getObjectNameCode());
41             } else if (instruction.getProperty("name") != null) {
42                 name = instruction.getProperty("name").toString();
43             }
44             if (name != null) {
45                 tag += " name=\"" + name + "\"";
46             }
47             if (instruction.getProperty("match") != null) {
48                 tag += " match=\"" + instruction.getProperty("match") + "\"";
49             }
50             String JavaDoc file = instruction.getSystemId();
51             if (file != null) {
52                 if (file.length()>15) {
53                     file="*" + file.substring(file.length()-14);
54                 }
55                 tag += " file=\"" + file + "\"";
56             }
57             tag += " line=\"" + instruction.getLineNumber() + "\"";
58             tag += " time=\"" + System.currentTimeMillis() + "\"";
59             tag += ">";
60             System.err.println(tag);
61         }
62     }
63
64     /**
65     * Called after an instruction of the stylesheet got processed
66     */

67
68     public void leave(InstructionInfo instruction) {
69         int loc = instruction.getConstructType();
70         if (loc == StandardNames.XSL_FUNCTION || loc == StandardNames.XSL_TEMPLATE) {
71             String JavaDoc tag = "<end time=\"" + System.currentTimeMillis() + "\"/></";
72             tag += (loc==StandardNames.XSL_FUNCTION ? "function>" : "template>");
73             System.err.println(tag);
74         }
75     }
76
77     /**
78     * Called when an item becomes current
79     */

80
81     public void startCurrentItem(Item item) {}
82
83     /**
84     * Called after a node of the source tree got processed
85     */

86
87     public void endCurrentItem(Item item) {}
88
89 }
90
91
92 //
93
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
94
// you may not use this file except in compliance with the License. You may obtain a copy of the
95
// License at http://www.mozilla.org/MPL/
96
//
97
// Software distributed under the License is distributed on an "AS IS" basis,
98
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
99
// See the License for the specific language governing rights and limitations under the License.
100
//
101
// The Original Code is: all this file.
102
//
103
// The Initial Developer of the Original Code is Michael H. Kay
104
//
105
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
106
//
107
// Contributor(s): none
108
//
Popular Tags