1 22 23 package org.xquark.schema.validation; 24 25 import org.xquark.schema.ElementDeclaration; 26 import org.xquark.schema.Particle; 27 import org.xquark.schema.SchemaConstants; 28 29 public class ElementContentIterator extends ContentIterator implements SchemaConstants { 30 private static final String RCSRevision = "$Revision: 1.1 $"; 31 private static final String RCSName = "$Name: $"; 32 33 private ElementDeclaration decl; 34 private ElementDeclaration matchedDecl = null; 35 private int count = 0; 36 37 public ElementContentIterator(ElementDeclaration decl, int min, int max) 39 { 40 super(min, max); 41 this.decl = decl; 42 } 43 44 public ElementContentIterator(Particle particle) 45 { 46 super(particle); 47 decl = (ElementDeclaration)particle.getTerm(); 48 } 49 50 public ElementDeclaration getMatchedDeclaration() { 51 return matchedDecl; 52 } 53 54 public ElementDeclaration getModelDeclaration() { 55 return decl; 56 } 57 58 public int getProcessContents() { 59 return STRICT; 60 } 61 62 protected int nextElement(String namespace, String localName) 63 { 64 if (decl.hasName(namespace, localName)) { 65 matchedDecl = decl; 66 return checkMatchedDeclaration(); 67 } else { 68 ElementDeclaration substitution = decl.getSubstitutionElement(namespace, localName); 69 if (substitution != null) { 70 matchedDecl = substitution; 71 return checkMatchedDeclaration(); 72 } else if (count == 0) { 73 return invalidElement("cvc-particle.2.3", parentParticle); 74 } else { 75 return stopProcessing(); 76 } 77 } 78 } 79 80 private int checkMatchedDeclaration() { 81 if (count == maxOccurs) { 82 invalidElement("cvc-particle.2.2", parentParticle); 83 return TOO_MANY; 84 } else { 85 if (reporter != null) 86 reporter.matched(parentParticle, count); 87 count++; 88 return MATCHED; 89 } 90 } 91 92 public int stopProcessing() { 93 if (count < minOccurs) 94 return invalidElement("cvc-particle.2.1", parentParticle); 95 else if (reporter != null && parentParticle != null && count < maxOccurs) 96 reporter.skipped(parentParticle); 97 return DONE; 98 } 99 100 protected boolean nextValidElements(java.util.List elements) { 101 if (count < maxOccurs && elements != null) { 102 if (!decl.isAbstract()) elements.add(decl); 103 decl.fillAllConcreteSubstitutionElements(elements); 104 } 105 if (count >= minOccurs) return true; 106 else return false; 107 } 108 109 } 110 111 112 | Popular Tags |