1 16 17 package org.apache.xerces.impl.xs; 18 19 import org.apache.xerces.impl.dv.ValidatedInfo; 20 import org.apache.xerces.xs.XSAnnotation; 21 import org.apache.xerces.xs.XSAttributeGroupDefinition; 22 import org.apache.xerces.xs.XSAttributeUse; 23 import org.apache.xerces.xs.XSConstants; 24 import org.apache.xerces.xs.XSNamespaceItem; 25 import org.apache.xerces.xs.XSObjectList; 26 import org.apache.xerces.xs.XSWildcard; 27 import org.apache.xerces.impl.xs.util.XSObjectListImpl; 28 29 40 public class XSAttributeGroupDecl implements XSAttributeGroupDefinition { 41 42 public String fName = null; 44 public String fTargetNamespace = null; 46 int fAttrUseNum = 0; 48 private static final int INITIAL_SIZE = 5; 50 XSAttributeUseImpl[] fAttributeUses = new XSAttributeUseImpl[INITIAL_SIZE]; 51 public XSWildcardDecl fAttributeWC = null; 53 public String fIDAttrName = null; 55 56 public XSAnnotationImpl fAnnotation; 58 59 protected XSObjectListImpl fAttrUses = null; 60 61 public String addAttributeUse(XSAttributeUseImpl attrUse) { 66 67 if (fAttrUseNum == fAttributeUses.length) { 68 fAttributeUses = resize(fAttributeUses, fAttrUseNum*2); 69 } 70 fAttributeUses[fAttrUseNum++] = attrUse; 71 if (attrUse.fUse == SchemaSymbols.USE_PROHIBITED) 74 return null; 75 76 if (attrUse.fAttrDecl.fType.isIDType()) { 77 if (fIDAttrName == null) 79 fIDAttrName = attrUse.fAttrDecl.fName; 80 else 81 return fIDAttrName; 82 } 83 84 return null; 85 } 86 87 public XSAttributeUse getAttributeUse(String namespace, String name) { 88 for (int i=0; i<fAttrUseNum; i++) { 89 if ( (fAttributeUses[i].fAttrDecl.fTargetNamespace == namespace) && 90 (fAttributeUses[i].fAttrDecl.fName == name) ) 91 return fAttributeUses[i]; 92 } 93 94 return null; 95 } 96 97 public void removeProhibitedAttrs() { 98 if (fAttrUseNum == 0) return; 99 int pCount = 0; 100 XSAttributeUseImpl[] pUses = new XSAttributeUseImpl[fAttrUseNum]; 101 for (int i = 0; i < fAttrUseNum; i++) { 102 if (fAttributeUses[i].fUse == SchemaSymbols.USE_PROHIBITED) { 103 pCount++; 104 pUses[fAttrUseNum-pCount] = fAttributeUses[i]; 108 } 109 } 110 111 int newCount = 0; 112 if (pCount > 0) { 113 OUTER: for (int i = 0; i < fAttrUseNum; i++) { 114 if (fAttributeUses[i].fUse == SchemaSymbols.USE_PROHIBITED) 115 continue; 116 for (int j = 1; j <= pCount; j++) { 117 if (fAttributeUses[i].fAttrDecl.fName == pUses[fAttrUseNum-pCount].fAttrDecl.fName && 118 fAttributeUses[i].fAttrDecl.fTargetNamespace == pUses[fAttrUseNum-pCount].fAttrDecl.fTargetNamespace) { 119 continue OUTER; 120 } 121 } 122 pUses[newCount++] = fAttributeUses[i]; 123 } 124 fAttributeUses = pUses; 125 fAttrUseNum = newCount; 126 } 127 } 128 129 140 public Object [] validRestrictionOf(String typeName, XSAttributeGroupDecl baseGroup) { 141 142 Object [] errorArgs = null; 143 XSAttributeUseImpl attrUse = null; 144 XSAttributeDecl attrDecl = null; 145 XSAttributeUseImpl baseAttrUse = null; 146 XSAttributeDecl baseAttrDecl = null; 147 148 for (int i=0; i<fAttrUseNum; i++) { 149 150 attrUse = fAttributeUses[i]; 151 attrDecl = attrUse.fAttrDecl; 152 153 baseAttrUse = (XSAttributeUseImpl)baseGroup.getAttributeUse(attrDecl.fTargetNamespace,attrDecl.fName); 155 if (baseAttrUse != null) { 156 160 if (baseAttrUse.getRequired() && !attrUse.getRequired()) { 161 errorArgs = new Object []{typeName, attrDecl.fName, 162 attrUse.fUse == SchemaSymbols.USE_OPTIONAL ? SchemaSymbols.ATTVAL_OPTIONAL : SchemaSymbols.ATTVAL_PROHIBITED, 163 "derivation-ok-restriction.2.1.1"}; 164 return errorArgs; 165 } 166 167 if (attrUse.fUse == SchemaSymbols.USE_PROHIBITED) { 170 continue; 171 } 172 173 baseAttrDecl = baseAttrUse.fAttrDecl; 174 if (! XSConstraints.checkSimpleDerivationOk(attrDecl.fType, 178 baseAttrDecl.fType, 179 baseAttrDecl.fType.getFinal()) ) { 180 errorArgs = new Object []{typeName, attrDecl.fName, attrDecl.fType.getName(), 181 baseAttrDecl.fType.getName(), "derivation-ok-restriction.2.1.2"}; 182 return errorArgs; 183 } 184 185 186 int baseConsType=baseAttrUse.fConstraintType!=XSConstants.VC_NONE? 190 baseAttrUse.fConstraintType:baseAttrDecl.getConstraintType(); 191 int thisConstType = attrUse.fConstraintType!=XSConstants.VC_NONE? 192 attrUse.fConstraintType:attrDecl.getConstraintType(); 193 194 if (baseConsType == XSConstants.VC_FIXED) { 195 196 if (thisConstType != XSConstants.VC_FIXED) { 197 errorArgs = new Object []{typeName, attrDecl.fName, 198 "derivation-ok-restriction.2.1.3.a"}; 199 return errorArgs; 200 } else { 201 ValidatedInfo baseFixedValue=(baseAttrUse.fDefault!=null ? 203 baseAttrUse.fDefault: baseAttrDecl.fDefault); 204 ValidatedInfo thisFixedValue=(attrUse.fDefault!=null ? 205 attrUse.fDefault: attrDecl.fDefault); 206 if (!baseFixedValue.actualValue.equals(thisFixedValue.actualValue)) { 207 errorArgs = new Object []{typeName, attrDecl.fName, thisFixedValue.stringValue(), 208 baseFixedValue.stringValue(), "derivation-ok-restriction.2.1.3.b"}; 209 return errorArgs; 210 } 211 212 } 213 214 } 215 } else { 216 218 if (baseGroup.fAttributeWC == null) { 222 errorArgs = new Object []{typeName, attrDecl.fName, 223 "derivation-ok-restriction.2.2.a"}; 224 return errorArgs; 225 } 226 else if (!baseGroup.fAttributeWC.allowNamespace(attrDecl.fTargetNamespace)) { 227 errorArgs = new Object []{typeName, attrDecl.fName, 228 attrDecl.fTargetNamespace==null?"":attrDecl.fTargetNamespace, 229 "derivation-ok-restriction.2.2.b"}; 230 return errorArgs; 231 } 232 } 233 } 234 235 for (int i=0; i<baseGroup.fAttrUseNum; i++) { 241 242 baseAttrUse = baseGroup.fAttributeUses[i]; 243 244 if (baseAttrUse.fUse == SchemaSymbols.USE_REQUIRED) { 245 246 baseAttrDecl = baseAttrUse.fAttrDecl; 247 if (getAttributeUse(baseAttrDecl.fTargetNamespace,baseAttrDecl.fName) == null) { 249 errorArgs = new Object []{typeName, baseAttrUse.fAttrDecl.fName, 250 "derivation-ok-restriction.3"}; 251 return errorArgs; 252 } 253 } 254 } 255 256 257 if (fAttributeWC != null) { 262 if (baseGroup.fAttributeWC == null) { 263 errorArgs = new Object []{typeName, "derivation-ok-restriction.4.1"}; 264 return errorArgs; 265 } 266 if (! fAttributeWC.isSubsetOf(baseGroup.fAttributeWC)) { 267 errorArgs = new Object []{typeName, "derivation-ok-restriction.4.2"}; 268 return errorArgs; 269 } 270 if (fAttributeWC.weakerProcessContents(baseGroup.fAttributeWC)) { 271 errorArgs = new Object []{typeName, 272 fAttributeWC.getProcessContentsAsString(), 273 baseGroup.fAttributeWC.getProcessContentsAsString(), 274 "derivation-ok-restriction.4.3"}; 275 return errorArgs; 276 } 277 } 278 279 return null; 280 281 } 282 283 static final XSAttributeUseImpl[] resize(XSAttributeUseImpl[] oldArray, int newSize) { 284 XSAttributeUseImpl[] newArray = new XSAttributeUseImpl[newSize]; 285 System.arraycopy(oldArray, 0, newArray, 0, Math.min(oldArray.length, newSize)); 286 return newArray; 287 } 288 289 public void reset(){ 291 fName = null; 292 fTargetNamespace = null; 293 for (int i=0;i<fAttrUseNum;i++) { 295 fAttributeUses[i] = null; 296 } 297 fAttrUseNum = 0; 298 fAttributeWC = null; 299 fAnnotation = null; 300 fIDAttrName = null; 301 302 } 303 304 307 public short getType() { 308 return XSConstants.ATTRIBUTE_GROUP; 309 } 310 311 315 public String getName() { 316 return fName; 317 } 318 319 324 public String getNamespace() { 325 return fTargetNamespace; 326 } 327 328 331 public XSObjectList getAttributeUses() { 332 if (fAttrUses == null){ 333 fAttrUses = new XSObjectListImpl(fAttributeUses, fAttrUseNum); 334 } 335 return fAttrUses; 336 } 337 338 341 public XSWildcard getAttributeWildcard() { 342 return fAttributeWC; 343 } 344 345 348 public XSAnnotation getAnnotation() { 349 return fAnnotation; 350 } 351 352 355 public XSNamespaceItem getNamespaceItem() { 356 return null; 358 } 359 360 } | Popular Tags |