001: package com.sun.xml.xsom.impl.scd;
002:
003: import com.sun.xml.xsom.XSAnnotation;
004: import com.sun.xml.xsom.XSAttGroupDecl;
005: import com.sun.xml.xsom.XSAttributeDecl;
006: import com.sun.xml.xsom.XSAttributeUse;
007: import com.sun.xml.xsom.XSComplexType;
008: import com.sun.xml.xsom.XSComponent;
009: import com.sun.xml.xsom.XSContentType;
010: import com.sun.xml.xsom.XSElementDecl;
011: import com.sun.xml.xsom.XSFacet;
012: import com.sun.xml.xsom.XSIdentityConstraint;
013: import com.sun.xml.xsom.XSModelGroup;
014: import com.sun.xml.xsom.XSModelGroupDecl;
015: import com.sun.xml.xsom.XSNotation;
016: import com.sun.xml.xsom.XSParticle;
017: import com.sun.xml.xsom.XSSchema;
018: import com.sun.xml.xsom.XSSimpleType;
019: import com.sun.xml.xsom.XSWildcard;
020: import com.sun.xml.xsom.XSXPath;
021: import com.sun.xml.xsom.visitor.XSFunction;
022:
023: import java.util.Iterator;
024:
025: /**
026: * Partial default implementation of {@link Axis}.
027: *
028: * <p>
029: * {@link XSParticle}s are skipped in SCD, so this class compensates that.
030: * For example, when we are considering a path from {@link XSComplexType},
031: * we need to also consider a path from its content type particle (if any.)
032: *
033: * @author Kohsuke Kawaguchi
034: */
035: abstract class AbstractAxisImpl<T extends XSComponent> implements
036: Axis<T>, XSFunction<Iterator<T>> {
037: /**
038: * Creates a singleton list.
039: */
040: protected final Iterator<T> singleton(T t) {
041: return Iterators.singleton(t);
042: }
043:
044: protected final Iterator<T> union(T... items) {
045: return new Iterators.Array<T>(items);
046: }
047:
048: protected final Iterator<T> union(Iterator<? extends T> first,
049: Iterator<? extends T> second) {
050: return new Iterators.Union<T>(first, second);
051: }
052:
053: public Iterator<T> iterator(XSComponent contextNode) {
054: return contextNode.apply(this );
055: }
056:
057: /**
058: * Gets the prefix of the axis, like "foo::".
059: */
060: public String getName() {
061: return toString();
062: }
063:
064: /**
065: * Default implementation that simply delegate sto {@link #iterator(XSComponent)}
066: */
067: public Iterator<T> iterator(
068: Iterator<? extends XSComponent> contextNodes) {
069: return new Iterators.Map<T, XSComponent>(contextNodes) {
070: protected Iterator<? extends T> apply(XSComponent u) {
071: return iterator(u);
072: }
073: };
074: }
075:
076: public boolean isModelGroup() {
077: return false;
078: }
079:
080: public Iterator<T> annotation(XSAnnotation ann) {
081: return empty();
082: }
083:
084: public Iterator<T> attGroupDecl(XSAttGroupDecl decl) {
085: return empty();
086: }
087:
088: public Iterator<T> attributeDecl(XSAttributeDecl decl) {
089: return empty();
090: }
091:
092: public Iterator<T> attributeUse(XSAttributeUse use) {
093: return empty();
094: }
095:
096: public Iterator<T> complexType(XSComplexType type) {
097: // compensate particle
098: XSParticle p = type.getContentType().asParticle();
099: if (p != null)
100: return particle(p);
101: else
102: return empty();
103: }
104:
105: public Iterator<T> schema(XSSchema schema) {
106: return empty();
107: }
108:
109: public Iterator<T> facet(XSFacet facet) {
110: return empty();
111: }
112:
113: public Iterator<T> notation(XSNotation notation) {
114: return empty();
115: }
116:
117: public Iterator<T> identityConstraint(XSIdentityConstraint decl) {
118: return empty();
119: }
120:
121: public Iterator<T> xpath(XSXPath xpath) {
122: return empty();
123: }
124:
125: public Iterator<T> simpleType(XSSimpleType simpleType) {
126: return empty();
127: }
128:
129: public Iterator<T> particle(XSParticle particle) {
130: return empty();
131: }
132:
133: public Iterator<T> empty(XSContentType empty) {
134: return empty();
135: }
136:
137: public Iterator<T> wildcard(XSWildcard wc) {
138: return empty();
139: }
140:
141: public Iterator<T> modelGroupDecl(XSModelGroupDecl decl) {
142: return empty();
143: }
144:
145: public Iterator<T> modelGroup(XSModelGroup group) {
146: // compensate for particles that are ignored in SCD
147: return new Iterators.Map<T, XSParticle>(group.iterator()) {
148: protected Iterator<? extends T> apply(XSParticle p) {
149: return particle(p);
150: }
151: };
152: }
153:
154: public Iterator<T> elementDecl(XSElementDecl decl) {
155: return empty();
156: }
157:
158: /**
159: * Returns an empty list.
160: */
161: protected final Iterator<T> empty() {
162: return Iterators.empty();
163: }
164:
165: }
|