1 16 17 package org.apache.xerces.impl.xs; 18 19 import org.apache.xerces.xs.XSConstants; 20 import org.apache.xerces.xs.XSNamespaceItem; 21 import org.apache.xerces.xs.XSParticle; 22 import org.apache.xerces.xs.XSTerm; 23 24 33 public class XSParticleDecl implements XSParticle { 34 35 public static final short PARTICLE_EMPTY = 0; 37 public static final short PARTICLE_ELEMENT = 1; 38 public static final short PARTICLE_WILDCARD = 2; 39 public static final short PARTICLE_MODELGROUP = 3; 40 public static final short PARTICLE_ZERO_OR_MORE = 4; 41 public static final short PARTICLE_ZERO_OR_ONE = 5; 42 public static final short PARTICLE_ONE_OR_MORE = 6; 43 44 public short fType = PARTICLE_EMPTY; 46 47 public XSTerm fValue = null; 52 53 public int fMinOccurs = 1; 55 public int fMaxOccurs = 1; 57 58 public XSParticleDecl makeClone() { 60 XSParticleDecl particle = new XSParticleDecl(); 61 particle.fType = fType; 62 particle.fMinOccurs = fMinOccurs; 63 particle.fMaxOccurs = fMaxOccurs; 64 particle.fDescription = fDescription; 65 particle.fValue = fValue; 66 return particle; 67 } 68 69 73 public boolean emptiable() { 74 return minEffectiveTotalRange() == 0; 75 } 76 77 public boolean isEmpty() { 79 if (fType == PARTICLE_EMPTY) 80 return true; 81 if (fType == PARTICLE_ELEMENT || fType == PARTICLE_WILDCARD) 82 return false; 83 84 return ((XSModelGroupImpl)fValue).isEmpty(); 85 } 86 87 94 public int minEffectiveTotalRange() { 95 if (fType == XSParticleDecl.PARTICLE_EMPTY) { 96 return 0; 97 } 98 if (fType == PARTICLE_MODELGROUP) { 99 return ((XSModelGroupImpl)fValue).minEffectiveTotalRange() * fMinOccurs; 100 } 101 return fMinOccurs; 102 } 103 104 public int maxEffectiveTotalRange() { 105 if (fType == XSParticleDecl.PARTICLE_EMPTY) { 106 return 0; 107 } 108 if (fType == PARTICLE_MODELGROUP) { 109 int max = ((XSModelGroupImpl)fValue).maxEffectiveTotalRange(); 110 if (max == SchemaSymbols.OCCURRENCE_UNBOUNDED) 111 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 112 if (max != 0 && fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED) 113 return SchemaSymbols.OCCURRENCE_UNBOUNDED; 114 return max * fMaxOccurs; 115 } 116 return fMaxOccurs; 117 } 118 119 122 private String fDescription = null; 123 public String toString() { 124 if (fDescription == null) { 125 StringBuffer buffer = new StringBuffer (); 126 appendParticle(buffer); 127 if (!(fMinOccurs == 0 && fMaxOccurs == 0 || 128 fMinOccurs == 1 && fMaxOccurs == 1)) { 129 buffer.append("{" + fMinOccurs); 130 if (fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED) 131 buffer.append("-UNBOUNDED"); 132 else if (fMinOccurs != fMaxOccurs) 133 buffer.append("-" + fMaxOccurs); 134 buffer.append("}"); 135 } 136 fDescription = buffer.toString(); 137 } 138 return fDescription; 139 } 140 141 145 void appendParticle(StringBuffer buffer) { 146 switch (fType) { 147 case PARTICLE_EMPTY: 148 buffer.append("EMPTY"); 149 break; 150 case PARTICLE_ELEMENT: 151 buffer.append(fValue.toString()); 152 break; 153 case PARTICLE_WILDCARD: 154 buffer.append('('); 155 buffer.append(fValue.toString()); 156 buffer.append(')'); 157 break; 158 case PARTICLE_MODELGROUP: 159 buffer.append(fValue.toString()); 160 break; 161 } 162 } 163 164 public void reset(){ 165 fType = PARTICLE_EMPTY; 166 fValue = null; 167 fMinOccurs = 1; 168 fMaxOccurs = 1; 169 fDescription = null; 170 } 171 172 175 public short getType() { 176 return XSConstants.PARTICLE; 177 } 178 179 183 public String getName() { 184 return null; 185 } 186 187 192 public String getNamespace() { 193 return null; 194 } 195 196 199 public int getMinOccurs() { 200 return fMinOccurs; 201 } 202 203 206 public boolean getMaxOccursUnbounded() { 207 return fMaxOccurs == SchemaSymbols.OCCURRENCE_UNBOUNDED; 208 } 209 210 213 public int getMaxOccurs() { 214 return fMaxOccurs; 215 } 216 217 220 public XSTerm getTerm() { 221 return fValue; 222 } 223 224 227 public XSNamespaceItem getNamespaceItem() { 228 return null; 229 } 230 231 } | Popular Tags |