1 /* Copyright 2004 The Apache Software Foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package org.apache.xmlbeans; 17 18 import java.math.BigInteger; 19 20 import javax.xml.namespace.QName; 21 22 /** 23 * Represents a Schema particle definition. 24 * <p> 25 * The content model of a complex type is a tree of particles. Each 26 * particle is either an {@link #ALL}, {@link #CHOICE}, {@link #SEQUENCE}, 27 * {@link #ELEMENT}, or {@link #WILDCARD}. 28 * All, choice and sequence particles are groups that can have child 29 * particles; elements and wildcards are always leaves of the particle tree. 30 * <p> 31 * The tree of particles available on a schema type is minimized, that 32 * is, it already has removed "pointless" particles such as empty 33 * sequences, nonrepeating sequences with only one item, and so on. 34 * (<a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#cos-particle-restrict">Pointless particles</a> 35 * are defined precisely in the XML Schema specification.) 36 * 37 * @see SchemaType#getContentModel 38 */ 39 public interface SchemaParticle 40 { 41 /** 42 * Returns the particle type ({@link #ALL}, {@link #CHOICE}, 43 * {@link #SEQUENCE}, {@link #ELEMENT}, or {@link #WILDCARD}). 44 */ 45 int getParticleType(); 46 47 /** 48 * An <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#declare-contentModel">xs:all</a> group. 49 * See {@link #getParticleType}. 50 */ 51 static final int ALL = 1; 52 /** 53 * A <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#declare-contentModel">xs:choice</a> group. 54 * See {@link #getParticleType}. 55 */ 56 static final int CHOICE = 2; 57 /** 58 * A <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#declare-contentModel">xs:sequence</a> group. 59 * See {@link #getParticleType}. 60 */ 61 static final int SEQUENCE = 3; 62 /** 63 * An <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#declare-element">xs:element</a> particle. 64 * This code means the particle can be coerced to {@link SchemaLocalElement}. 65 * See {@link #getParticleType}. 66 */ 67 static final int ELEMENT = 4; 68 /** 69 * An <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#declare-openness">xs:any</a> particle, 70 * also known as an element wildcard. 71 * See {@link #getParticleType}. 72 */ 73 static final int WILDCARD = 5; 74 75 /** 76 * Returns the minOccurs value for this particle. 77 * If it's not specified explicitly, this returns BigInteger.ONE. 78 */ 79 BigInteger getMinOccurs(); 80 81 /** 82 * Returns the maxOccurs value for this particle, or null if it 83 * is unbounded. 84 * If it's not specified explicitly, this returns BigInteger.ONE. 85 */ 86 BigInteger getMaxOccurs(); 87 88 /** 89 * Returns the minOccurs value, pegged to a 32-bit int for 90 * convenience of a validating state machine that doesn't count 91 * higher than MAX_INT anyway. 92 */ 93 public int getIntMinOccurs(); 94 95 /** 96 * Returns the maxOccurs value, pegged to a 32-bit int for 97 * convenience of a validating state machine that doesn't count 98 * higher than MAX_INT anyway. Unbounded is given as MAX_INT. 99 */ 100 public int getIntMaxOccurs(); 101 102 103 /** 104 * One if minOccurs == maxOccurs == 1. 105 */ 106 boolean isSingleton(); 107 108 /** 109 * Applies to sequence, choice, and all particles only: returns an array 110 * of all the particle children in order. 111 */ 112 SchemaParticle[] getParticleChildren(); 113 114 /** 115 * Another way to access the particle children. 116 */ 117 SchemaParticle getParticleChild(int i); 118 119 /** 120 * The number of children. 121 */ 122 int countOfParticleChild(); 123 124 /** 125 * True if this particle can start with the given element 126 * (taking into account the structure of all child particles 127 * of course). 128 */ 129 boolean canStartWithElement(QName name); 130 131 /** 132 * Returns the QNameSet of element names that can be 133 * accepted at the beginning of this particle. 134 */ 135 QNameSet acceptedStartNames(); 136 137 /** 138 * True if this particle can be skipped (taking into account 139 * both the minOcurs as well as the structure of all the 140 * child particles) 141 */ 142 boolean isSkippable(); 143 144 /** 145 * For wildcards, returns a QNameSet representing the wildcard. 146 */ 147 QNameSet getWildcardSet(); 148 149 /** 150 * For wildcards, returns the processing code ({@link #STRICT}, {@link #LAX}, {@link #SKIP}). 151 */ 152 int getWildcardProcess(); 153 154 /** <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#Wildcard_details">Strict wildcard</a> processing. See {@link #getWildcardProcess} */ 155 static final int STRICT = 1; 156 /** <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#Wildcard_details">Lax wildcard</a> processing. See {@link #getWildcardProcess} */ 157 static final int LAX = 2; 158 /** <a target="_blank" href="http://www.w3.org/TR/xmlschema-1/#Wildcard_details">Skip wildcard</a> processing. See {@link #getWildcardProcess} */ 159 static final int SKIP = 3; 160 161 /** 162 * For elements only: the QName for the element use. 163 * May be unqualified version of referenced element's name. 164 */ 165 QName getName(); 166 167 /** 168 * For elements only: returns the type of the element. 169 */ 170 SchemaType getType(); 171 172 /** 173 * For elements only: true if nillable. 174 */ 175 boolean isNillable(); 176 177 /** 178 * For elements only: returns the default (or fixed) text value 179 */ 180 String getDefaultText(); 181 182 /** 183 * For elements only: returns the default (or fixed) strongly-typed value 184 */ 185 XmlAnySimpleType getDefaultValue(); 186 187 /** 188 * For elements only: True if has default. If isFixed, then isDefault is always true. 189 */ 190 boolean isDefault(); 191 192 /** 193 * For elements only: true if is fixed value. 194 */ 195 boolean isFixed(); 196 197 }