2
* The Apache Software License, Version 1.1
5
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in
17
* the documentation and/or other materials provided with the
20
* 3. The end-user documentation included with the redistribution,
21
* if any, must include the following acknowledgment:
22
* "This product includes software developed by the
23
* Apache Software Foundation (http://www.apache.org/)."
24
* Alternately, this acknowledgment may appear in the software itself,
25
* if and wherever such third-party acknowledgments normally appear.
27
* 4. The names "Xerces" and "Apache Software Foundation" must
28
* not be used to endorse or promote products derived from this
29
* software without prior written permission. For written
30
* permission, please contact apache@apache.org.
32
* 5. Products derived from this software may not be called "Apache",
33
* nor may "Apache" appear in their name, without prior written
34
* permission of the Apache Software Foundation.
36
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
* ====================================================================
50
* This software consists of voluntary contributions made by many
51
* individuals on behalf of the Apache Software Foundation and was
52
* originally based on software copyright (c) 1999, International
53
* Business Machines, Inc., http://www.apache.org. For more
54
* information on the Apache Software Foundation, please see
55
* <http://www.apache.org/>.
58
package org.apache.xerces.impl.dtd;
61
* ContentSpec really exists to aid the parser classes in implementing
62
* access to the grammar.
64
* This class is used by the DTD scanner and the validator classes,
65
* allowing them to be used separately or together. This "struct"
66
* class is used to build content models for validation, where it
67
* is more efficient to fetch all of the information for each of
68
* these content model "fragments" than to fetch each field one at
69
* a time. Since configurations are allowed to have validators
70
* without a DTD scanner (i.e. a schema validator) and a DTD scanner
71
* without a validator (non-validating processor), this class can be
72
* used by each without requiring the presence of the other.
74
* When processing element declarations, the DTD scanner will build
75
* up a representation of the content model using the node types that
76
* are defined here. Since a non-validating processor only needs to
77
* remember the type of content model declared (i.e. ANY, EMPTY, MIXED,
78
* or CHILDREN), it is free to discard the specific details of the
79
* MIXED and CHILDREN content models described using this class.
81
* In the typical case of a validating processor reading the grammar
82
* of the document from a DTD, the information about the content model
83
* declared will be preserved and later "compiled" into an efficient
84
* form for use during element validation. Each content spec node
85
* that is saved is assigned a unique index that is used as a handle
86
* for the "value" or "otherValue" fields of other content spec nodes.
87
* A leaf node has a "value" that is either an index in the string
88
* pool of the element type of that leaf, or a value of -1 to indicate
89
* the special "#PCDATA" leaf type used in a mixed content model.
91
* For a mixed content model, the content spec will be made up of
92
* leaf and choice content spec nodes, with an optional "zero or more"
93
* node. For example, the mixed content declaration "(#PCDATA)" would
94
* contain a single leaf node with a node value of -1. A mixed content
95
* declaration of "(#PCDATA|foo)*" would have a content spec consisting
96
* of two leaf nodes, for the "#PCDATA" and "foo" choices, a choice node
97
* with the "value" set to the index of the "#PCDATA" leaf node and the
98
* "otherValue" set to the index of the "foo" leaf node, and a "zero or
99
* more" node with the "value" set to the index of the choice node. If
100
* the content model has more choices, for example "(#PCDATA|a|b)*", then
101
* there will be more corresponding choice and leaf nodes, the choice
102
* nodes will be chained together through the "value" field with each
103
* leaf node referenced by the "otherValue" field.
105
* For element content models, there are sequence nodes and also "zero or
106
* one" and "one or more" nodes. The leaf nodes would always have a valid
107
* string pool index, as the "#PCDATA" leaf is not used in the declarations
108
* for element content models.
110
* @version $Id: XMLContentSpec.java,v 1.3 2002/01/29 01:15:10 lehors Exp $
112
public class XMLContentSpec {
119
* Name or #PCDATA. Leaf nodes that represent parsed character
120
* data (#PCDATA) have values of -1.
122
public static final short CONTENTSPECNODE_LEAF = 0;
124
/** Represents a zero or one occurence count, '?'. */
125
public static final short CONTENTSPECNODE_ZERO_OR_ONE = 1;
127
/** Represents a zero or more occurence count, '*'. */
128
public static final short CONTENTSPECNODE_ZERO_OR_MORE = 2;
130
/** Represents a one or more occurence count, '+'. */
131
public static final short CONTENTSPECNODE_ONE_OR_MORE = 3;
133
/** Represents choice, '|'. */
134
public static final short CONTENTSPECNODE_CHOICE = 4;
136
/** Represents sequence, ','. */
137
public static final short CONTENTSPECNODE_SEQ = 5;
140
* Represents any namespace specified namespace. When the element
141
* found in the document must belong to a specific namespace,
142
* <code>otherValue</code> will contain the name of the namespace.
143
* If <code>otherValue</code> is <code>-1</code> then the element
144
* can be from any namespace.
146
* Lists of valid namespaces are created from choice content spec
147
* nodes that have any content spec nodes as children.
149
public static final short CONTENTSPECNODE_ANY = 6;
152
* Represents any other namespace (XML Schema: ##other).
154
* When the content spec node type is set to CONTENTSPECNODE_ANY_OTHER,
155
* <code>value</code> will contain the namespace that <em>cannot</em>
158
public static final short CONTENTSPECNODE_ANY_OTHER = 7;
160
/** Represents any local element (XML Schema: ##local). */
161
public static final short CONTENTSPECNODE_ANY_LOCAL = 8;
163
/** prcessContent is 'lax' **/
164
public static final short CONTENTSPECNODE_ANY_LAX = 22;
166
public static final short CONTENTSPECNODE_ANY_OTHER_LAX = 23;
168
public static final short CONTENTSPECNODE_ANY_LOCAL_LAX = 24;
170
/** processContent is 'skip' **/
172
public static final short CONTENTSPECNODE_ANY_SKIP = 38;
174
public static final short CONTENTSPECNODE_ANY_OTHER_SKIP = 39;
176
public static final short CONTENTSPECNODE_ANY_LOCAL_SKIP = 40;
182
* The content spec node type.
184
* @see #CONTENTSPECNODE_LEAF
185
* @see #CONTENTSPECNODE_ZERO_OR_ONE
186
* @see #CONTENTSPECNODE_ZERO_OR_MORE
187
* @see #CONTENTSPECNODE_ONE_OR_MORE
188
* @see #CONTENTSPECNODE_CHOICE
189
* @see #CONTENTSPECNODE_SEQ
194
* The "left hand" value object of the content spec node.
195
* leaf name.localpart, single child for unary ops, left child for binary ops.
200
* The "right hand" value of the content spec node.
201
* leaf name.uri, right child for binary ops
203
public Object otherValue;
209
/** Default constructor. */
210
public XMLContentSpec() {
214
/** Constructs a content spec with the specified values. */
215
public XMLContentSpec(short type, Object value, Object otherValue) {
216
setValues(type, value, otherValue);
220
* Constructs a content spec from the values in the specified content spec.
222
public XMLContentSpec(XMLContentSpec contentSpec) {
223
setValues(contentSpec);
227
* Constructs a content spec from the values specified by the given
228
* content spec provider and identifier.
230
public XMLContentSpec(XMLContentSpec.Provider provider,
231
int contentSpecIndex) {
232
setValues(provider, contentSpecIndex);
239
/** Clears the values. */
240
public void clear() {
246
/** Sets the values. */
247
public void setValues(short type, Object value, Object otherValue) {
250
this.otherValue = otherValue;
253
/** Sets the values of the specified content spec. */
254
public void setValues(XMLContentSpec contentSpec) {
255
type = contentSpec.type;
256
value = contentSpec.value;
257
otherValue = contentSpec.otherValue;
261
* Sets the values from the values specified by the given content spec
262
* provider and identifier. If the specified content spec cannot be
263
* provided, the values of this content spec are cleared.
265
public void setValues(XMLContentSpec.Provider provider,
266
int contentSpecIndex) {
267
if (!provider.getContentSpec(contentSpecIndex, this)) {
277
/** Returns a hash code for this node. */
278
public int hashCode() {
280
value.hashCode() << 8 |
281
otherValue.hashCode();
284
/** Returns true if the two objects are equal. */
285
public boolean equals(Object object) {
286
if (object != null && object instanceof XMLContentSpec) {
287
XMLContentSpec contentSpec = (XMLContentSpec)object;
288
return type == contentSpec.type &&
289
value == contentSpec.value &&
290
otherValue == contentSpec.otherValue;
301
* Provides a means for walking the structure built out of
302
* content spec "nodes". The user of this provider interface is
303
* responsible for knowing what the content spec node values
304
* "mean". If those values refer to content spec identifiers,
305
* then the user can call back into the provider to get the
306
* next content spec node in the structure.
308
public interface Provider {
311
// XMLContentSpec.Provider methods
315
* Fills in the provided content spec structure with content spec
316
* information for a unique identifier.
318
* @param contentSpecIndex The content spec identifier. All content
319
* spec "nodes" have a unique identifier.
320
* @param contentSpec The content spec struct to fill in with
323
* @return Returns true if the contentSpecIndex was found.
325
public boolean getContentSpec(int contentSpecIndex, XMLContentSpec contentSpec);
327
} // interface Provider
329
} // class XMLContentSpec