| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.expr.accum; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Component; |
| 11 |
import net.sf.saxon.expr.Expression; |
| 12 |
import net.sf.saxon.expr.Literal; |
| 13 |
import net.sf.saxon.expr.instruct.Actor; |
| 14 |
import net.sf.saxon.expr.instruct.Block; |
| 15 |
import net.sf.saxon.expr.instruct.SlotManager; |
| 16 |
import net.sf.saxon.lib.NamespaceConstant; |
| 17 |
import net.sf.saxon.om.StandardNames; |
| 18 |
import net.sf.saxon.om.StructuredQName; |
| 19 |
import net.sf.saxon.trace.ExpressionPresenter; |
| 20 |
import net.sf.saxon.trace.LocationKind; |
| 21 |
import net.sf.saxon.trans.*; |
| 22 |
import net.sf.saxon.trans.rules.Rule; |
| 23 |
import net.sf.saxon.value.SequenceType; |
| 24 |
|
| 25 |
import java.util.Map; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class Accumulator extends Actor { |
| 31 |
|
| 32 |
private StructuredQName accumulatorName; |
| 33 |
|
| 34 |
private SimpleMode preDescentRules; |
| 35 |
private SimpleMode postDescentRules; |
| 36 |
|
| 37 |
private Expression initialValueExpression; |
| 38 |
private SequenceType type; |
| 39 |
private boolean streamable; |
| 40 |
private boolean universallyApplicable; |
| 41 |
private int importPrecedence; |
| 42 |
private boolean tracing; |
| 43 |
|
| 44 |
private SlotManager slotManagerForInitialValueExpression; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public Accumulator() { |
| 49 |
preDescentRules = new SimpleMode(new StructuredQName("saxon", NamespaceConstant.SAXON, "preDescent")); |
| 50 |
postDescentRules = new SimpleMode(new StructuredQName("saxon", NamespaceConstant.SAXON, "postDescent")); |
| 51 |
|
| 52 |
body = Literal.makeEmptySequence(); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
@Override |
| 61 |
public SymbolicName getSymbolicName() { |
| 62 |
return new SymbolicName(StandardNames.XSL_ACCUMULATOR, getAccumulatorName()); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public boolean isDeclaredStreamable() { |
| 72 |
return streamable; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public void setDeclaredStreamable(boolean streamable) { |
| 82 |
this.streamable = streamable; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public StructuredQName getAccumulatorName() { |
| 92 |
return accumulatorName; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public void setAccumulatorName(StructuredQName firstName) { |
| 102 |
this.accumulatorName = firstName; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public int getImportPrecedence() { |
| 111 |
return importPrecedence; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public void setImportPrecedence(int importPrecedence) { |
| 120 |
this.importPrecedence = importPrecedence; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
public void setUniversallyApplicable(boolean universal) { |
| 129 |
this.universallyApplicable = universal; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public boolean isUniversallyApplicable() { |
| 138 |
return universallyApplicable; |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public boolean isTracing() { |
| 147 |
return tracing; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
public void setTracing(boolean tracing) { |
| 156 |
this.tracing = tracing; |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
public SlotManager getSlotManagerForInitialValueExpression() { |
| 166 |
return slotManagerForInitialValueExpression; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
public void setSlotManagerForInitialValueExpression(SlotManager slotManagerForInitialValueExpression) { |
| 176 |
this.slotManagerForInitialValueExpression = slotManagerForInitialValueExpression; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public SimpleMode getPreDescentRules() { |
| 186 |
return preDescentRules; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
public void setPreDescentRules(SimpleMode preDescentRules) { |
| 196 |
this.preDescentRules = preDescentRules; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
public SimpleMode getPostDescentRules() { |
| 206 |
return postDescentRules; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public void setPostDescentRules(SimpleMode postDescentRules) { |
| 217 |
this.postDescentRules = postDescentRules; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public Expression getInitialValueExpression() { |
| 227 |
return initialValueExpression; |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
public void setInitialValueExpression(Expression initialValueExpression) { |
| 237 |
this.initialValueExpression = initialValueExpression; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
public void addChildExpression(Expression expression) { |
| 246 |
Expression e = Block.makeBlock(getBody(), expression); |
| 247 |
setBody(e); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
public SequenceType getType() { |
| 258 |
return type; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
public void setType(SequenceType type) { |
| 269 |
this.type = type; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
public boolean isCompatible(Accumulator other) { |
| 279 |
return getAccumulatorName().equals(other.getAccumulatorName()); |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
@Override |
| 287 |
public int getComponentKind() { |
| 288 |
return StandardNames.XSL_ACCUMULATOR; |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
public int getConstructType() { |
| 299 |
return StandardNames.XSL_ACCUMULATOR; |
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
public StructuredQName getObjectName() { |
| 309 |
return accumulatorName; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
@Override |
| 319 |
public void export(ExpressionPresenter presenter) throws XPathException { |
| 320 |
export(presenter, null); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
public void export(final ExpressionPresenter out, Map<Component, Integer> componentIdMap) throws XPathException { |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
out.startElement("accumulator"); |
| 335 |
out.emitAttribute("name", getObjectName()); |
| 336 |
out.emitAttribute("line", getLineNumber() + ""); |
| 337 |
out.emitAttribute("module", getSystemId()); |
| 338 |
out.emitAttribute("as", type.toExportString()); |
| 339 |
out.emitAttribute("streamable", streamable ? "1" : "0"); |
| 340 |
out.emitAttribute("slots", getSlotManagerForInitialValueExpression().getNumberOfVariables()+""); |
| 341 |
if (componentIdMap != null) { |
| 342 |
out.emitAttribute("binds", "" + getDeclaringComponent().listComponentReferences(componentIdMap)); |
| 343 |
} |
| 344 |
if (isUniversallyApplicable()) { |
| 345 |
out.emitAttribute("flags", "u"); |
| 346 |
} |
| 347 |
out.setChildRole("init"); |
| 348 |
initialValueExpression.export(out); |
| 349 |
|
| 350 |
SimpleMode.RuleAction action = new SimpleMode.RuleAction() { |
| 351 |
public void processRule(Rule r) throws XPathException { |
| 352 |
out.startElement("accRule"); |
| 353 |
out.emitAttribute("slots", ((AccumulatorRule)r.getAction()).getStackFrameMap().getNumberOfVariables()+""); |
| 354 |
out.emitAttribute("rank", ""+r.getRank()); |
| 355 |
if (((AccumulatorRule) r.getAction()).isCapturing()) { |
| 356 |
out.emitAttribute("flags", "c"); |
| 357 |
} |
| 358 |
r.getPattern().export(out); |
| 359 |
r.getAction().export(out); |
| 360 |
out.endElement(); |
| 361 |
} |
| 362 |
}; |
| 363 |
try { |
| 364 |
out.startElement("pre"); |
| 365 |
out.emitAttribute("slots", preDescentRules.getStackFrameSlotsNeeded()+""); |
| 366 |
preDescentRules.processRules(action); |
| 367 |
out.endElement(); |
| 368 |
out.startElement("post"); |
| 369 |
out.emitAttribute("slots", postDescentRules.getStackFrameSlotsNeeded() + ""); |
| 370 |
postDescentRules.processRules(action); |
| 371 |
out.endElement(); |
| 372 |
} catch (XPathException e) { |
| 373 |
throw new AssertionError(e); |
| 374 |
} |
| 375 |
out.endElement(); |
| 376 |
} |
| 377 |
} |