1 22 23 package org.xquark.schema.validation; 24 25 import org.xquark.schema.*; 26 27 public class WildcardContentIterator extends ContentIterator 28 implements SchemaConstants 29 { 30 private static final String RCSRevision = "$Revision: 1.1 $"; 31 private static final String RCSName = "$Name: $"; 32 private Wildcard wildcard; 33 private int count = 0; 34 private int process; 35 private ElementDeclaration matchedDecl = null; 36 37 public WildcardContentIterator(Particle particle) 38 { 39 super(particle.getMinOccurs(), particle.getMaxOccurs()); 40 this.parentParticle = particle; 41 wildcard = (Wildcard)particle.getTerm(); 42 process = wildcard.getProcessContents(); 43 } 44 45 public ElementDeclaration getMatchedDeclaration() { 46 return matchedDecl; 47 } 48 49 public int getProcessContents() { 50 return process; 51 } 52 53 protected int nextElement(String namespace, String localName) 54 { 55 if (namespace != null && namespace.length() == 0) 56 namespace = null; 57 58 String errCode = wildcard.checkNamespaceAllowed(namespace); 59 if (errCode != null) { 60 if ( count == 0 ) 61 return invalidElement("cvc-particle.1.3", parentParticle, new SchemaException(errCode, wildcard)); 62 else 63 return stopProcessing(); 64 } 65 66 if (count == maxOccurs) { 67 invalidElement("cvc-particle.1.2", parentParticle); 68 return TOO_MANY; 69 } 70 if (reporter != null) 71 reporter.matched(parentParticle, count); 72 count++; 73 74 if (process == Wildcard.SKIP) return ContentIterator.UNKNOWN; 75 76 matchedDecl = wildcard.getManager().getElementDeclaration(namespace, localName); 77 if (matchedDecl != null) 78 return MATCHED; 79 else 80 return ContentIterator.UNKNOWN; 81 } 82 83 public int stopProcessing() { 84 if (count < minOccurs) 85 return invalidElement("cvc-particle.1.1", parentParticle); 86 else { 87 if (reporter != null && parentParticle != null && count < maxOccurs) 88 reporter.skipped(parentParticle); 89 return DONE; 90 } 91 } 92 93 protected boolean nextValidElements(java.util.List elements) { 94 return count >= minOccurs; 95 } 96 97 } 98 99 100 | Popular Tags |