1 57 58 package com.sun.org.apache.xerces.internal.impl.xs.traversers; 59 60 import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar; 61 import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols; 62 import com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl; 63 import com.sun.org.apache.xerces.internal.impl.xs.XSModelGroupImpl; 64 import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl; 65 import com.sun.org.apache.xerces.internal.util.DOMUtil; 66 import com.sun.org.apache.xerces.internal.impl.xs.util.XInt; 67 import com.sun.org.apache.xerces.internal.xs.XSObject; 68 import org.w3c.dom.Element ; 69 70 75 abstract class XSDAbstractParticleTraverser extends XSDAbstractTraverser { 76 77 XSDAbstractParticleTraverser (XSDHandler handler, 78 XSAttributeChecker gAttrCheck) { 79 super(handler, gAttrCheck); 80 } 81 82 93 XSParticleDecl traverseAll(Element allDecl, 94 XSDocumentInfo schemaDoc, 95 SchemaGrammar grammar, 96 int allContextFlags, 97 XSObject parent) { 98 99 101 Object [] attrValues = fAttrChecker.checkAttributes(allDecl, false, schemaDoc); 102 103 Element child = DOMUtil.getFirstChildElement(allDecl); 104 105 XSAnnotationImpl annotation = null; 106 if (child !=null) { 107 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 109 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc); 110 child = DOMUtil.getNextSiblingElement(child); 111 } 112 } 113 String childName = null; 114 XSParticleDecl particle; 115 fPArray.pushContext(); 116 117 for (; child != null; child = DOMUtil.getNextSiblingElement(child)) { 118 119 particle = null; 120 childName = DOMUtil.getLocalName(child); 121 122 if (childName.equals(SchemaSymbols.ELT_ELEMENT)) { 124 particle = fSchemaHandler.fElementTraverser.traverseLocal(child, schemaDoc, grammar, PROCESSING_ALL_EL, parent); 125 } 126 else { 127 Object [] args = {"all", "(annotation?, element*)", DOMUtil.getLocalName(child)}; 128 reportSchemaError("s4s-elt-must-match.1", args, child); 129 } 130 131 if (particle != null) 132 fPArray.addParticle(particle); 133 } 134 135 particle = null; 136 XInt minAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]; 137 XInt maxAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]; 138 Long defaultVals = (Long )attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT]; 139 140 XSModelGroupImpl group = new XSModelGroupImpl(); 141 group.fCompositor = XSModelGroupImpl.MODELGROUP_ALL; 142 group.fParticleCount = fPArray.getParticleCount(); 143 group.fParticles = fPArray.popContext(); 144 group.fAnnotation = annotation; 145 particle = new XSParticleDecl(); 146 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 147 particle.fMinOccurs = minAtt.intValue(); 148 particle.fMaxOccurs = maxAtt.intValue(); 149 particle.fValue = group; 150 151 particle = checkOccurrences(particle, 152 SchemaSymbols.ELT_ALL, 153 (Element )allDecl.getParentNode(), 154 allContextFlags, 155 defaultVals.longValue()); 156 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 157 158 return particle; 159 } 160 161 176 XSParticleDecl traverseSequence(Element seqDecl, 177 XSDocumentInfo schemaDoc, 178 SchemaGrammar grammar, 179 int allContextFlags, 180 XSObject parent) { 181 182 return traverseSeqChoice(seqDecl, schemaDoc, grammar, allContextFlags, false, parent); 183 } 184 185 200 XSParticleDecl traverseChoice(Element choiceDecl, 201 XSDocumentInfo schemaDoc, 202 SchemaGrammar grammar, 203 int allContextFlags, 204 XSObject parent) { 205 206 return traverseSeqChoice (choiceDecl, schemaDoc, grammar, allContextFlags, true, parent); 207 } 208 209 218 private XSParticleDecl traverseSeqChoice(Element decl, 219 XSDocumentInfo schemaDoc, 220 SchemaGrammar grammar, 221 int allContextFlags, 222 boolean choice, 223 XSObject parent) { 224 225 Object [] attrValues = fAttrChecker.checkAttributes(decl, false, schemaDoc); 227 228 Element child = DOMUtil.getFirstChildElement(decl); 229 XSAnnotationImpl annotation = null; 230 if (child !=null) { 231 if (DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 233 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc); 234 child = DOMUtil.getNextSiblingElement(child); 235 } 236 } 237 boolean hadContent = false; 238 String childName = null; 239 XSParticleDecl particle; 240 fPArray.pushContext(); 241 242 for (;child != null;child = DOMUtil.getNextSiblingElement(child)) { 243 244 particle = null; 245 246 childName = DOMUtil.getLocalName(child); 247 if (childName.equals(SchemaSymbols.ELT_ELEMENT)) { 248 particle = fSchemaHandler.fElementTraverser.traverseLocal(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent); 249 } 250 else if (childName.equals(SchemaSymbols.ELT_GROUP)) { 251 particle = fSchemaHandler.fGroupTraverser.traverseLocal(child, schemaDoc, grammar); 252 253 if (hasAllContent(particle)) { 256 particle = null; 259 reportSchemaError("cos-all-limited.1.2", null, child); 260 } 261 262 } 263 else if (childName.equals(SchemaSymbols.ELT_CHOICE)) { 264 particle = traverseChoice(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent); 265 } 266 else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) { 267 particle = traverseSequence(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent); 268 } 269 else if (childName.equals(SchemaSymbols.ELT_ANY)) { 270 particle = fSchemaHandler.fWildCardTraverser.traverseAny(child, schemaDoc, grammar); 271 } 272 else { 273 Object [] args; 274 if (choice) { 275 args = new Object []{"choice", "(annotation?, (element | group | choice | sequence | any)*)", DOMUtil.getLocalName(child)}; 276 } 277 else { 278 args = new Object []{"sequence", "(annotation?, (element | group | choice | sequence | any)*)", DOMUtil.getLocalName(child)}; 279 } 280 reportSchemaError("s4s-elt-must-match.1", args, child); 281 } 282 283 if (particle != null) 284 fPArray.addParticle(particle); 285 } 286 287 particle = null; 288 289 XInt minAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]; 290 XInt maxAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]; 291 Long defaultVals = (Long )attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT]; 292 293 XSModelGroupImpl group = new XSModelGroupImpl(); 294 group.fCompositor = choice ? XSModelGroupImpl.MODELGROUP_CHOICE : XSModelGroupImpl.MODELGROUP_SEQUENCE; 295 group.fParticleCount = fPArray.getParticleCount(); 296 group.fParticles = fPArray.popContext(); 297 group.fAnnotation = annotation; 298 particle = new XSParticleDecl(); 299 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 300 particle.fMinOccurs = minAtt.intValue(); 301 particle.fMaxOccurs = maxAtt.intValue(); 302 particle.fValue = group; 303 304 particle = checkOccurrences(particle, 305 choice ? SchemaSymbols.ELT_CHOICE : SchemaSymbols.ELT_SEQUENCE, 306 (Element )decl.getParentNode(), 307 allContextFlags, 308 defaultVals.longValue()); 309 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 310 311 return particle; 312 } 313 314 protected boolean hasAllContent(XSParticleDecl particle) { 316 if (particle != null && particle.fType == XSParticleDecl.PARTICLE_MODELGROUP) { 318 return ((XSModelGroupImpl)particle.fValue).fCompositor == XSModelGroupImpl.MODELGROUP_ALL; 319 } 320 321 return false; 322 } 323 324 protected static class ParticleArray { 334 XSParticleDecl[] fParticles = new XSParticleDecl[10]; 336 int[] fPos = new int[5]; 341 int fContextCount = 0; 343 344 void pushContext() { 346 fContextCount++; 347 if (fContextCount == fPos.length) { 349 int newSize = fContextCount * 2; 350 int[] newArray = new int[newSize]; 351 System.arraycopy(fPos, 0, newArray, 0, fContextCount); 352 fPos = newArray; 353 } 354 fPos[fContextCount] = fPos[fContextCount-1]; 358 } 359 360 int getParticleCount() { 362 return fPos[fContextCount] - fPos[fContextCount-1]; 363 } 364 365 void addParticle(XSParticleDecl particle) { 367 if (fPos[fContextCount] == fParticles.length) { 369 int newSize = fPos[fContextCount] * 2; 370 XSParticleDecl[] newArray = new XSParticleDecl[newSize]; 371 System.arraycopy(fParticles, 0, newArray, 0, fPos[fContextCount]); 372 fParticles = newArray; 373 } 374 fParticles[fPos[fContextCount]++] = particle; 375 } 376 377 XSParticleDecl[] popContext() { 379 int count = fPos[fContextCount] - fPos[fContextCount-1]; 380 XSParticleDecl[] array = null; 381 if (count != 0) { 382 array = new XSParticleDecl[count]; 383 System.arraycopy(fParticles, fPos[fContextCount-1], array, 0, count); 384 for (int i = fPos[fContextCount-1]; i < fPos[fContextCount]; i++) 386 fParticles[i] = null; 387 } 388 fContextCount--; 389 return array; 390 } 391 392 } 393 394 ParticleArray fPArray = new ParticleArray(); 396 } 397 | Popular Tags |