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.xs.XSAnnotation; 62 import com.sun.org.apache.xerces.internal.xs.XSAttributeGroupDefinition; 63 import com.sun.org.apache.xerces.internal.xs.XSAttributeUse; 64 import com.sun.org.apache.xerces.internal.xs.XSConstants; 65 import com.sun.org.apache.xerces.internal.xs.XSNamespaceItem; 66 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 67 import com.sun.org.apache.xerces.internal.xs.XSWildcard; 68 import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl; 69 70 79 public class XSAttributeGroupDecl implements XSAttributeGroupDefinition { 80 81 public String fName = null; 83 public String fTargetNamespace = null; 85 int fAttrUseNum = 0; 87 private static final int INITIAL_SIZE = 5; 89 XSAttributeUseImpl[] fAttributeUses = new XSAttributeUseImpl[INITIAL_SIZE]; 90 public XSWildcardDecl fAttributeWC = null; 92 public String fIDAttrName = null; 94 95 public XSAnnotationImpl fAnnotation; 97 98 protected XSObjectListImpl fAttrUses = null; 99 100 public String addAttributeUse(XSAttributeUseImpl attrUse) { 105 106 if (fAttrUseNum == fAttributeUses.length) { 107 fAttributeUses = resize(fAttributeUses, fAttrUseNum*2); 108 } 109 fAttributeUses[fAttrUseNum++] = attrUse; 110 if (attrUse.fUse == SchemaSymbols.USE_PROHIBITED) 113 return null; 114 115 if (attrUse.fAttrDecl.fType.isIDType()) { 116 if (fIDAttrName == null) 118 fIDAttrName = attrUse.fAttrDecl.fName; 119 else 120 return fIDAttrName; 121 } 122 123 return null; 124 } 125 126 public XSAttributeUse getAttributeUse(String namespace, String name) { 127 for (int i=0; i<fAttrUseNum; i++) { 128 if ( (fAttributeUses[i].fAttrDecl.fTargetNamespace == namespace) && 129 (fAttributeUses[i].fAttrDecl.fName == name) ) 130 return fAttributeUses[i]; 131 } 132 133 return null; 134 } 135 136 public void removeProhibitedAttrs() { 137 if (fAttrUseNum == 0) return; 138 int pCount = 0; 139 XSAttributeUseImpl[] pUses = new XSAttributeUseImpl[fAttrUseNum]; 140 for (int i = 0; i < fAttrUseNum; i++) { 141 if (fAttributeUses[i].fUse == SchemaSymbols.USE_PROHIBITED) { 142 pCount++; 143 pUses[fAttrUseNum-pCount] = fAttributeUses[i]; 147 } 148 } 149 150 int newCount = 0; 151 if (pCount > 0) { 152 OUTER: for (int i = 0; i < fAttrUseNum; i++) { 153 if (fAttributeUses[i].fUse == SchemaSymbols.USE_PROHIBITED) 154 continue; 155 for (int j = 1; j <= pCount; j++) { 156 if (fAttributeUses[i].fAttrDecl.fName == pUses[fAttrUseNum-pCount].fAttrDecl.fName && 157 fAttributeUses[i].fAttrDecl.fTargetNamespace == pUses[fAttrUseNum-pCount].fAttrDecl.fTargetNamespace) { 158 continue OUTER; 159 } 160 } 161 pUses[newCount++] = fAttributeUses[i]; 162 } 163 fAttributeUses = pUses; 164 fAttrUseNum = newCount; 165 } 166 } 167 168 179 public Object [] validRestrictionOf(String typeName, XSAttributeGroupDecl baseGroup) { 180 181 Object [] errorArgs = null; 182 XSAttributeUseImpl attrUse = null; 183 XSAttributeDecl attrDecl = null; 184 XSAttributeUseImpl baseAttrUse = null; 185 XSAttributeDecl baseAttrDecl = null; 186 187 for (int i=0; i<fAttrUseNum; i++) { 188 189 attrUse = fAttributeUses[i]; 190 attrDecl = attrUse.fAttrDecl; 191 192 baseAttrUse = (XSAttributeUseImpl)baseGroup.getAttributeUse(attrDecl.fTargetNamespace,attrDecl.fName); 194 if (baseAttrUse != null) { 195 199 if (baseAttrUse.getRequired() && !attrUse.getRequired()) { 200 errorArgs = new Object []{typeName, attrDecl.fName, 201 attrUse.fUse == SchemaSymbols.USE_OPTIONAL ? SchemaSymbols.ATTVAL_OPTIONAL : SchemaSymbols.ATTVAL_PROHIBITED, 202 "derivation-ok-restriction.2.1.1"}; 203 return errorArgs; 204 } 205 206 if (attrUse.fUse == SchemaSymbols.USE_PROHIBITED) { 209 continue; 210 } 211 212 baseAttrDecl = baseAttrUse.fAttrDecl; 213 if (! XSConstraints.checkSimpleDerivationOk(attrDecl.fType, 217 baseAttrDecl.fType, 218 baseAttrDecl.fType.getFinal()) ) { 219 errorArgs = new Object []{typeName, attrDecl.fName, attrDecl.fType.getName(), 220 baseAttrDecl.fType.getName(), "derivation-ok-restriction.2.1.2"}; 221 return errorArgs; 222 } 223 224 225 int baseConsType=baseAttrUse.fConstraintType!=XSConstants.VC_NONE? 229 baseAttrUse.fConstraintType:baseAttrDecl.getConstraintType(); 230 int thisConstType = attrUse.fConstraintType!=XSConstants.VC_NONE? 231 attrUse.fConstraintType:attrDecl.getConstraintType(); 232 233 if (baseConsType == XSConstants.VC_FIXED) { 234 235 if (thisConstType != XSConstants.VC_FIXED) { 236 errorArgs = new Object []{typeName, attrDecl.fName, 237 "derivation-ok-restriction.2.1.3.a"}; 238 return errorArgs; 239 } else { 240 ValidatedInfo baseFixedValue=(baseAttrUse.fDefault!=null ? 242 baseAttrUse.fDefault: baseAttrDecl.fDefault); 243 ValidatedInfo thisFixedValue=(attrUse.fDefault!=null ? 244 attrUse.fDefault: attrDecl.fDefault); 245 if (!baseFixedValue.actualValue.equals(thisFixedValue.actualValue)) { 246 errorArgs = new Object []{typeName, attrDecl.fName, thisFixedValue.stringValue(), 247 baseFixedValue.stringValue(), "derivation-ok-restriction.2.1.3.b"}; 248 return errorArgs; 249 } 250 251 } 252 253 } 254 } else { 255 257 if (baseGroup.fAttributeWC == null) { 261 errorArgs = new Object []{typeName, attrDecl.fName, 262 "derivation-ok-restriction.2.2.a"}; 263 return errorArgs; 264 } 265 else if (!baseGroup.fAttributeWC.allowNamespace(attrDecl.fTargetNamespace)) { 266 errorArgs = new Object []{typeName, attrDecl.fName, 267 attrDecl.fTargetNamespace==null?"":attrDecl.fTargetNamespace, 268 "derivation-ok-restriction.2.2.b"}; 269 return errorArgs; 270 } 271 } 272 } 273 274 for (int i=0; i<baseGroup.fAttrUseNum; i++) { 280 281 baseAttrUse = baseGroup.fAttributeUses[i]; 282 283 if (baseAttrUse.fUse == SchemaSymbols.USE_REQUIRED) { 284 285 baseAttrDecl = baseAttrUse.fAttrDecl; 286 if (getAttributeUse(baseAttrDecl.fTargetNamespace,baseAttrDecl.fName) == null) { 288 errorArgs = new Object []{typeName, baseAttrUse.fAttrDecl.fName, 289 "derivation-ok-restriction.3"}; 290 return errorArgs; 291 } 292 } 293 } 294 295 296 if (fAttributeWC != null) { 301 if (baseGroup.fAttributeWC == null) { 302 errorArgs = new Object []{typeName, "derivation-ok-restriction.4.1"}; 303 return errorArgs; 304 } 305 if (! fAttributeWC.isSubsetOf(baseGroup.fAttributeWC)) { 306 errorArgs = new Object []{typeName, "derivation-ok-restriction.4.2"}; 307 return errorArgs; 308 } 309 if (fAttributeWC.weakerProcessContents(baseGroup.fAttributeWC)) { 310 errorArgs = new Object []{typeName, 311 fAttributeWC.getProcessContentsAsString(), 312 baseGroup.fAttributeWC.getProcessContentsAsString(), 313 "derivation-ok-restriction.4.3"}; 314 return errorArgs; 315 } 316 } 317 318 return null; 319 320 } 321 322 static final XSAttributeUseImpl[] resize(XSAttributeUseImpl[] oldArray, int newSize) { 323 XSAttributeUseImpl[] newArray = new XSAttributeUseImpl[newSize]; 324 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 325 return newArray; 326 } 327 328 public void reset(){ 330 fName = null; 331 fTargetNamespace = null; 332 for (int i=0;i<fAttrUseNum;i++) { 334 fAttributeUses[i] = null; 335 } 336 fAttrUseNum = 0; 337 fAttributeWC = null; 338 fAnnotation = null; 339 fIDAttrName = null; 340 341 } 342 343 346 public short getType() { 347 return XSConstants.ATTRIBUTE_GROUP; 348 } 349 350 354 public String getName() { 355 return fName; 356 } 357 358 363 public String getNamespace() { 364 return fTargetNamespace; 365 } 366 367 370 public XSObjectList getAttributeUses() { 371 if (fAttrUses == null){ 372 fAttrUses = new XSObjectListImpl(fAttributeUses, fAttrUseNum); 373 } 374 return fAttrUses; 375 } 376 377 380 public XSWildcard getAttributeWildcard() { 381 return fAttributeWC; 382 } 383 384 387 public XSAnnotation getAnnotation() { 388 return fAnnotation; 389 } 390 391 394 public XSNamespaceItem getNamespaceItem() { 395 return null; 397 } 398 399 } | Popular Tags |