1 16 17 package org.apache.xerces.impl.xs.traversers; 18 19 import org.apache.xerces.impl.xs.SchemaGrammar; 20 import org.apache.xerces.impl.xs.SchemaSymbols; 21 import org.apache.xerces.impl.xs.XSAnnotationImpl; 22 import org.apache.xerces.impl.xs.XSModelGroupImpl; 23 import org.apache.xerces.impl.xs.XSParticleDecl; 24 import org.apache.xerces.impl.xs.util.XInt; 25 import org.apache.xerces.util.DOMUtil; 26 import org.apache.xerces.xs.XSObject; 27 import org.w3c.dom.Element ; 28 29 36 abstract class XSDAbstractParticleTraverser extends XSDAbstractTraverser { 37 38 XSDAbstractParticleTraverser (XSDHandler handler, 39 XSAttributeChecker gAttrCheck) { 40 super(handler, gAttrCheck); 41 } 42 43 54 XSParticleDecl traverseAll(Element allDecl, 55 XSDocumentInfo schemaDoc, 56 SchemaGrammar grammar, 57 int allContextFlags, 58 XSObject parent) { 59 60 62 Object [] attrValues = fAttrChecker.checkAttributes(allDecl, false, schemaDoc); 63 64 Element child = DOMUtil.getFirstChildElement(allDecl); 65 66 XSAnnotationImpl annotation = null; 67 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 68 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc); 69 child = DOMUtil.getNextSiblingElement(child); 70 } 71 else { 72 String text = DOMUtil.getSyntheticAnnotation(allDecl); 73 if (text != null) { 74 annotation = traverseSyntheticAnnotation(allDecl, text, attrValues, false, schemaDoc); 75 } 76 } 77 String childName = null; 78 XSParticleDecl particle; 79 fPArray.pushContext(); 80 81 for (; child != null; child = DOMUtil.getNextSiblingElement(child)) { 82 83 particle = null; 84 childName = DOMUtil.getLocalName(child); 85 86 if (childName.equals(SchemaSymbols.ELT_ELEMENT)) { 88 particle = fSchemaHandler.fElementTraverser.traverseLocal(child, schemaDoc, grammar, PROCESSING_ALL_EL, parent); 89 } 90 else { 91 Object [] args = {"all", "(annotation?, element*)", DOMUtil.getLocalName(child)}; 92 reportSchemaError("s4s-elt-must-match.1", args, child); 93 } 94 95 if (particle != null) 96 fPArray.addParticle(particle); 97 } 98 99 particle = null; 100 XInt minAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]; 101 XInt maxAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]; 102 Long defaultVals = (Long )attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT]; 103 104 XSModelGroupImpl group = new XSModelGroupImpl(); 105 group.fCompositor = XSModelGroupImpl.MODELGROUP_ALL; 106 group.fParticleCount = fPArray.getParticleCount(); 107 group.fParticles = fPArray.popContext(); 108 group.fAnnotation = annotation; 109 particle = new XSParticleDecl(); 110 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 111 particle.fMinOccurs = minAtt.intValue(); 112 particle.fMaxOccurs = maxAtt.intValue(); 113 particle.fValue = group; 114 115 particle = checkOccurrences(particle, 116 SchemaSymbols.ELT_ALL, 117 (Element )allDecl.getParentNode(), 118 allContextFlags, 119 defaultVals.longValue()); 120 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 121 122 return particle; 123 } 124 125 140 XSParticleDecl traverseSequence(Element seqDecl, 141 XSDocumentInfo schemaDoc, 142 SchemaGrammar grammar, 143 int allContextFlags, 144 XSObject parent) { 145 146 return traverseSeqChoice(seqDecl, schemaDoc, grammar, allContextFlags, false, parent); 147 } 148 149 164 XSParticleDecl traverseChoice(Element choiceDecl, 165 XSDocumentInfo schemaDoc, 166 SchemaGrammar grammar, 167 int allContextFlags, 168 XSObject parent) { 169 170 return traverseSeqChoice (choiceDecl, schemaDoc, grammar, allContextFlags, true, parent); 171 } 172 173 182 private XSParticleDecl traverseSeqChoice(Element decl, 183 XSDocumentInfo schemaDoc, 184 SchemaGrammar grammar, 185 int allContextFlags, 186 boolean choice, 187 XSObject parent) { 188 189 Object [] attrValues = fAttrChecker.checkAttributes(decl, false, schemaDoc); 191 192 Element child = DOMUtil.getFirstChildElement(decl); 193 XSAnnotationImpl annotation = null; 194 if (child !=null && DOMUtil.getLocalName(child).equals(SchemaSymbols.ELT_ANNOTATION)) { 195 annotation = traverseAnnotationDecl(child, attrValues, false, schemaDoc); 196 child = DOMUtil.getNextSiblingElement(child); 197 } 198 else { 199 String text = DOMUtil.getSyntheticAnnotation(decl); 200 if (text != null) { 201 annotation = traverseSyntheticAnnotation(decl, text, attrValues, false, schemaDoc); 202 } 203 } 204 205 boolean hadContent = false; 206 String childName = null; 207 XSParticleDecl particle; 208 fPArray.pushContext(); 209 210 for (;child != null;child = DOMUtil.getNextSiblingElement(child)) { 211 212 particle = null; 213 214 childName = DOMUtil.getLocalName(child); 215 if (childName.equals(SchemaSymbols.ELT_ELEMENT)) { 216 particle = fSchemaHandler.fElementTraverser.traverseLocal(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent); 217 } 218 else if (childName.equals(SchemaSymbols.ELT_GROUP)) { 219 particle = fSchemaHandler.fGroupTraverser.traverseLocal(child, schemaDoc, grammar); 220 221 if (hasAllContent(particle)) { 224 particle = null; 227 reportSchemaError("cos-all-limited.1.2", null, child); 228 } 229 230 } 231 else if (childName.equals(SchemaSymbols.ELT_CHOICE)) { 232 particle = traverseChoice(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent); 233 } 234 else if (childName.equals(SchemaSymbols.ELT_SEQUENCE)) { 235 particle = traverseSequence(child, schemaDoc, grammar, NOT_ALL_CONTEXT, parent); 236 } 237 else if (childName.equals(SchemaSymbols.ELT_ANY)) { 238 particle = fSchemaHandler.fWildCardTraverser.traverseAny(child, schemaDoc, grammar); 239 } 240 else { 241 Object [] args; 242 if (choice) { 243 args = new Object []{"choice", "(annotation?, (element | group | choice | sequence | any)*)", DOMUtil.getLocalName(child)}; 244 } 245 else { 246 args = new Object []{"sequence", "(annotation?, (element | group | choice | sequence | any)*)", DOMUtil.getLocalName(child)}; 247 } 248 reportSchemaError("s4s-elt-must-match.1", args, child); 249 } 250 251 if (particle != null) 252 fPArray.addParticle(particle); 253 } 254 255 particle = null; 256 257 XInt minAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MINOCCURS]; 258 XInt maxAtt = (XInt)attrValues[XSAttributeChecker.ATTIDX_MAXOCCURS]; 259 Long defaultVals = (Long )attrValues[XSAttributeChecker.ATTIDX_FROMDEFAULT]; 260 261 XSModelGroupImpl group = new XSModelGroupImpl(); 262 group.fCompositor = choice ? XSModelGroupImpl.MODELGROUP_CHOICE : XSModelGroupImpl.MODELGROUP_SEQUENCE; 263 group.fParticleCount = fPArray.getParticleCount(); 264 group.fParticles = fPArray.popContext(); 265 group.fAnnotation = annotation; 266 particle = new XSParticleDecl(); 267 particle.fType = XSParticleDecl.PARTICLE_MODELGROUP; 268 particle.fMinOccurs = minAtt.intValue(); 269 particle.fMaxOccurs = maxAtt.intValue(); 270 particle.fValue = group; 271 272 particle = checkOccurrences(particle, 273 choice ? SchemaSymbols.ELT_CHOICE : SchemaSymbols.ELT_SEQUENCE, 274 (Element )decl.getParentNode(), 275 allContextFlags, 276 defaultVals.longValue()); 277 fAttrChecker.returnAttrArray(attrValues, schemaDoc); 278 279 return particle; 280 } 281 282 protected boolean hasAllContent(XSParticleDecl particle) { 284 if (particle != null && particle.fType == XSParticleDecl.PARTICLE_MODELGROUP) { 286 return ((XSModelGroupImpl)particle.fValue).fCompositor == XSModelGroupImpl.MODELGROUP_ALL; 287 } 288 289 return false; 290 } 291 292 protected static class ParticleArray { 302 XSParticleDecl[] fParticles = new XSParticleDecl[10]; 304 int[] fPos = new int[5]; 309 int fContextCount = 0; 311 312 void pushContext() { 314 fContextCount++; 315 if (fContextCount == fPos.length) { 317 int newSize = fContextCount * 2; 318 int[] newArray = new int[newSize]; 319 System.arraycopy(fPos, 0, newArray, 0, fContextCount); 320 fPos = newArray; 321 } 322 fPos[fContextCount] = fPos[fContextCount-1]; 326 } 327 328 int getParticleCount() { 330 return fPos[fContextCount] - fPos[fContextCount-1]; 331 } 332 333 void addParticle(XSParticleDecl particle) { 335 if (fPos[fContextCount] == fParticles.length) { 337 int newSize = fPos[fContextCount] * 2; 338 XSParticleDecl[] newArray = new XSParticleDecl[newSize]; 339 System.arraycopy(fParticles, 0, newArray, 0, fPos[fContextCount]); 340 fParticles = newArray; 341 } 342 fParticles[fPos[fContextCount]++] = particle; 343 } 344 345 XSParticleDecl[] popContext() { 347 int count = fPos[fContextCount] - fPos[fContextCount-1]; 348 XSParticleDecl[] array = null; 349 if (count != 0) { 350 array = new XSParticleDecl[count]; 351 System.arraycopy(fParticles, fPos[fContextCount-1], array, 0, count); 352 for (int i = fPos[fContextCount-1]; i < fPos[fContextCount]; i++) 354 fParticles[i] = null; 355 } 356 fContextCount--; 357 return array; 358 } 359 360 } 361 362 ParticleArray fPArray = new ParticleArray(); 364 } 365 | Popular Tags |