KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > trace > TracerEvent


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: TracerEvent.java,v 1.9 2004/02/16 23:00:27 minchau Exp $
18  */

19 package org.apache.xalan.trace;
20
21 import org.apache.xalan.templates.ElemTemplateElement;
22 import org.apache.xalan.transformer.TransformerImpl;
23 import org.apache.xml.utils.QName;
24
25 import org.w3c.dom.Attr JavaDoc;
26 import org.w3c.dom.Element JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.NodeList JavaDoc;
29
30 /**
31  * Parent class of events generated for tracing the
32  * progress of the XSL processor.
33  * @xsl.usage advanced
34  */

35 public class TracerEvent implements java.util.EventListener JavaDoc
36 {
37
38   /**
39    * The node in the style tree where the event occurs.
40    */

41   public final ElemTemplateElement m_styleNode;
42
43   /**
44    * The XSLT processor instance.
45    */

46   public final TransformerImpl m_processor;
47
48   /**
49    * The current context node.
50    */

51   public final Node JavaDoc m_sourceNode;
52
53   /**
54    * The current mode.
55    */

56   public final QName m_mode;
57
58   /**
59    * Create an event originating at the given node of the style tree.
60    * @param processor The XSLT TransformerFactory.
61    * @param sourceNode The current context node.
62    * @param mode The current mode.
63    * @param m_styleNode node in the style tree reference for the event.
64    * Should not be null. That is not enforced.
65    * @param styleNode The stylesheet element that is executing.
66    */

67   public TracerEvent(TransformerImpl processor, Node JavaDoc sourceNode, QName mode,
68                      ElemTemplateElement styleNode)
69   {
70
71     this.m_processor = processor;
72     this.m_sourceNode = sourceNode;
73     this.m_mode = mode;
74     this.m_styleNode = styleNode;
75   }
76
77   /**
78    * Returns a string representation of the node.
79    * The string returned for elements will contain the element name
80    * and any attributes enclosed in angle brackets.
81    * The string returned for attributes will be of form, "name=value."
82    *
83    * @param n any DOM node. Must not be null.
84    *
85    * @return a string representation of the given node.
86    */

87   public static String JavaDoc printNode(Node JavaDoc n)
88   {
89
90     String JavaDoc r = n.hashCode() + " ";
91
92     if (n instanceof Element)
93     {
94       r += "<" + n.getNodeName();
95
96       Node JavaDoc c = n.getFirstChild();
97
98       while (null != c)
99       {
100         if (c instanceof Attr JavaDoc)
101         {
102           r += printNode(c) + " ";
103         }
104
105         c = c.getNextSibling();
106       }
107
108       r += ">";
109     }
110     else
111     {
112       if (n instanceof Attr JavaDoc)
113       {
114         r += n.getNodeName() + "=" + n.getNodeValue();
115       }
116       else
117       {
118         r += n.getNodeName();
119       }
120     }
121
122     return r;
123   }
124
125   /**
126    * Returns a string representation of the node list.
127    * The string will contain the list of nodes inside square braces.
128    * Elements will contain the element name
129    * and any attributes enclosed in angle brackets.
130    * Attributes will be of form, "name=value."
131    *
132    * @param l any DOM node list. Must not be null.
133    *
134    * @return a string representation of the given node list.
135    */

136   public static String JavaDoc printNodeList(NodeList JavaDoc l)
137   {
138
139     String JavaDoc r = l.hashCode() + "[";
140     int len = l.getLength() - 1;
141     int i = 0;
142
143     while (i < len)
144     {
145       Node JavaDoc n = l.item(i);
146
147       if (null != n)
148       {
149         r += printNode(n) + ", ";
150       }
151
152       ++i;
153     }
154
155     if (i == len)
156     {
157       Node JavaDoc n = l.item(len);
158
159       if (null != n)
160       {
161         r += printNode(n);
162       }
163     }
164
165     return r + "]";
166   }
167 }
168
Popular Tags