2
* The Apache Software License, Version 1.1
5
* Copyright (c) 2001, 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) 2001, 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.xs;
60
import org.apache.xerces.xs.XSConstants;
61
import org.apache.xerces.xs.XSNamespaceItem;
62
import org.apache.xerces.xs.XSParticle;
63
import org.apache.xerces.xs.XSTerm;
66
* Store schema particle declaration.
68
* @author Sandy Gao, IBM
70
* @version $Id: XSParticleDecl.java,v 1.12 2003/11/11 20:14:58 sandygao Exp $
72
public class XSParticleDecl implements XSParticle {
75
public static final short PARTICLE_EMPTY = 0;
76
public static final short PARTICLE_ELEMENT = 1;
77
public static final short PARTICLE_WILDCARD = 2;
78
public static final short PARTICLE_MODELGROUP = 3;
79
public static final short PARTICLE_ZERO_OR_MORE = 4;
80
public static final short PARTICLE_ZERO_OR_ONE = 5;
81
public static final short PARTICLE_ONE_OR_MORE = 6;
83
// type of the particle
84
public short fType = PARTICLE_EMPTY;
86
// term of the particle
87
// for PARTICLE_ELEMENT : the element decl
88
// for PARTICLE_WILDCARD: the wildcard decl
89
// for PARTICLE_MODELGROUP: the model group
90
public XSTerm fValue = null;
92
// minimum occurrence of this particle
93
public int fMinOccurs = 1;
94
// maximum occurrence of this particle
95
public int fMaxOccurs = 1;
98
public XSParticleDecl makeClone() {
99
XSParticleDecl particle = new XSParticleDecl();
100
particle.fType = fType;
101
particle.fMinOccurs = fMinOccurs;
102
particle.fMaxOccurs = fMaxOccurs;
103
particle.fDescription = fDescription;
104
particle.fValue = fValue;
109
* 3.9.6 Schema Component Constraint: Particle Emptiable
110
* whether this particle is emptible
112
public boolean emptiable() {
113
return minEffectiveTotalRange() == 0;
116
// whether this particle contains nothing
117
public boolean isEmpty() {
118
if (fType == PARTICLE_EMPTY)
120
if (fType == PARTICLE_ELEMENT || fType == PARTICLE_WILDCARD)
123
return ((XSModelGroupImpl)fValue).isEmpty();
127
* 3.8.6 Effective Total Range (all and sequence) and
128
* Effective Total Range (choice)
129
* The following methods are used to return min/max range for a particle.
130
* They are not exactly the same as it's described in the spec, but all the
131
* values from the spec are retrievable by these methods.
133
public int minEffectiveTotalRange() {
134
if (fType == XSParticleDecl.PARTICLE_EMPTY) {
137
if (fType == PARTICLE_MODELGROUP) {
138
return ((XSModelGroupImpl)fValue).minEffectiveTotalRange() * fMinOccurs;
143
public int maxEffectiveTotalRange() {
144
if (fType == XSParticleDecl.PARTICLE_EMPTY) {
147
if (fType == PARTICLE_MODELGROUP) {
148
int max = ((XSModelGroupImpl)fValue).maxEffectiveTotalRange();
149
if (max == SchemaSymbols.OCCURRENCE_UNBOUNDED)
150
return SchemaSymbols.OCCURRENCE_UNBOUNDED;
151
if (max != 0 && fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED)
152
return SchemaSymbols.OCCURRENCE_UNBOUNDED;
153
return max * fMaxOccurs;
159
* get the string description of this particle
161
private String fDescription = null;
162
public String toString() {
163
if (fDescription == null) {
164
StringBuffer buffer = new StringBuffer();
165
appendParticle(buffer);
166
if (!(fMinOccurs == 0 && fMaxOccurs == 0 ||
167
fMinOccurs == 1 && fMaxOccurs == 1)) {
168
buffer.append("{" + fMinOccurs);
169
if (fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED)
170
buffer.append("-UNBOUNDED");
171
else if (fMinOccurs != fMaxOccurs)
172
buffer.append("-" + fMaxOccurs);
175
fDescription = buffer.toString();
181
* append the string description of this particle to the string buffer
182
* this is for error message.
184
void appendParticle(StringBuffer buffer) {
187
buffer.append("EMPTY");
189
case PARTICLE_ELEMENT:
190
case PARTICLE_WILDCARD:
192
buffer.append(fValue.toString());
195
case PARTICLE_MODELGROUP:
196
buffer.append(fValue.toString());
202
fType = PARTICLE_EMPTY;
210
* Get the type of the object, i.e ELEMENT_DECLARATION.
212
public short getType() {
213
return XSConstants.PARTICLE;
217
* The <code>name</code> of this <code>XSObject</code> depending on the
218
* <code>XSObject</code> type.
220
public String getName() {
225
* The namespace URI of this node, or <code>null</code> if it is
226
* unspecified. defines how a namespace URI is attached to schema
229
public String getNamespace() {
234
* {min occurs} determines the minimum number of terms that can occur.
236
public int getMinOccurs() {
241
* {max occurs} whether the maxOccurs value is unbounded.
243
public boolean getMaxOccursUnbounded() {
244
return fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED;
248
* {max occurs} determines the maximum number of terms that can occur.
250
public int getMaxOccurs() {
255
* {term} One of a model group, a wildcard, or an element declaration.
257
public XSTerm getTerm() {
262
* @see org.apache.xerces.xs.XSObject#getNamespaceItem()
264
public XSNamespaceItem getNamespaceItem() {
268
} // class XSParticle