325N/A/*
325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.xsom.impl.scd;
325N/A
325N/Aimport com.sun.xml.internal.xsom.XSAnnotation;
325N/Aimport com.sun.xml.internal.xsom.XSAttGroupDecl;
325N/Aimport com.sun.xml.internal.xsom.XSAttributeDecl;
325N/Aimport com.sun.xml.internal.xsom.XSAttributeUse;
325N/Aimport com.sun.xml.internal.xsom.XSComplexType;
325N/Aimport com.sun.xml.internal.xsom.XSComponent;
325N/Aimport com.sun.xml.internal.xsom.XSContentType;
325N/Aimport com.sun.xml.internal.xsom.XSElementDecl;
325N/Aimport com.sun.xml.internal.xsom.XSFacet;
325N/Aimport com.sun.xml.internal.xsom.XSIdentityConstraint;
325N/Aimport com.sun.xml.internal.xsom.XSModelGroup;
325N/Aimport com.sun.xml.internal.xsom.XSModelGroupDecl;
325N/Aimport com.sun.xml.internal.xsom.XSNotation;
325N/Aimport com.sun.xml.internal.xsom.XSParticle;
325N/Aimport com.sun.xml.internal.xsom.XSSchema;
325N/Aimport com.sun.xml.internal.xsom.XSSimpleType;
325N/Aimport com.sun.xml.internal.xsom.XSWildcard;
325N/Aimport com.sun.xml.internal.xsom.XSXPath;
325N/Aimport com.sun.xml.internal.xsom.visitor.XSFunction;
325N/A
325N/Aimport java.util.Iterator;
325N/A
325N/A/**
325N/A * Partial default implementation of {@link Axis}.
325N/A *
325N/A * <p>
325N/A * {@link XSParticle}s are skipped in SCD, so this class compensates that.
325N/A * For example, when we are considering a path from {@link XSComplexType},
325N/A * we need to also consider a path from its content type particle (if any.)
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Aabstract class AbstractAxisImpl<T extends XSComponent> implements Axis<T>, XSFunction<Iterator<T>> {
325N/A /**
325N/A * Creates a singleton list.
325N/A */
325N/A protected final Iterator<T> singleton(T t) {
325N/A return Iterators.singleton(t);
325N/A }
325N/A
325N/A protected final Iterator<T> union(T... items) {
325N/A return new Iterators.Array<T>(items);
325N/A }
325N/A
325N/A protected final Iterator<T> union(Iterator<? extends T> first, Iterator<? extends T> second) {
325N/A return new Iterators.Union<T>(first,second);
325N/A }
325N/A
325N/A public Iterator<T> iterator(XSComponent contextNode) {
325N/A return contextNode.apply(this);
325N/A }
325N/A
325N/A /**
325N/A * Gets the prefix of the axis, like "foo::".
325N/A */
325N/A public String getName() {
325N/A return toString();
325N/A }
325N/A
325N/A /**
325N/A * Default implementation that simply delegate sto {@link #iterator(XSComponent)}
325N/A */
325N/A public Iterator<T> iterator(Iterator<? extends XSComponent> contextNodes) {
325N/A return new Iterators.Map<T,XSComponent>(contextNodes) {
325N/A protected Iterator<? extends T> apply(XSComponent u) {
325N/A return iterator(u);
325N/A }
325N/A };
325N/A }
325N/A
325N/A public boolean isModelGroup() {
325N/A return false;
325N/A }
325N/A
325N/A public Iterator<T> annotation(XSAnnotation ann) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> attGroupDecl(XSAttGroupDecl decl) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> attributeDecl(XSAttributeDecl decl) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> attributeUse(XSAttributeUse use) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> complexType(XSComplexType type) {
325N/A // compensate particle
325N/A XSParticle p = type.getContentType().asParticle();
325N/A if(p!=null)
325N/A return particle(p);
325N/A else
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> schema(XSSchema schema) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> facet(XSFacet facet) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> notation(XSNotation notation) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> identityConstraint(XSIdentityConstraint decl) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> xpath(XSXPath xpath) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> simpleType(XSSimpleType simpleType) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> particle(XSParticle particle) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> empty(XSContentType empty) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> wildcard(XSWildcard wc) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> modelGroupDecl(XSModelGroupDecl decl) {
325N/A return empty();
325N/A }
325N/A
325N/A public Iterator<T> modelGroup(XSModelGroup group) {
325N/A // compensate for particles that are ignored in SCD
325N/A return new Iterators.Map<T,XSParticle>(group.iterator()) {
325N/A protected Iterator<? extends T> apply(XSParticle p) {
325N/A return particle(p);
325N/A }
325N/A };
325N/A }
325N/A
325N/A public Iterator<T> elementDecl(XSElementDecl decl) {
325N/A return empty();
325N/A }
325N/A
325N/A /**
325N/A * Returns an empty list.
325N/A */
325N/A protected final Iterator<T> empty() {
325N/A return Iterators.empty();
325N/A }
325N/A
325N/A}