1 57 58 package com.sun.org.apache.xerces.internal.impl.xs; 59 60 import com.sun.org.apache.xerces.internal.impl.dv.ValidatedInfo; 61 import com.sun.org.apache.xerces.internal.impl.xs.identity.IdentityConstraint; 62 import com.sun.org.apache.xerces.internal.xs.ShortList; 63 import com.sun.org.apache.xerces.internal.xs.XSAnnotation; 64 import com.sun.org.apache.xerces.internal.xs.XSComplexTypeDefinition; 65 import com.sun.org.apache.xerces.internal.xs.XSConstants; 66 import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration; 67 import com.sun.org.apache.xerces.internal.xs.XSNamedMap; 68 import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem; 69 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 70 import com.sun.org.apache.xerces.internal.impl.xs.util.XSNamedMapImpl; 71 72 80 public class XSElementDecl implements XSElementDeclaration { 81 82 public final static short SCOPE_ABSENT = 0; 84 public final static short SCOPE_GLOBAL = 1; 85 public final static short SCOPE_LOCAL = 2; 86 87 public String fName = null; 89 public String fTargetNamespace = null; 91 public XSTypeDefinition fType = null; 93 short fMiscFlags = 0; 95 public short fScope = XSConstants.SCOPE_ABSENT; 96 XSComplexTypeDecl fEnclosingCT = null; 98 public short fBlock = XSConstants.DERIVATION_NONE; 100 public short fFinal = XSConstants.DERIVATION_NONE; 102 public XSAnnotationImpl fAnnotation = null; 104 public ValidatedInfo fDefault = null; 106 public XSElementDecl fSubGroup = null; 108 static final int INITIAL_SIZE = 2; 110 int fIDCPos = 0; 111 IdentityConstraint[] fIDConstraints = new IdentityConstraint[INITIAL_SIZE]; 112 113 private static final short CONSTRAINT_MASK = 3; 114 private static final short NILLABLE = 4; 115 private static final short ABSTRACT = 8; 116 117 public void setConstraintType(short constraintType) { 119 fMiscFlags ^= (fMiscFlags & CONSTRAINT_MASK); 121 fMiscFlags |= (constraintType & CONSTRAINT_MASK); 123 } 124 public void setIsNillable() { 125 fMiscFlags |= NILLABLE; 126 } 127 public void setIsAbstract() { 128 fMiscFlags |= ABSTRACT; 129 } 130 public void setIsGlobal() { 131 fScope = SCOPE_GLOBAL; 132 } 133 public void setIsLocal(XSComplexTypeDecl enclosingCT) { 134 fScope = SCOPE_LOCAL; 135 fEnclosingCT = enclosingCT; 136 } 137 138 public void addIDConstraint(IdentityConstraint idc) { 139 if (fIDCPos == fIDConstraints.length) { 140 fIDConstraints = resize(fIDConstraints, fIDCPos*2); 141 } 142 fIDConstraints[fIDCPos++] = idc; 143 } 144 145 public IdentityConstraint[] getIDConstraints() { 146 if (fIDCPos == 0) { 147 return null; 148 } 149 if (fIDCPos < fIDConstraints.length) { 150 fIDConstraints = resize(fIDConstraints, fIDCPos); 151 } 152 return fIDConstraints; 153 } 154 155 static final IdentityConstraint[] resize(IdentityConstraint[] oldArray, int newSize) { 156 IdentityConstraint[] newArray = new IdentityConstraint[newSize]; 157 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 158 return newArray; 159 } 160 161 164 private String fDescription = null; 165 public String toString() { 166 if (fDescription == null) { 167 StringBuffer buffer = new StringBuffer (); 168 buffer.append("\""); 169 if (fTargetNamespace != null) 170 buffer.append(fTargetNamespace); 171 buffer.append("\""); 172 buffer.append(":"); 173 buffer.append(fName); 174 fDescription = buffer.toString(); 175 } 176 return fDescription; 177 } 178 179 182 public int hashCode() { 183 int code = fName.hashCode(); 184 if (fTargetNamespace != null) 185 code = (code<<16)+fTargetNamespace.hashCode(); 186 return code; 187 } 188 189 192 public boolean equals(Object o) { 193 return o == this; 194 } 195 196 199 public void reset(){ 200 201 fName = null; 202 fTargetNamespace = null; 203 fType = null; 204 fMiscFlags = 0; 205 fBlock = XSConstants.DERIVATION_NONE; 206 fFinal = XSConstants.DERIVATION_NONE; 207 fDefault = null; 208 fAnnotation = null; 209 fSubGroup = null; 210 for (int i=0;i<fIDCPos;i++) { 212 fIDConstraints[i] = null; 213 } 214 215 fIDCPos = 0; 216 } 217 218 221 public short getType() { 222 return XSConstants.ELEMENT_DECLARATION; 223 } 224 225 229 public String getName() { 230 return fName; 231 } 232 233 238 public String getNamespace() { 239 return fTargetNamespace; 240 } 241 242 245 public XSTypeDefinition getTypeDefinition() { 246 return fType; 247 } 248 249 256 public short getScope() { 257 return fScope; 258 } 259 260 265 public XSComplexTypeDefinition getEnclosingCTDefinition() { 266 return fEnclosingCT; 267 } 268 269 272 public short getConstraintType() { 273 return (short)(fMiscFlags & CONSTRAINT_MASK); 274 } 275 276 280 public String getConstraintValue() { 281 return getConstraintType() == XSConstants.VC_NONE ? 283 null : 284 fDefault.stringValue(); 285 } 286 287 294 public boolean getNillable() { 295 return ((fMiscFlags & NILLABLE) != 0); 296 } 297 298 301 public XSNamedMap getIdentityConstraints() { 302 return new XSNamedMapImpl(fIDConstraints, fIDCPos); 303 } 304 305 309 public XSElementDeclaration getSubstitutionGroupAffiliation() { 310 return fSubGroup; 311 } 312 313 321 public boolean isSubstitutionGroupExclusion(short exclusion) { 322 return (fFinal & exclusion) != 0; 323 } 324 325 333 public short getSubstitutionGroupExclusions() { 334 return fFinal; 335 } 336 337 345 public boolean isDisallowedSubstitution(short disallowed) { 346 return (fBlock & disallowed) != 0; 347 } 348 349 354 public short getDisallowedSubstitutions() { 355 return fBlock; 356 } 357 358 361 public boolean getAbstract() { 362 return ((fMiscFlags & ABSTRACT) != 0); 363 } 364 365 368 public XSAnnotation getAnnotation() { 369 return fAnnotation; 370 } 371 372 373 376 public XSNamespaceItem getNamespaceItem() { 377 return null; 379 } 380 381 public Object getActualVC() { 382 return fDefault.actualValue; 383 } 384 385 public short getActualVCType() { 386 return fDefault.actualValueType; 387 } 388 389 public ShortList getItemValueTypes() { 390 return fDefault.itemValueTypes; 391 } 392 393 } | Popular Tags |