1 16 19 package org.apache.xalan.trace; 20 21 import java.lang.reflect.Method ; 22 import java.util.TooManyListenersException ; 23 import java.util.Vector ; 24 25 import org.apache.xalan.templates.ElemTemplateElement; 26 import org.apache.xalan.transformer.TransformerImpl; 27 import org.apache.xpath.XPath; 28 import org.apache.xpath.objects.XObject; 29 import org.w3c.dom.Node ; 30 31 35 public class TraceManager 36 { 37 38 39 private TransformerImpl m_transformer; 40 41 46 public TraceManager(TransformerImpl transformer) 47 { 48 m_transformer = transformer; 49 } 50 51 55 private Vector m_traceListeners = null; 56 57 63 public void addTraceListener(TraceListener tl) 64 throws TooManyListenersException 65 { 66 67 TransformerImpl.S_DEBUG = true; 68 69 if (null == m_traceListeners) 70 m_traceListeners = new Vector (); 71 72 m_traceListeners.addElement(tl); 73 } 74 75 79 public void removeTraceListener(TraceListener tl) 80 { 81 82 if (null != m_traceListeners) 83 { 84 m_traceListeners.removeElement(tl); 85 86 if (0 == m_traceListeners.size()) m_traceListeners = null; 90 } 91 } 92 93 98 public void fireGenerateEvent(GenerateEvent te) 99 { 100 101 if (null != m_traceListeners) 102 { 103 int nListeners = m_traceListeners.size(); 104 105 for (int i = 0; i < nListeners; i++) 106 { 107 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 108 109 tl.generated(te); 110 } 111 } 112 } 113 114 119 public boolean hasTraceListeners() 120 { 121 return (null != m_traceListeners); 122 } 123 124 131 public void fireTraceEvent(ElemTemplateElement styleNode) 132 { 133 134 if (hasTraceListeners()) 135 { 136 int sourceNode = m_transformer.getXPathContext().getCurrentNode(); 137 Node source = m_transformer.getXPathContext().getDTM( 138 sourceNode).getNode(sourceNode); 139 140 fireTraceEvent(new TracerEvent(m_transformer, source, 141 m_transformer.getMode(), 142 styleNode)); 143 } 144 } 145 146 154 public void fireTraceEndEvent(ElemTemplateElement styleNode) 155 { 156 157 if (hasTraceListeners()) 158 { 159 int sourceNode = m_transformer.getXPathContext().getCurrentNode(); 160 Node source = m_transformer.getXPathContext().getDTM( 161 sourceNode).getNode(sourceNode); 162 163 fireTraceEndEvent(new TracerEvent(m_transformer, source, 164 m_transformer.getMode(), 165 styleNode)); 166 } 167 } 168 169 174 public void fireTraceEndEvent(TracerEvent te) 175 { 176 177 if (hasTraceListeners()) 178 { 179 int nListeners = m_traceListeners.size(); 180 181 for (int i = 0; i < nListeners; i++) 182 { 183 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 184 if(tl instanceof TraceListenerEx2) 185 { 186 ((TraceListenerEx2)tl).traceEnd(te); 187 } 188 } 189 } 190 } 191 192 193 194 199 public void fireTraceEvent(TracerEvent te) 200 { 201 202 if (hasTraceListeners()) 203 { 204 int nListeners = m_traceListeners.size(); 205 206 for (int i = 0; i < nListeners; i++) 207 { 208 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 209 210 tl.trace(te); 211 } 212 } 213 } 214 215 226 public void fireSelectedEvent( 227 int sourceNode, ElemTemplateElement styleNode, String attributeName, 228 XPath xpath, XObject selection) 229 throws javax.xml.transform.TransformerException 230 { 231 232 if (hasTraceListeners()) 233 { 234 Node source = m_transformer.getXPathContext().getDTM( 235 sourceNode).getNode(sourceNode); 236 237 fireSelectedEvent(new SelectionEvent(m_transformer, source, styleNode, 238 attributeName, xpath, selection)); 239 } 240 } 241 242 253 public void fireSelectedEndEvent( 254 int sourceNode, ElemTemplateElement styleNode, String attributeName, 255 XPath xpath, XObject selection) 256 throws javax.xml.transform.TransformerException 257 { 258 259 if (hasTraceListeners()) 260 { 261 Node source = m_transformer.getXPathContext().getDTM( 262 sourceNode).getNode(sourceNode); 263 264 fireSelectedEndEvent(new EndSelectionEvent(m_transformer, source, styleNode, 265 attributeName, xpath, selection)); 266 } 267 } 268 269 276 public void fireSelectedEndEvent(EndSelectionEvent se) 277 throws javax.xml.transform.TransformerException 278 { 279 280 if (hasTraceListeners()) 281 { 282 int nListeners = m_traceListeners.size(); 283 284 for (int i = 0; i < nListeners; i++) 285 { 286 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 287 288 if(tl instanceof TraceListenerEx) 289 ((TraceListenerEx)tl).selectEnd(se); 290 } 291 } 292 } 293 294 301 public void fireSelectedEvent(SelectionEvent se) 302 throws javax.xml.transform.TransformerException 303 { 304 305 if (hasTraceListeners()) 306 { 307 int nListeners = m_traceListeners.size(); 308 309 for (int i = 0; i < nListeners; i++) 310 { 311 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 312 313 tl.selected(se); 314 } 315 } 316 } 317 318 319 328 public void fireExtensionEndEvent(Method method, Object instance, Object [] arguments) 329 { 330 ExtensionEvent ee = new ExtensionEvent(m_transformer, method, instance, arguments); 331 332 if (hasTraceListeners()) 333 { 334 int nListeners = m_traceListeners.size(); 335 336 for (int i = 0; i < nListeners; i++) 337 { 338 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 339 if(tl instanceof TraceListenerEx3) 340 { 341 ((TraceListenerEx3)tl).extensionEnd(ee); 342 } 343 } 344 } 345 } 346 347 356 public void fireExtensionEvent(Method method, Object instance, Object [] arguments) 357 { 358 ExtensionEvent ee = new ExtensionEvent(m_transformer, method, instance, arguments); 359 360 if (hasTraceListeners()) 361 { 362 int nListeners = m_traceListeners.size(); 363 364 for (int i = 0; i < nListeners; i++) 365 { 366 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 367 if(tl instanceof TraceListenerEx3) 368 { 369 ((TraceListenerEx3)tl).extension(ee); 370 } 371 } 372 } 373 } 374 375 382 public void fireExtensionEndEvent(ExtensionEvent ee) 383 { 384 if (hasTraceListeners()) 385 { 386 int nListeners = m_traceListeners.size(); 387 388 for (int i = 0; i < nListeners; i++) 389 { 390 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 391 if(tl instanceof TraceListenerEx3) 392 { 393 ((TraceListenerEx3)tl).extensionEnd(ee); 394 } 395 } 396 } 397 } 398 399 406 public void fireExtensionEvent(ExtensionEvent ee) 407 { 408 409 if (hasTraceListeners()) 410 { 411 int nListeners = m_traceListeners.size(); 412 413 for (int i = 0; i < nListeners; i++) 414 { 415 TraceListener tl = (TraceListener) m_traceListeners.elementAt(i); 416 if(tl instanceof TraceListenerEx3) 417 { 418 ((TraceListenerEx3)tl).extension(ee); 419 } 420 } 421 } 422 } 423 } 424 | Popular Tags |