| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.trace; |
| 9 |
|
| 10 |
import net.sf.saxon.Controller; |
| 11 |
import net.sf.saxon.expr.XPathContext; |
| 12 |
import net.sf.saxon.lib.Logger; |
| 13 |
import net.sf.saxon.lib.TraceListener; |
| 14 |
import net.sf.saxon.lib.TraceListener2; |
| 15 |
import net.sf.saxon.om.Item; |
| 16 |
import net.sf.saxon.trans.SimpleMode; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public class TraceEventMulticaster implements TraceListener { |
| 23 |
|
| 24 |
protected final TraceListener a, b; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
protected TraceEventMulticaster(TraceListener a, TraceListener b) { |
| 34 |
this.a = a; |
| 35 |
this.b = b; |
| 36 |
} |
| 37 |
|
| 38 |
public void setOutputDestination(Logger stream) { |
| 39 |
a.setOutputDestination(stream); |
| 40 |
b.setOutputDestination(stream); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
protected TraceListener remove(TraceListener oldl) { |
| 51 |
if (oldl == a) { |
| 52 |
return b; |
| 53 |
} |
| 54 |
if (oldl == b) { |
| 55 |
return a; |
| 56 |
} |
| 57 |
TraceListener a2 = removeInternal(a, oldl); |
| 58 |
TraceListener b2 = removeInternal(b, oldl); |
| 59 |
if (a2 == a && b2 == b) { |
| 60 |
return this; |
| 61 |
} |
| 62 |
return addInternal(a2, b2); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public void open(Controller controller) { |
| 70 |
a.open(controller); |
| 71 |
b.open(controller); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public void close() { |
| 79 |
a.close(); |
| 80 |
b.close(); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public void enter(InstructionInfo element, XPathContext context) { |
| 88 |
a.enter(element, context); |
| 89 |
b.enter(element, context); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public void leave(InstructionInfo element) { |
| 96 |
a.leave(element); |
| 97 |
b.leave(element); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public void startCurrentItem(Item item) { |
| 104 |
a.startCurrentItem(item); |
| 105 |
b.startCurrentItem(item); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public void endCurrentItem(Item item) { |
| 112 |
a.endCurrentItem(item); |
| 113 |
b.endCurrentItem(item); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
public void startRuleSearch() { |
| 119 |
if (a instanceof TraceListener2) { |
| 120 |
((TraceListener2) a).startRuleSearch(); |
| 121 |
} |
| 122 |
if (b instanceof TraceListener2) { |
| 123 |
((TraceListener2) b).startRuleSearch(); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
public void endRuleSearch(Object rule, SimpleMode mode, Item item) { |
| 134 |
if (a instanceof TraceListener2) { |
| 135 |
((TraceListener2) a).endRuleSearch(rule, mode, item); |
| 136 |
} |
| 137 |
if (b instanceof TraceListener2) { |
| 138 |
((TraceListener2) b).endRuleSearch(rule, mode, item); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
public static TraceListener add(TraceListener a, TraceListener b) { |
| 150 |
return (TraceListener) addInternal(a, b); |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
public static TraceListener remove(TraceListener l, TraceListener oldl) { |
| 161 |
return (TraceListener) removeInternal(l, oldl); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
protected static TraceListener addInternal(TraceListener a, TraceListener b) { |
| 176 |
if (a == null) { |
| 177 |
return b; |
| 178 |
} |
| 179 |
if (b == null) { |
| 180 |
return a; |
| 181 |
} |
| 182 |
return new TraceEventMulticaster(a, b); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
protected static TraceListener removeInternal(TraceListener l, TraceListener oldl) { |
| 199 |
if (l == oldl || l == null) { |
| 200 |
return null; |
| 201 |
} else if (l instanceof TraceEventMulticaster) { |
| 202 |
return ((TraceEventMulticaster) l).remove(oldl); |
| 203 |
} else { |
| 204 |
return l; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
} |
| 209 |
|