286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * The Apache Software License, Version 1.1
286N/A *
286N/A *
286N/A * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
286N/A * reserved.
286N/A *
286N/A * Redistribution and use in source and binary forms, with or without
286N/A * modification, are permitted provided that the following conditions
286N/A * are met:
286N/A *
286N/A * 1. Redistributions of source code must retain the above copyright
286N/A * notice, this list of conditions and the following disclaimer.
286N/A *
286N/A * 2. Redistributions in binary form must reproduce the above copyright
286N/A * notice, this list of conditions and the following disclaimer in
286N/A * the documentation and/or other materials provided with the
286N/A * distribution.
286N/A *
286N/A * 3. The end-user documentation included with the redistribution,
286N/A * if any, must include the following acknowledgment:
286N/A * "This product includes software developed by the
286N/A * Apache Software Foundation (http://www.apache.org/)."
286N/A * Alternately, this acknowledgment may appear in the software itself,
286N/A * if and wherever such third-party acknowledgments normally appear.
286N/A *
286N/A * 4. The names "Xerces" and "Apache Software Foundation" must
286N/A * not be used to endorse or promote products derived from this
286N/A * software without prior written permission. For written
286N/A * permission, please contact apache@apache.org.
286N/A *
286N/A * 5. Products derived from this software may not be called "Apache",
286N/A * nor may "Apache" appear in their name, without prior written
286N/A * permission of the Apache Software Foundation.
286N/A *
286N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
286N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
286N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
286N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
286N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
286N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
286N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
286N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
286N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
286N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
286N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
286N/A * SUCH DAMAGE.
286N/A * ====================================================================
286N/A *
286N/A * This software consists of voluntary contributions made by many
286N/A * individuals on behalf of the Apache Software Foundation and was
286N/A * originally based on software copyright (c) 1999, International
286N/A * Business Machines, Inc., http://www.apache.org. For more
286N/A * information on the Apache Software Foundation, please see
286N/A * <http://www.apache.org/>.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.impl.dtd;
286N/A
286N/A/**
286N/A * ContentSpec really exists to aid the parser classes in implementing
286N/A * access to the grammar.
286N/A * <p>
286N/A * This class is used by the DTD scanner and the validator classes,
286N/A * allowing them to be used separately or together. This "struct"
286N/A * class is used to build content models for validation, where it
286N/A * is more efficient to fetch all of the information for each of
286N/A * these content model "fragments" than to fetch each field one at
286N/A * a time. Since configurations are allowed to have validators
286N/A * without a DTD scanner (i.e. a schema validator) and a DTD scanner
286N/A * without a validator (non-validating processor), this class can be
286N/A * used by each without requiring the presence of the other.
286N/A * <p>
286N/A * When processing element declarations, the DTD scanner will build
286N/A * up a representation of the content model using the node types that
286N/A * are defined here. Since a non-validating processor only needs to
286N/A * remember the type of content model declared (i.e. ANY, EMPTY, MIXED,
286N/A * or CHILDREN), it is free to discard the specific details of the
286N/A * MIXED and CHILDREN content models described using this class.
286N/A * <p>
286N/A * In the typical case of a validating processor reading the grammar
286N/A * of the document from a DTD, the information about the content model
286N/A * declared will be preserved and later "compiled" into an efficient
286N/A * form for use during element validation. Each content spec node
286N/A * that is saved is assigned a unique index that is used as a handle
286N/A * for the "value" or "otherValue" fields of other content spec nodes.
286N/A * A leaf node has a "value" that is either an index in the string
286N/A * pool of the element type of that leaf, or a value of -1 to indicate
286N/A * the special "#PCDATA" leaf type used in a mixed content model.
286N/A * <p>
286N/A * For a mixed content model, the content spec will be made up of
286N/A * leaf and choice content spec nodes, with an optional "zero or more"
286N/A * node. For example, the mixed content declaration "(#PCDATA)" would
286N/A * contain a single leaf node with a node value of -1. A mixed content
286N/A * declaration of "(#PCDATA|foo)*" would have a content spec consisting
286N/A * of two leaf nodes, for the "#PCDATA" and "foo" choices, a choice node
286N/A * with the "value" set to the index of the "#PCDATA" leaf node and the
286N/A * "otherValue" set to the index of the "foo" leaf node, and a "zero or
286N/A * more" node with the "value" set to the index of the choice node. If
286N/A * the content model has more choices, for example "(#PCDATA|a|b)*", then
286N/A * there will be more corresponding choice and leaf nodes, the choice
286N/A * nodes will be chained together through the "value" field with each
286N/A * leaf node referenced by the "otherValue" field.
286N/A * <p>
286N/A * For element content models, there are sequence nodes and also "zero or
286N/A * one" and "one or more" nodes. The leaf nodes would always have a valid
286N/A * string pool index, as the "#PCDATA" leaf is not used in the declarations
286N/A * for element content models.
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A */
286N/Apublic class XMLContentSpec {
286N/A
286N/A //
286N/A // Constants
286N/A //
286N/A
286N/A /**
286N/A * Name or #PCDATA. Leaf nodes that represent parsed character
286N/A * data (#PCDATA) have values of -1.
286N/A */
286N/A public static final short CONTENTSPECNODE_LEAF = 0;
286N/A
286N/A /** Represents a zero or one occurence count, '?'. */
286N/A public static final short CONTENTSPECNODE_ZERO_OR_ONE = 1;
286N/A
286N/A /** Represents a zero or more occurence count, '*'. */
286N/A public static final short CONTENTSPECNODE_ZERO_OR_MORE = 2;
286N/A
286N/A /** Represents a one or more occurence count, '+'. */
286N/A public static final short CONTENTSPECNODE_ONE_OR_MORE = 3;
286N/A
286N/A /** Represents choice, '|'. */
286N/A public static final short CONTENTSPECNODE_CHOICE = 4;
286N/A
286N/A /** Represents sequence, ','. */
286N/A public static final short CONTENTSPECNODE_SEQ = 5;
286N/A
286N/A /**
286N/A * Represents any namespace specified namespace. When the element
286N/A * found in the document must belong to a specific namespace,
286N/A * <code>otherValue</code> will contain the name of the namespace.
286N/A * If <code>otherValue</code> is <code>-1</code> then the element
286N/A * can be from any namespace.
286N/A * <p>
286N/A * Lists of valid namespaces are created from choice content spec
286N/A * nodes that have any content spec nodes as children.
286N/A */
286N/A public static final short CONTENTSPECNODE_ANY = 6;
286N/A
286N/A /**
286N/A * Represents any other namespace (XML Schema: ##other).
286N/A * <p>
286N/A * When the content spec node type is set to CONTENTSPECNODE_ANY_OTHER,
286N/A * <code>value</code> will contain the namespace that <em>cannot</em>
286N/A * occur.
286N/A */
286N/A public static final short CONTENTSPECNODE_ANY_OTHER = 7;
286N/A
286N/A /** Represents any local element (XML Schema: ##local). */
286N/A public static final short CONTENTSPECNODE_ANY_LOCAL = 8;
286N/A
286N/A /** prcessContent is 'lax' **/
286N/A public static final short CONTENTSPECNODE_ANY_LAX = 22;
286N/A
286N/A public static final short CONTENTSPECNODE_ANY_OTHER_LAX = 23;
286N/A
286N/A public static final short CONTENTSPECNODE_ANY_LOCAL_LAX = 24;
286N/A
286N/A /** processContent is 'skip' **/
286N/A
286N/A public static final short CONTENTSPECNODE_ANY_SKIP = 38;
286N/A
286N/A public static final short CONTENTSPECNODE_ANY_OTHER_SKIP = 39;
286N/A
286N/A public static final short CONTENTSPECNODE_ANY_LOCAL_SKIP = 40;
286N/A //
286N/A // Data
286N/A //
286N/A
286N/A /**
286N/A * The content spec node type.
286N/A *
286N/A * @see #CONTENTSPECNODE_LEAF
286N/A * @see #CONTENTSPECNODE_ZERO_OR_ONE
286N/A * @see #CONTENTSPECNODE_ZERO_OR_MORE
286N/A * @see #CONTENTSPECNODE_ONE_OR_MORE
286N/A * @see #CONTENTSPECNODE_CHOICE
286N/A * @see #CONTENTSPECNODE_SEQ
286N/A */
286N/A public short type;
286N/A
286N/A /**
286N/A * The "left hand" value object of the content spec node.
286N/A * leaf name.localpart, single child for unary ops, left child for binary ops.
286N/A */
286N/A public Object value;
286N/A
286N/A /**
286N/A * The "right hand" value of the content spec node.
286N/A * leaf name.uri, right child for binary ops
286N/A */
286N/A public Object otherValue;
286N/A
286N/A //
286N/A // Constructors
286N/A //
286N/A
286N/A /** Default constructor. */
286N/A public XMLContentSpec() {
286N/A clear();
286N/A }
286N/A
286N/A /** Constructs a content spec with the specified values. */
286N/A public XMLContentSpec(short type, Object value, Object otherValue) {
286N/A setValues(type, value, otherValue);
286N/A }
286N/A
286N/A /**
286N/A * Constructs a content spec from the values in the specified content spec.
286N/A */
286N/A public XMLContentSpec(XMLContentSpec contentSpec) {
286N/A setValues(contentSpec);
286N/A }
286N/A
286N/A /**
286N/A * Constructs a content spec from the values specified by the given
286N/A * content spec provider and identifier.
286N/A */
286N/A public XMLContentSpec(XMLContentSpec.Provider provider,
286N/A int contentSpecIndex) {
286N/A setValues(provider, contentSpecIndex);
286N/A }
286N/A
286N/A //
286N/A // Public methods
286N/A //
286N/A
286N/A /** Clears the values. */
286N/A public void clear() {
286N/A type = -1;
286N/A value = null;
286N/A otherValue = null;
286N/A }
286N/A
286N/A /** Sets the values. */
286N/A public void setValues(short type, Object value, Object otherValue) {
286N/A this.type = type;
286N/A this.value = value;
286N/A this.otherValue = otherValue;
286N/A }
286N/A
286N/A /** Sets the values of the specified content spec. */
286N/A public void setValues(XMLContentSpec contentSpec) {
286N/A type = contentSpec.type;
286N/A value = contentSpec.value;
286N/A otherValue = contentSpec.otherValue;
286N/A }
286N/A
286N/A /**
286N/A * Sets the values from the values specified by the given content spec
286N/A * provider and identifier. If the specified content spec cannot be
286N/A * provided, the values of this content spec are cleared.
286N/A */
286N/A public void setValues(XMLContentSpec.Provider provider,
286N/A int contentSpecIndex) {
286N/A if (!provider.getContentSpec(contentSpecIndex, this)) {
286N/A clear();
286N/A }
286N/A }
286N/A
286N/A
286N/A //
286N/A // Object methods
286N/A //
286N/A
286N/A /** Returns a hash code for this node. */
286N/A public int hashCode() {
286N/A return type << 16 |
286N/A value.hashCode() << 8 |
286N/A otherValue.hashCode();
286N/A }
286N/A
286N/A /** Returns true if the two objects are equal. */
286N/A public boolean equals(Object object) {
286N/A if (object != null && object instanceof XMLContentSpec) {
286N/A XMLContentSpec contentSpec = (XMLContentSpec)object;
286N/A return type == contentSpec.type &&
286N/A value == contentSpec.value &&
286N/A otherValue == contentSpec.otherValue;
286N/A }
286N/A return false;
286N/A }
286N/A
286N/A
286N/A //
286N/A // Interfaces
286N/A //
286N/A
286N/A /**
286N/A * Provides a means for walking the structure built out of
286N/A * content spec "nodes". The user of this provider interface is
286N/A * responsible for knowing what the content spec node values
286N/A * "mean". If those values refer to content spec identifiers,
286N/A * then the user can call back into the provider to get the
286N/A * next content spec node in the structure.
286N/A *
286N/A * @xerces.internal
286N/A */
286N/A public interface Provider {
286N/A
286N/A //
286N/A // XMLContentSpec.Provider methods
286N/A //
286N/A
286N/A /**
286N/A * Fills in the provided content spec structure with content spec
286N/A * information for a unique identifier.
286N/A *
286N/A * @param contentSpecIndex The content spec identifier. All content
286N/A * spec "nodes" have a unique identifier.
286N/A * @param contentSpec The content spec struct to fill in with
286N/A * the information.
286N/A *
286N/A * @return Returns true if the contentSpecIndex was found.
286N/A */
286N/A public boolean getContentSpec(int contentSpecIndex, XMLContentSpec contentSpec);
286N/A
286N/A } // interface Provider
286N/A
286N/A} // class XMLContentSpec