1 22 23 package org.xquark.schema.validation; 24 25 import org.xquark.schema.*; 26 27 public class AllContentIterator extends ContentIterator { 28 private static final String RCSRevision = "$Revision: 1.1 $"; 29 private static final String RCSName = "$Name: $"; 30 31 private AllModelGroup group; 32 private AllModelGroup current; 33 private ContentIterator iterator; 34 private boolean inUse = false; 35 36 public AllContentIterator(Particle particle) 37 { 38 super(particle); 39 group = (AllModelGroup)particle.getTerm(); 40 this.current = (AllModelGroup)group.clone(); 41 } 42 43 public ElementDeclaration getMatchedDeclaration() { 44 if (iterator != null) 45 return iterator.getMatchedDeclaration(); 46 else return null; 47 } 48 49 public ElementDeclaration getModelDeclaration() { 50 if (iterator != null) 51 return iterator.getModelDeclaration(); 52 else return null; 53 } 54 55 public int getProcessContents() { 56 if (iterator != null) 57 return iterator.getProcessContents(); 58 else return LAX; 59 } 60 61 private ContentIterator selectContentIterator(String namespace, String localName) 62 { 63 java.util.Iterator it = current.iterator(); 64 while (it.hasNext()) { 65 Particle particle = (Particle)it.next(); 66 if (particle.hasNextElement(namespace, localName)) { 67 inUse = true; 68 it.remove(); 69 return ContentIteratorFactory.createIterator(particle, reporter); 70 } 71 } 72 return null; 73 } 74 75 protected int nextElement(String namespace, String localName) 76 { 77 iterator = selectContentIterator(namespace, localName); 78 if (iterator == null) 79 return stopProcessing(); 80 switch (iterator.nextElement(namespace, localName)) { 81 case MATCHED: 82 return MATCHED; 83 case UNKNOWN: 84 return UNKNOWN; 85 case INVALID: 86 case TOO_MANY: 87 case DONE: 88 default: 89 if (iterator.getMatchedDeclaration() != null) 90 return invalidElement(iterator.getExceptions()); 91 else 92 return invalidElement("cvc-particle.3.3", parentParticle, iterator.getExceptions()); 93 } 94 } 95 96 public int stopProcessing() { 97 if (!inUse) { 98 if ( minOccurs != 0 && groupMinExtent() !=0 ) { 99 return invalidElement("cvc-particle.3.1", parentParticle); 100 } else if (reporter != null) { 101 reporter.skipped(parentParticle); 102 } 103 return DONE; 104 } 105 java.util.Iterator it = current.iterator(); 106 while (it.hasNext()) { 107 Particle particle = (Particle)it.next(); 108 if (particle.getMinExtent() > 0) { 109 SchemaException se = SchemaException.computeMinExtentException(particle); 110 return invalidElement("cvc-particle.3.3", parentParticle, se); 111 } else if (reporter != null) { 112 reporter.skipped(particle); 113 } 114 } 115 return DONE; 116 } 117 118 protected boolean nextValidElements(java.util.List elements) { 119 java.util.Iterator it = current.iterator(); 125 boolean allOptional = true; 126 while (it.hasNext()) { 127 Particle particle = (Particle)it.next(); 128 if (elements != null) { 129 if (particle.getMinExtent() > 0) 130 elements.addAll(particle.firstValidElements()); 131 else 132 elements.addAll(0, particle.firstValidElements()); 133 } 134 if (particle.getMinExtent() > 0) allOptional = false; 135 } 136 return allOptional; 137 } 138 139 private int groupMinExtent() { 140 if ( group == null || group.size() == 0 ) return 0; 141 java.util.Iterator it = group.iterator(); 142 int minExtent = 0; 143 while ( it.hasNext() ) { 144 Particle p = (Particle)it.next(); 145 minExtent += p.getMinExtent(); 146 } 147 return minExtent; 148 } 149 150 } 151 152 153 154 155 | Popular Tags |