1 57 58 package org.enhydra.apache.xerces.validators.common; 59 60 import org.enhydra.apache.xerces.framework.XMLContentSpec; 61 import org.enhydra.apache.xerces.utils.QName; 62 import org.enhydra.apache.xerces.validators.schema.SchemaGrammar; 63 import org.enhydra.apache.xerces.validators.schema.SubstitutionGroupComparator; 64 65 80 public class MixedContentModel 81 implements XMLContentModel { 82 83 84 88 89 private int fCount; 90 91 92 private QName fChildren[]; 93 94 95 private int fChildrenType[]; 96 97 98 private SubstitutionGroupComparator comparator = null; 99 100 104 private boolean fOrdered; 105 106 107 private boolean fDTD; 108 109 113 121 public MixedContentModel(QName childList[], 122 int childListType[], 123 int offset, int length) throws CMException { 124 this(childList, childListType, offset, length, false, false); 125 } 126 127 136 public MixedContentModel(QName childList[], 137 int childListType[], 138 int offset, int length, 139 boolean ordered) throws CMException { 140 this(childList, childListType, offset, length, ordered, false); 141 } 142 143 152 public MixedContentModel(QName childList[], 153 int childListType[], 154 int offset, int length, 155 boolean ordered, 156 boolean dtd) throws CMException { 157 158 fCount = length; 160 fChildren = new QName[fCount]; 161 fChildrenType = new int[fCount]; 162 for (int i = 0; i < fCount; i++) { 163 fChildren[i] = new QName(childList[offset + i]); 164 fChildrenType[i] = childListType[offset + i]; 165 } 166 fOrdered = ordered; 167 168 fDTD = dtd; 169 170 } 172 public void checkUniqueParticleAttribution(SchemaGrammar gram) { 174 for (int i = 0; i < fCount; i++) 176 fChildren[i].uri = gram.getContentSpecOrgUri(fChildren[i].uri); 177 178 } 181 183 187 211 public int validateContent(QName children[], int offset, int length) 212 throws Exception { 213 214 if (fOrdered) { 216 int inIndex = 0; 217 for (int outIndex = 0; outIndex < length; outIndex++) { 218 219 final QName curChild = children[offset + outIndex]; 221 if (curChild.localpart == -1) { 222 continue; 223 } 224 225 int type = fChildrenType[inIndex]; 227 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 228 if (fDTD) { 229 if (fChildren[inIndex].rawname != children[offset + outIndex].rawname) { 230 return outIndex; 231 } 232 } 233 else { 234 if (fChildren[inIndex].uri != children[offset + outIndex].uri && 235 fChildren[inIndex].localpart != children[offset + outIndex].localpart) { 236 return outIndex; 237 } 238 } 239 } 240 241 inIndex++; 243 } 244 } 245 246 else { 248 for (int outIndex = 0; outIndex < length; outIndex++) 249 { 250 final QName curChild = children[offset + outIndex]; 252 253 if (curChild.localpart == -1) 255 continue; 256 257 int inIndex = 0; 259 for (; inIndex < fCount; inIndex++) 260 { 261 int type = fChildrenType[inIndex]; 262 if (type == XMLContentSpec.CONTENTSPECNODE_LEAF) { 263 if (fDTD) { 264 if (curChild.rawname == fChildren[inIndex].rawname) { 265 break; 266 } 267 } 268 else { 269 if (curChild.uri == fChildren[inIndex].uri && 270 curChild.localpart == fChildren[inIndex].localpart) 271 break; 272 } 273 } 274 } 275 276 if (inIndex == fCount) 278 return outIndex; 279 } 280 } 281 282 return -1; 284 285 } 286 287 public int validateContentSpecial(QName children[], int offset, int length) throws Exception { 288 return validateContent(children,offset, length); 290 } 291 292 public void setSubstitutionGroupComparator(SubstitutionGroupComparator comparator) { 293 this.comparator = comparator; 294 } 295 296 324 public int whatCanGoHere(boolean fullyValid 325 , InsertableElementsInfo info) throws Exception 326 { 327 for (int index = info.insertAt; index < info.childCount-1; index++) 333 info.curChildren[index] = info.curChildren[index+1]; 334 info.childCount--; 335 336 final int failedIndex = validateContent(info.curChildren, 0, info.childCount); 341 if ((failedIndex != -1) && (failedIndex < info.insertAt)) 342 return failedIndex; 343 344 info.canHoldPCData = true; 350 info.isValidEOC = true; 351 352 info.resultsCount = fCount; 357 358 if ((info.results == null) || (info.results.length < info.resultsCount)) 359 info.results = new boolean[info.resultsCount]; 360 361 if ((info.possibleChildren == null) 362 || (info.possibleChildren.length < info.resultsCount)) 363 { 364 info.possibleChildren = new QName[info.resultsCount]; 365 for (int i = 0; i < info.possibleChildren.length; i++) { 366 info.possibleChildren[i] = new QName(); 367 } 368 } 369 370 boolean bStatus = true; 381 if (fullyValid && (failedIndex < info.childCount)) 382 bStatus = false; 383 384 for (int index = 0; index < fCount; index++) 390 { 391 info.possibleChildren[index].setValues(fChildren[index]); 392 info.results[index] = bStatus; 393 } 394 395 return -1; 396 } 397 398 399 public ContentLeafNameTypeVector getContentLeafNameTypeVector() { 400 return null; 401 } 402 403 404 } | Popular Tags |