1 16 17 package org.apache.xerces.impl.xs; 18 19 import org.apache.xerces.impl.dv.ValidatedInfo; 20 import org.apache.xerces.impl.xs.identity.IdentityConstraint; 21 import org.apache.xerces.xs.ShortList; 22 import org.apache.xerces.xs.XSAnnotation; 23 import org.apache.xerces.xs.XSComplexTypeDefinition; 24 import org.apache.xerces.xs.XSConstants; 25 import org.apache.xerces.xs.XSElementDeclaration; 26 import org.apache.xerces.xs.XSNamedMap; 27 import org.apache.xerces.xs.XSNamespaceItem; 28 import org.apache.xerces.xs.XSTypeDefinition; 29 import org.apache.xerces.impl.xs.util.XSNamedMapImpl; 30 31 41 public class XSElementDecl implements XSElementDeclaration { 42 43 public final static short SCOPE_ABSENT = 0; 45 public final static short SCOPE_GLOBAL = 1; 46 public final static short SCOPE_LOCAL = 2; 47 48 public String fName = null; 50 public String fTargetNamespace = null; 52 public XSTypeDefinition fType = null; 54 short fMiscFlags = 0; 56 public short fScope = XSConstants.SCOPE_ABSENT; 57 XSComplexTypeDecl fEnclosingCT = null; 59 public short fBlock = XSConstants.DERIVATION_NONE; 61 public short fFinal = XSConstants.DERIVATION_NONE; 63 public XSAnnotationImpl fAnnotation = null; 65 public ValidatedInfo fDefault = null; 67 public XSElementDecl fSubGroup = null; 69 static final int INITIAL_SIZE = 2; 71 int fIDCPos = 0; 72 IdentityConstraint[] fIDConstraints = new IdentityConstraint[INITIAL_SIZE]; 73 74 private static final short CONSTRAINT_MASK = 3; 75 private static final short NILLABLE = 4; 76 private static final short ABSTRACT = 8; 77 78 public void setConstraintType(short constraintType) { 80 fMiscFlags ^= (fMiscFlags & CONSTRAINT_MASK); 82 fMiscFlags |= (constraintType & CONSTRAINT_MASK); 84 } 85 public void setIsNillable() { 86 fMiscFlags |= NILLABLE; 87 } 88 public void setIsAbstract() { 89 fMiscFlags |= ABSTRACT; 90 } 91 public void setIsGlobal() { 92 fScope = SCOPE_GLOBAL; 93 } 94 public void setIsLocal(XSComplexTypeDecl enclosingCT) { 95 fScope = SCOPE_LOCAL; 96 fEnclosingCT = enclosingCT; 97 } 98 99 public void addIDConstraint(IdentityConstraint idc) { 100 if (fIDCPos == fIDConstraints.length) { 101 fIDConstraints = resize(fIDConstraints, fIDCPos*2); 102 } 103 fIDConstraints[fIDCPos++] = idc; 104 } 105 106 public IdentityConstraint[] getIDConstraints() { 107 if (fIDCPos == 0) { 108 return null; 109 } 110 if (fIDCPos < fIDConstraints.length) { 111 fIDConstraints = resize(fIDConstraints, fIDCPos); 112 } 113 return fIDConstraints; 114 } 115 116 static final IdentityConstraint[] resize(IdentityConstraint[] oldArray, int newSize) { 117 IdentityConstraint[] newArray = new IdentityConstraint[newSize]; 118 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 119 return newArray; 120 } 121 122 125 private String fDescription = null; 126 public String toString() { 127 if (fDescription == null) { 128 if (fTargetNamespace != null) { 129 StringBuffer buffer = new StringBuffer ( 130 fTargetNamespace.length() + 131 ((fName != null) ? fName.length() : 4) + 3); 132 buffer.append('"'); 133 buffer.append(fTargetNamespace); 134 buffer.append('"'); 135 buffer.append(':'); 136 buffer.append(fName); 137 fDescription = buffer.toString(); 138 } 139 else { 140 fDescription = fName; 141 } 142 } 143 return fDescription; 144 } 145 146 149 public int hashCode() { 150 int code = fName.hashCode(); 151 if (fTargetNamespace != null) 152 code = (code<<16)+fTargetNamespace.hashCode(); 153 return code; 154 } 155 156 159 public boolean equals(Object o) { 160 return o == this; 161 } 162 163 166 public void reset(){ 167 168 fName = null; 169 fTargetNamespace = null; 170 fType = null; 171 fMiscFlags = 0; 172 fBlock = XSConstants.DERIVATION_NONE; 173 fFinal = XSConstants.DERIVATION_NONE; 174 fDefault = null; 175 fAnnotation = null; 176 fSubGroup = null; 177 for (int i=0;i<fIDCPos;i++) { 179 fIDConstraints[i] = null; 180 } 181 182 fIDCPos = 0; 183 } 184 185 188 public short getType() { 189 return XSConstants.ELEMENT_DECLARATION; 190 } 191 192 196 public String getName() { 197 return fName; 198 } 199 200 205 public String getNamespace() { 206 return fTargetNamespace; 207 } 208 209 212 public XSTypeDefinition getTypeDefinition() { 213 return fType; 214 } 215 216 223 public short getScope() { 224 return fScope; 225 } 226 227 232 public XSComplexTypeDefinition getEnclosingCTDefinition() { 233 return fEnclosingCT; 234 } 235 236 239 public short getConstraintType() { 240 return (short)(fMiscFlags & CONSTRAINT_MASK); 241 } 242 243 247 public String getConstraintValue() { 248 return getConstraintType() == XSConstants.VC_NONE ? 250 null : 251 fDefault.stringValue(); 252 } 253 254 261 public boolean getNillable() { 262 return ((fMiscFlags & NILLABLE) != 0); 263 } 264 265 268 public XSNamedMap getIdentityConstraints() { 269 return new XSNamedMapImpl(fIDConstraints, fIDCPos); 270 } 271 272 276 public XSElementDeclaration getSubstitutionGroupAffiliation() { 277 return fSubGroup; 278 } 279 280 288 public boolean isSubstitutionGroupExclusion(short exclusion) { 289 return (fFinal & exclusion) != 0; 290 } 291 292 300 public short getSubstitutionGroupExclusions() { 301 return fFinal; 302 } 303 304 312 public boolean isDisallowedSubstitution(short disallowed) { 313 return (fBlock & disallowed) != 0; 314 } 315 316 321 public short getDisallowedSubstitutions() { 322 return fBlock; 323 } 324 325 328 public boolean getAbstract() { 329 return ((fMiscFlags & ABSTRACT) != 0); 330 } 331 332 335 public XSAnnotation getAnnotation() { 336 return fAnnotation; 337 } 338 339 340 343 public XSNamespaceItem getNamespaceItem() { 344 return null; 346 } 347 348 public Object getActualVC() { 349 return getConstraintType() == XSConstants.VC_NONE ? 350 null : 351 fDefault.actualValue; 352 } 353 354 public short getActualVCType() { 355 return getConstraintType() == XSConstants.VC_NONE ? 356 XSConstants.UNAVAILABLE_DT : 357 fDefault.actualValueType; 358 } 359 360 public ShortList getItemValueTypes() { 361 return getConstraintType() == XSConstants.VC_NONE ? 362 null : 363 fDefault.itemValueTypes; 364 } 365 366 } | Popular Tags |