1 57 58 package com.sun.org.apache.xerces.internal.impl.xs; 59 60 import com.sun.org.apache.xerces.internal.xs.*; 61 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 62 63 70 public class XSModelGroupImpl implements XSModelGroup { 71 72 public static final short MODELGROUP_CHOICE = 101; 77 public static final short MODELGROUP_SEQUENCE = 102; 78 public static final short MODELGROUP_ALL = 103; 79 80 public short fCompositor; 82 83 public XSParticleDecl[] fParticles = null; 85 public int fParticleCount = 0; 86 87 public XSAnnotationImpl fAnnotation; 89 90 public boolean isEmpty() { 92 for (int i = 0; i < fParticleCount; i++) { 93 if (!fParticles[i].isEmpty()) 94 return false; 95 } 96 return true; 97 } 98 99 106 public int minEffectiveTotalRange() { 107 if (fCompositor == MODELGROUP_CHOICE) 108 return minEffectiveTotalRangeChoice(); 109 else 110 return minEffectiveTotalRangeAllSeq(); 111 } 112 113 private int minEffectiveTotalRangeAllSeq() { 115 int total = 0; 116 for (int i = 0; i < fParticleCount; i++) 117 total += fParticles[i].minEffectiveTotalRange(); 118 return total; 119 } 120 121 private int minEffectiveTotalRangeChoice() { 123 int min = 0, one; 124 if (fParticleCount > 0) 125 min = fParticles[0].minEffectiveTotalRange(); 126 127 for (int i = 1; i < fParticleCount; i++) { 128 one = fParticles[i].minEffectiveTotalRange(); 129 if (one < min) 130 min = one; 131 } 132 133 return min; 134 } 135 136 public int maxEffectiveTotalRange() { 137 if (fCompositor == MODELGROUP_CHOICE) 138 return maxEffectiveTotalRangeChoice(); 139 else 140 return maxEffectiveTotalRangeAllSeq(); 141 } 142 143 private int maxEffectiveTotalRangeAllSeq() { 146 int total = 0, one; 147 for (int i = 0; i < fParticleCount; i++) { 148 one = fParticles[i].maxEffectiveTotalRange(); 149 if (one == SchemaSymbols.OCCURRENCE_UNBOUNDED) 150 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 151 total += one; 152 } 153 return total; 154 } 155 156 private int maxEffectiveTotalRangeChoice() { 159 int max = 0, one; 160 if (fParticleCount > 0) { 161 max = fParticles[0].maxEffectiveTotalRange(); 162 if (max == SchemaSymbols.OCCURRENCE_UNBOUNDED) 163 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 164 } 165 166 for (int i = 1; i < fParticleCount; i++) { 167 one = fParticles[i].maxEffectiveTotalRange(); 168 if (one == SchemaSymbols.OCCURRENCE_UNBOUNDED) 169 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 170 if (one > max) 171 max = one; 172 } 173 return max; 174 } 175 176 179 private String fDescription = null; 180 public String toString() { 181 if (fDescription == null) { 182 StringBuffer buffer = new StringBuffer (); 183 if (fCompositor == MODELGROUP_ALL) 184 buffer.append("all("); 185 else 186 buffer.append('('); 187 if (fParticleCount > 0) 188 buffer.append(fParticles[0].toString()); 189 for (int i = 1; i < fParticleCount; i++) { 190 if (fCompositor == MODELGROUP_CHOICE) 191 buffer.append('|'); 192 else 193 buffer.append(','); 194 buffer.append(fParticles[i].toString()); 195 } 196 buffer.append(')'); 197 fDescription = buffer.toString(); 198 } 199 return fDescription; 200 } 201 202 public void reset(){ 203 fCompositor = MODELGROUP_SEQUENCE; 204 fParticles = null; 205 fParticleCount = 0; 206 fDescription = null; 207 fAnnotation = null; 208 } 209 210 213 public short getType() { 214 return XSConstants.MODEL_GROUP; 215 } 216 217 221 public String getName() { 222 return null; 223 } 224 225 230 public String getNamespace() { 231 return null; 232 } 233 234 238 public short getCompositor() { 239 if (fCompositor == MODELGROUP_CHOICE) 240 return XSModelGroup.COMPOSITOR_CHOICE; 241 else if (fCompositor == MODELGROUP_SEQUENCE) 242 return XSModelGroup.COMPOSITOR_SEQUENCE; 243 else 244 return XSModelGroup.COMPOSITOR_ALL; 245 } 246 247 250 public XSObjectList getParticles() { 251 return new XSObjectListImpl(fParticles, fParticleCount); 252 } 253 254 257 public XSAnnotation getAnnotation() { 258 return fAnnotation; 259 } 260 261 264 public XSNamespaceItem getNamespaceItem() { 265 return null; 266 } 267 268 } | Popular Tags |