325N/A/*
325N/A * Copyright (c) 2005, 2010, 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/A * Copyright (C) 2004-2011
325N/A *
325N/A * Permission is hereby granted, free of charge, to any person obtaining a copy
325N/A * of this software and associated documentation files (the "Software"), to deal
325N/A * in the Software without restriction, including without limitation the rights
325N/A * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
325N/A * copies of the Software, and to permit persons to whom the Software is
325N/A * furnished to do so, subject to the following conditions:
325N/A *
325N/A * The above copyright notice and this permission notice shall be included in
325N/A * all copies or substantial portions of the Software.
325N/A *
325N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
325N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
325N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
325N/A * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
325N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
325N/A * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
325N/A * THE SOFTWARE.
325N/A */
325N/Apackage com.sun.xml.internal.rngom.nc;
325N/A
325N/Aimport com.sun.xml.internal.rngom.ast.om.ParsedNameClass;
325N/A
325N/Aimport javax.xml.namespace.QName;
325N/Aimport java.io.Serializable;
325N/Aimport java.util.HashSet;
325N/Aimport java.util.Set;
325N/A
325N/A/**
325N/A * Name class is a set of {@link QName}s.
325N/A */
325N/Apublic abstract class NameClass implements ParsedNameClass, Serializable {
325N/A static final int SPECIFICITY_NONE = -1;
325N/A static final int SPECIFICITY_ANY_NAME = 0;
325N/A static final int SPECIFICITY_NS_NAME = 1;
325N/A static final int SPECIFICITY_NAME = 2;
325N/A
325N/A /**
325N/A * Returns true if the given {@link QName} is a valid name
325N/A * for this QName.
325N/A */
325N/A public abstract boolean contains(QName name);
325N/A
325N/A public abstract int containsSpecificity(QName name);
325N/A
325N/A /**
325N/A * Visitor pattern support.
325N/A */
325N/A public abstract <V> V accept(NameClassVisitor<V> visitor);
325N/A
325N/A /**
325N/A * Returns true if the name class accepts infinite number of
325N/A * {@link QName}s.
325N/A *
325N/A * <p>
325N/A * Intuitively, this method returns true if the name class is
325N/A * some sort of wildcard.
325N/A */
325N/A public abstract boolean isOpen();
325N/A
325N/A /**
325N/A * If the name class is closed (IOW !{@link #isOpen()}),
325N/A * return the set of names in this name class. Otherwise the behavior
325N/A * is undefined.
325N/A */
325N/A public Set<QName> listNames() {
325N/A final Set<QName> names = new HashSet<QName>();
325N/A accept(new NameClassWalker() {
325N/A @Override
325N/A public Void visitName(QName name) {
325N/A names.add(name);
325N/A return null;
325N/A }
325N/A });
325N/A return names;
325N/A }
325N/A
325N/A /**
325N/A * Returns true if the intersection between this name class
325N/A * and the specified name class is non-empty.
325N/A */
325N/A public final boolean hasOverlapWith( NameClass nc2 ) {
325N/A return OverlapDetector.overlap(this,nc2);
325N/A }
325N/A
325N/A
325N/A /** Sigleton instance that represents "anyName". */
325N/A public static final NameClass ANY = new AnyNameClass();
325N/A
325N/A /**
325N/A * Sigleton instance that accepts no name.
325N/A *
325N/A * <p>
325N/A * This instance is useful when doing boolean arithmetic over
325N/A * name classes (such as computing an inverse of a given name class, etc),
325N/A * even though it can never appear in a RELAX NG surface syntax.
325N/A *
325N/A * <p>
325N/A * Internally, this instance is also used for:
325N/A * <ol>
325N/A * <li>Used to recover from errors during parsing.
325N/A * <li>Mark element patterns with &lt;notAllowed/> content model.
325N/A * </ol>
325N/A */
325N/A public static final NameClass NULL = new NullNameClass();
325N/A}