1 57 58 package com.sun.org.apache.xerces.internal.impl.xs; 59 60 import com.sun.org.apache.xerces.internal.xs.XSConstants; 61 import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem; 62 import com.sun.org.apache.xerces.internal.xs.XSParticle; 63 import com.sun.org.apache.xerces.internal.xs.XSTerm; 64 65 72 public class XSParticleDecl implements XSParticle { 73 74 public static final short PARTICLE_EMPTY = 0; 76 public static final short PARTICLE_ELEMENT = 1; 77 public static final short PARTICLE_WILDCARD = 2; 78 public static final short PARTICLE_MODELGROUP = 3; 79 public static final short PARTICLE_ZERO_OR_MORE = 4; 80 public static final short PARTICLE_ZERO_OR_ONE = 5; 81 public static final short PARTICLE_ONE_OR_MORE = 6; 82 83 public short fType = PARTICLE_EMPTY; 85 86 public XSTerm fValue = null; 91 92 public int fMinOccurs = 1; 94 public int fMaxOccurs = 1; 96 97 public XSParticleDecl makeClone() { 99 XSParticleDecl particle = new XSParticleDecl(); 100 particle.fType = fType; 101 particle.fMinOccurs = fMinOccurs; 102 particle.fMaxOccurs = fMaxOccurs; 103 particle.fDescription = fDescription; 104 particle.fValue = fValue; 105 return particle; 106 } 107 108 112 public boolean emptiable() { 113 return minEffectiveTotalRange() == 0; 114 } 115 116 public boolean isEmpty() { 118 if (fType == PARTICLE_EMPTY) 119 return true; 120 if (fType == PARTICLE_ELEMENT || fType == PARTICLE_WILDCARD) 121 return false; 122 123 return ((XSModelGroupImpl)fValue).isEmpty(); 124 } 125 126 133 public int minEffectiveTotalRange() { 134 if (fType == XSParticleDecl.PARTICLE_EMPTY) { 135 return 0; 136 } 137 if (fType == PARTICLE_MODELGROUP) { 138 return ((XSModelGroupImpl)fValue).minEffectiveTotalRange() * fMinOccurs; 139 } 140 return fMinOccurs; 141 } 142 143 public int maxEffectiveTotalRange() { 144 if (fType == XSParticleDecl.PARTICLE_EMPTY) { 145 return 0; 146 } 147 if (fType == PARTICLE_MODELGROUP) { 148 int max = ((XSModelGroupImpl)fValue).maxEffectiveTotalRange(); 149 if (max == SchemaSymbols.OCCURRENCE_UNBOUNDED) 150 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 151 if (max != 0 && fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED) 152 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 153 return max * fMaxOccurs; 154 } 155 return fMaxOccurs; 156 } 157 158 161 private String fDescription = null; 162 public String toString() { 163 if (fDescription == null) { 164 StringBuffer buffer = new StringBuffer (); 165 appendParticle(buffer); 166 if (!(fMinOccurs == 0 && fMaxOccurs == 0 || 167 fMinOccurs == 1 && fMaxOccurs == 1)) { 168 buffer.append("{" + fMinOccurs); 169 if (fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED) 170 buffer.append("-UNBOUNDED"); 171 else if (fMinOccurs != fMaxOccurs) 172 buffer.append("-" + fMaxOccurs); 173 buffer.append("}"); 174 } 175 fDescription = buffer.toString(); 176 } 177 return fDescription; 178 } 179 180 184 void appendParticle(StringBuffer buffer) { 185 switch (fType) { 186 case PARTICLE_EMPTY: 187 buffer.append("EMPTY"); 188 break; 189 case PARTICLE_ELEMENT: 190 case PARTICLE_WILDCARD: 191 buffer.append('('); 192 buffer.append(fValue.toString()); 193 buffer.append(')'); 194 break; 195 case PARTICLE_MODELGROUP: 196 buffer.append(fValue.toString()); 197 break; 198 } 199 } 200 201 public void reset(){ 202 fType = PARTICLE_EMPTY; 203 fValue = null; 204 fMinOccurs = 1; 205 fMaxOccurs = 1; 206 fDescription = null; 207 } 208 209 212 public short getType() { 213 return XSConstants.PARTICLE; 214 } 215 216 220 public String getName() { 221 return null; 222 } 223 224 229 public String getNamespace() { 230 return null; 231 } 232 233 236 public int getMinOccurs() { 237 return fMinOccurs; 238 } 239 240 243 public boolean getMaxOccursUnbounded() { 244 return fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED; 245 } 246 247 250 public int getMaxOccurs() { 251 return fMaxOccurs; 252 } 253 254 257 public XSTerm getTerm() { 258 return fValue; 259 } 260 261 264 public XSNamespaceItem getNamespaceItem() { 265 return null; 266 } 267 268 } | Popular Tags |