1 package com.icl.saxon.trace; 2 import com.icl.saxon.om.NodeInfo; 3 import com.icl.saxon.NodeHandler; 4 import com.icl.saxon.Context; 5 6 import java.util.EventListener ; 7 8 14 public class SaxonEventMulticaster implements TraceListener { 15 16 protected final EventListener a, b; 17 18 24 protected SaxonEventMulticaster(EventListener a, EventListener b) { 25 this.a = a; this.b = b; 26 } 27 28 33 protected EventListener remove(EventListener oldl) { 34 if (oldl == a) return b; 35 if (oldl == b) return a; 36 EventListener a2 = removeInternal(a, oldl); 37 EventListener b2 = removeInternal(b, oldl); 38 if (a2 == a && b2 == b) { 39 return this; } 41 return addInternal(a2, b2); 42 } 43 44 47 48 public void open() { 49 ((TraceListener)a).open(); 50 ((TraceListener)b).open(); 51 } 52 53 56 57 public void close() { 58 ((TraceListener)a).close(); 59 ((TraceListener)b).close(); 60 } 61 62 63 66 public void toplevel(NodeInfo element) 67 { 68 ((TraceListener)a).toplevel(element); 69 ((TraceListener)b).toplevel(element); 70 } 71 72 75 public void enterSource(NodeHandler handler, Context context) 76 { 77 ((TraceListener)a).enterSource(handler, context); 78 ((TraceListener)b).enterSource(handler, context); 79 } 80 81 84 public void leaveSource(NodeHandler handler, Context context) 85 { 86 ((TraceListener)a).leaveSource(handler, context); 87 ((TraceListener)b).leaveSource(handler, context); 88 } 89 90 93 public void enter(NodeInfo element, Context context) 94 { 95 ((TraceListener)a).enter(element, context); 96 ((TraceListener)b).enter(element, context); 97 } 98 99 102 public void leave(NodeInfo element, Context context) 103 { 104 ((TraceListener)a).leave(element, context); 105 ((TraceListener)b).leave(element, context); 106 } 107 108 114 public static TraceListener add(TraceListener a, TraceListener b) { 115 return (TraceListener)addInternal(a, b); 116 } 117 118 124 public static TraceListener remove(TraceListener l, TraceListener oldl) { 125 return (TraceListener) removeInternal(l, oldl); 126 } 127 128 138 protected static EventListener addInternal(EventListener a, EventListener b) { 139 if (a == null) return b; 140 if (b == null) return a; 141 return new SaxonEventMulticaster(a, b); 142 } 143 144 155 protected static EventListener removeInternal(EventListener l, EventListener oldl) { 156 if (l == oldl || l == null) { 157 return null; 158 } else if (l instanceof SaxonEventMulticaster) { 159 return ((SaxonEventMulticaster)l).remove(oldl); 160 } else { 161 return l; } 163 } 164 165 } 166 167 | Popular Tags |