1 package net.sf.saxon.trace; 2 import net.sf.saxon.expr.XPathContext; 3 import net.sf.saxon.om.Item; 4 5 import java.util.EventListener ; 6 7 13 public class TraceEventMulticaster implements TraceListener { 14 15 protected final EventListener a, b; 16 17 23 protected TraceEventMulticaster(EventListener a, EventListener b) { 24 this.a = a; this.b = b; 25 } 26 27 32 protected EventListener remove(EventListener oldl) { 33 if (oldl == a) return b; 34 if (oldl == b) return a; 35 EventListener a2 = removeInternal(a, oldl); 36 EventListener b2 = removeInternal(b, oldl); 37 if (a2 == a && b2 == b) { 38 return this; } 40 return addInternal(a2, b2); 41 } 42 43 46 47 public void open() { 48 ((TraceListener)a).open(); 49 ((TraceListener)b).open(); 50 } 51 52 55 56 public void close() { 57 ((TraceListener)a).close(); 58 ((TraceListener)b).close(); 59 } 60 61 62 65 public void enter(InstructionInfo element, XPathContext context) 66 { 67 ((TraceListener)a).enter(element, context); 68 ((TraceListener)b).enter(element, context); 69 } 70 71 74 public void leave(InstructionInfo element) 75 { 76 ((TraceListener)a).leave(element); 77 ((TraceListener)b).leave(element); 78 } 79 80 83 public void startCurrentItem(Item item) 84 { 85 ((TraceListener)a).startCurrentItem(item); 86 ((TraceListener)b).startCurrentItem(item); 87 } 88 89 92 public void endCurrentItem(Item item) 93 { 94 ((TraceListener)a).endCurrentItem(item); 95 ((TraceListener)b).endCurrentItem(item); 96 } 97 98 104 public static TraceListener add(TraceListener a, TraceListener b) { 105 return (TraceListener)addInternal(a, b); 106 } 107 108 114 public static TraceListener remove(TraceListener l, TraceListener oldl) { 115 return (TraceListener) removeInternal(l, oldl); 116 } 117 118 128 protected static EventListener addInternal(EventListener a, EventListener b) { 129 if (a == null) return b; 130 if (b == null) return a; 131 return new TraceEventMulticaster(a, b); 132 } 133 134 145 146 protected static EventListener removeInternal(EventListener l, EventListener oldl) { 147 if (l == oldl || l == null) { 148 return null; 149 } else if (l instanceof TraceEventMulticaster) { 150 return ((TraceEventMulticaster)l).remove(oldl); 151 } else { 152 return l; } 154 } 155 156 } 157 158 | Popular Tags |