1 16 17 package org.apache.xerces.impl.xs; 18 19 import org.apache.xerces.xs.*; 20 import org.apache.xerces.impl.xs.util.XSObjectListImpl; 21 22 31 public class XSModelGroupImpl implements XSModelGroup { 32 33 public static final short MODELGROUP_CHOICE = 101; 38 public static final short MODELGROUP_SEQUENCE = 102; 39 public static final short MODELGROUP_ALL = 103; 40 41 public short fCompositor; 43 44 public XSParticleDecl[] fParticles = null; 46 public int fParticleCount = 0; 47 48 public XSAnnotationImpl fAnnotation; 50 51 public boolean isEmpty() { 53 for (int i = 0; i < fParticleCount; i++) { 54 if (!fParticles[i].isEmpty()) 55 return false; 56 } 57 return true; 58 } 59 60 67 public int minEffectiveTotalRange() { 68 if (fCompositor == MODELGROUP_CHOICE) 69 return minEffectiveTotalRangeChoice(); 70 else 71 return minEffectiveTotalRangeAllSeq(); 72 } 73 74 private int minEffectiveTotalRangeAllSeq() { 76 int total = 0; 77 for (int i = 0; i < fParticleCount; i++) 78 total += fParticles[i].minEffectiveTotalRange(); 79 return total; 80 } 81 82 private int minEffectiveTotalRangeChoice() { 84 int min = 0, one; 85 if (fParticleCount > 0) 86 min = fParticles[0].minEffectiveTotalRange(); 87 88 for (int i = 1; i < fParticleCount; i++) { 89 one = fParticles[i].minEffectiveTotalRange(); 90 if (one < min) 91 min = one; 92 } 93 94 return min; 95 } 96 97 public int maxEffectiveTotalRange() { 98 if (fCompositor == MODELGROUP_CHOICE) 99 return maxEffectiveTotalRangeChoice(); 100 else 101 return maxEffectiveTotalRangeAllSeq(); 102 } 103 104 private int maxEffectiveTotalRangeAllSeq() { 107 int total = 0, one; 108 for (int i = 0; i < fParticleCount; i++) { 109 one = fParticles[i].maxEffectiveTotalRange(); 110 if (one == SchemaSymbols.OCCURRENCE_UNBOUNDED) 111 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 112 total += one; 113 } 114 return total; 115 } 116 117 private int maxEffectiveTotalRangeChoice() { 120 int max = 0, one; 121 if (fParticleCount > 0) { 122 max = fParticles[0].maxEffectiveTotalRange(); 123 if (max == SchemaSymbols.OCCURRENCE_UNBOUNDED) 124 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 125 } 126 127 for (int i = 1; i < fParticleCount; i++) { 128 one = fParticles[i].maxEffectiveTotalRange(); 129 if (one == SchemaSymbols.OCCURRENCE_UNBOUNDED) 130 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 131 if (one > max) 132 max = one; 133 } 134 return max; 135 } 136 137 140 private String fDescription = null; 141 public String toString() { 142 if (fDescription == null) { 144 StringBuffer buffer = new StringBuffer (); 145 if (fCompositor == MODELGROUP_ALL) 146 buffer.append("all("); 147 else buffer.append('('); 149 if (fParticleCount > 0) 150 buffer.append(fParticles[0].toString()); 151 for (int i = 1; i < fParticleCount; i++) { 152 if (fCompositor == MODELGROUP_CHOICE) 153 buffer.append('|'); 154 else 155 buffer.append(','); 156 buffer.append(fParticles[i].toString()); 157 } 158 buffer.append(')'); 160 fDescription = buffer.toString(); 161 } 162 return fDescription; 163 } 164 165 public void reset(){ 166 fCompositor = MODELGROUP_SEQUENCE; 167 fParticles = null; 168 fParticleCount = 0; 169 fDescription = null; 170 fAnnotation = null; 171 } 172 173 176 public short getType() { 177 return XSConstants.MODEL_GROUP; 178 } 179 180 184 public String getName() { 185 return null; 186 } 187 188 193 public String getNamespace() { 194 return null; 195 } 196 197 201 public short getCompositor() { 202 if (fCompositor == MODELGROUP_CHOICE) 203 return XSModelGroup.COMPOSITOR_CHOICE; 204 else if (fCompositor == MODELGROUP_SEQUENCE) 205 return XSModelGroup.COMPOSITOR_SEQUENCE; 206 else 207 return XSModelGroup.COMPOSITOR_ALL; 208 } 209 210 213 public XSObjectList getParticles() { 214 return new XSObjectListImpl(fParticles, fParticleCount); 215 } 216 217 220 public XSAnnotation getAnnotation() { 221 return fAnnotation; 222 } 223 224 227 public XSNamespaceItem getNamespaceItem() { 228 return null; 229 } 230 231 } | Popular Tags |