01: package com.sun.xml.xsom.impl.scd;
02:
03: import com.sun.xml.xsom.SCD;
04: import com.sun.xml.xsom.XSComponent;
05:
06: import java.util.Iterator;
07:
08: /**
09: * Schema component designator.
10: *
11: * @author Kohsuke Kawaguchi
12: */
13: public final class SCDImpl extends SCD {
14: /**
15: * SCD is fundamentally a list of steps.
16: */
17: private final Step[] steps;
18:
19: /**
20: * The original textual SCD representation.
21: */
22: private final String text;
23:
24: public SCDImpl(String text, Step[] steps) {
25: this .text = text;
26: this .steps = steps;
27: }
28:
29: public Iterator<XSComponent> select(
30: Iterator<? extends XSComponent> contextNode) {
31: Iterator<XSComponent> nodeSet = (Iterator) contextNode;
32:
33: int len = steps.length;
34: for (int i = 0; i < len; i++) {
35: if (i != 0 && i != len - 1
36: && !steps[i - 1].axis.isModelGroup()
37: && steps[i].axis.isModelGroup()) {
38: // expand the current nodeset by adding abbreviatable complex type and model groups.
39: // note that such expansion is not allowed to occure in in between model group axes.
40:
41: // TODO: this step is not needed if the next step is known not to react to
42: // complex type nor model groups, such as, say Axis.FACET
43: nodeSet = new Iterators.Unique<XSComponent>(
44: new Iterators.Map<XSComponent, XSComponent>(
45: nodeSet) {
46: protected Iterator<XSComponent> apply(
47: XSComponent u) {
48: return new Iterators.Union<XSComponent>(
49: Iterators.singleton(u),
50: Axis.INTERMEDIATE_SKIP
51: .iterator(u));
52: }
53: });
54: }
55: nodeSet = steps[i].evaluate(nodeSet);
56: }
57:
58: return nodeSet;
59: }
60:
61: public String toString() {
62: return text;
63: }
64: }
|