xsconstraints.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,481 行 · 第 1/5 页
JAVA
1,481 行
try { // validate the original lexical rep, and set the actual value actualValue = dv.validate(value, context, vinfo); // validate the canonical lexical rep if (vinfo != null) actualValue = dv.validate(vinfo.stringValue(), context, vinfo); } catch (InvalidDatatypeValueException ide) { return null; } return actualValue; } static void reportSchemaError(XMLErrorReporter errorReporter, SimpleLocator loc, String key, Object[] args) { if (loc != null) { errorReporter.reportError(loc, XSMessageFormatter.SCHEMA_DOMAIN, key, args, XMLErrorReporter.SEVERITY_ERROR); } else { errorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN, key, args, XMLErrorReporter.SEVERITY_ERROR); } } /** * used to check the 3 constraints against each complex type * (should be each model group): * Unique Particle Attribution, Particle Derivation (Restriction), * Element Declrations Consistent. */ public static void fullSchemaChecking(XSGrammarBucket grammarBucket, SubstitutionGroupHandler SGHandler, CMBuilder cmBuilder, XMLErrorReporter errorReporter) { // get all grammars, and put all substitution group information // in the substitution group handler SGHandler.reset(); SchemaGrammar[] grammars = grammarBucket.getGrammars(); for (int i = grammars.length-1; i >= 0; i--) { SGHandler.addSubstitutionGroup(grammars[i].getSubstitutionGroups()); } XSParticleDecl fakeDerived = new XSParticleDecl(); XSParticleDecl fakeBase = new XSParticleDecl(); fakeDerived.fType = XSParticleDecl.PARTICLE_MODELGROUP; fakeBase.fType = XSParticleDecl.PARTICLE_MODELGROUP; // before worrying about complexTypes, let's get // groups redefined by restriction out of the way. for (int g = grammars.length-1; g >= 0; g--) { XSGroupDecl [] redefinedGroups = grammars[g].getRedefinedGroupDecls(); SimpleLocator [] rgLocators = grammars[g].getRGLocators(); for(int i=0; i<redefinedGroups.length; ) { XSGroupDecl derivedGrp = redefinedGroups[i++]; XSModelGroupImpl derivedMG = derivedGrp.fModelGroup; XSGroupDecl baseGrp = redefinedGroups[i++]; XSModelGroupImpl baseMG = baseGrp.fModelGroup; if(baseMG == null) { if(derivedMG != null) { // can't be a restriction! reportSchemaError(errorReporter, rgLocators[i/2-1], "src-redefine.6.2.2", new Object[]{derivedGrp.fName, "rcase-Recurse.2"}); } } else { fakeDerived.fValue = derivedMG; fakeBase.fValue = baseMG; try { particleValidRestriction(fakeDerived, SGHandler, fakeBase, SGHandler); } catch (XMLSchemaException e) { String key = e.getKey(); reportSchemaError(errorReporter, rgLocators[i/2-1], key, e.getArgs()); reportSchemaError(errorReporter, rgLocators[i/2-1], "src-redefine.6.2.2", new Object[]{derivedGrp.fName, key}); } } } } // for each complex type, check the 3 constraints. // types need to be checked XSComplexTypeDecl[] types; SimpleLocator [] ctLocators; // to hold the errors // REVISIT: do we want to report all errors? or just one? //XMLSchemaError1D errors = new XMLSchemaError1D(); // whether need to check this type again; // whether only do UPA checking boolean further, fullChecked; // if do all checkings, how many need to be checked again. int keepType; // i: grammar; j: type; k: error // for all grammars SymbolHash elemTable = new SymbolHash(); for (int i = grammars.length-1, j, k; i >= 0; i--) { // get whether to skip EDC, and types need to be checked keepType = 0; fullChecked = grammars[i].fFullChecked; types = grammars[i].getUncheckedComplexTypeDecls(); ctLocators = grammars[i].getUncheckedCTLocators(); // for each type for (j = types.length-1; j >= 0; j--) { // if we've already full-checked this grammar, then // skip the EDC constraint if (!fullChecked) { // 1. Element Decl Consistent if (types[j].fParticle!=null) { elemTable.clear(); try { checkElementDeclsConsistent(types[j], types[j].fParticle, elemTable, SGHandler); } catch (XMLSchemaException e) { reportSchemaError(errorReporter, ctLocators[j], e.getKey(), e.getArgs()); } } } // 2. Particle Derivation if (types[j].fBaseType != null && types[j].fBaseType != SchemaGrammar.fAnyType && types[j].fDerivedBy == XSConstants.DERIVATION_RESTRICTION && (types[j].fBaseType instanceof XSComplexTypeDecl)) { XSParticleDecl derivedParticle=types[j].fParticle; XSParticleDecl baseParticle= ((XSComplexTypeDecl)(types[j].fBaseType)).fParticle; if (derivedParticle==null && (!(baseParticle==null || baseParticle.emptiable()))) { reportSchemaError(errorReporter,ctLocators[j], "derivation-ok-restriction.5.3.2", new Object[]{types[j].fName, types[j].fBaseType.getName()}); } else if (derivedParticle!=null && baseParticle!=null) try { particleValidRestriction(types[j].fParticle, SGHandler, ((XSComplexTypeDecl)(types[j].fBaseType)).fParticle, SGHandler); } catch (XMLSchemaException e) { reportSchemaError(errorReporter, ctLocators[j], e.getKey(), e.getArgs()); reportSchemaError(errorReporter, ctLocators[j], "derivation-ok-restriction.5.4.2", new Object[]{types[j].fName}); } } // 3. UPA // get the content model and check UPA XSCMValidator cm = types[j].getContentModel(cmBuilder); further = false; if (cm != null) { try { further = cm.checkUniqueParticleAttribution(SGHandler); } catch (XMLSchemaException e) { reportSchemaError(errorReporter, ctLocators[j], e.getKey(), e.getArgs()); } } // now report all errors // REVISIT: do we want to report all errors? or just one? /*for (k = errors.getErrorCodeNum()-1; k >= 0; k--) { reportSchemaError(errorReporter, ctLocators[j], errors.getErrorCode(k), errors.getArgs(k)); }*/ // if we are doing all checkings, and this one needs further // checking, store it in the type array. if (!fullChecked && further) types[keepType++] = types[j]; // clear errors for the next type. // REVISIT: do we want to report all errors? or just one? //errors.clear(); } // we've done with the types in this grammar. if we are checking // all constraints, need to trim type array to a proper size: // only contain those need further checking. // and mark this grammar that it only needs UPA checking. if (!fullChecked) { grammars[i].setUncheckedTypeNum(keepType); grammars[i].fFullChecked = true; } } } /* Check that a given particle is a valid restriction of a base particle. */ public static void checkElementDeclsConsistent(XSComplexTypeDecl type, XSParticleDecl particle, SymbolHash elemDeclHash, SubstitutionGroupHandler sgHandler) throws XMLSchemaException { // check for elements in the tree with the same name and namespace int pType = particle.fType; if (pType == XSParticleDecl.PARTICLE_WILDCARD) return; if (pType == XSParticleDecl.PARTICLE_ELEMENT) { XSElementDecl elem = (XSElementDecl)(particle.fValue); findElemInTable(type, elem, elemDeclHash); if (elem.fScope == XSConstants.SCOPE_GLOBAL) { // Check for subsitution groups. XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(elem); for (int i = 0; i < subGroup.length; i++) { findElemInTable(type, subGroup[i], elemDeclHash); } } return; } XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue; for (int i = 0; i < group.fParticleCount; i++) checkElementDeclsConsistent(type, group.fParticles[i], elemDeclHash, sgHandler); } public static void findElemInTable(XSComplexTypeDecl type, XSElementDecl elem, SymbolHash elemDeclHash) throws XMLSchemaException { // How can we avoid this concat? LM. String name = elem.fName + "," + elem.fTargetNamespace; XSElementDecl existingElem = null; if ((existingElem = (XSElementDecl)(elemDeclHash.get(name))) == null) { // just add it in elemDeclHash.put(name, elem); } else { // If this is the same check element, we're O.K. if (elem == existingElem) return; if (elem.fType != existingElem.fType) { // Types are not the same throw new XMLSchemaException("cos-element-consistent", new Object[] {type.fName, elem.fName}); } } } /* Check that a given particle is a valid restriction of a base particle. */ private static void particleValidRestriction(XSParticleDecl dParticle, SubstitutionGroupHandler dSGHandler, XSParticleDecl bParticle, SubstitutionGroupHandler bSGHandler) throws XMLSchemaException { particleValidRestriction(dParticle, dSGHandler, bParticle, bSGHandler, true); } private static void particleValidRestriction(XSParticleDecl dParticle, SubstitutionGroupHandler dSGHandler, XSParticleDecl bParticle, SubstitutionGroupHandler bSGHandler, boolean checkWCOccurrence) throws XMLSchemaException { Vector dChildren = null; Vector bChildren = null; int dMinEffectiveTotalRange=OCCURRENCE_UNKNOWN; int dMaxEffectiveTotalRange=OCCURRENCE_UNKNOWN; // Check for empty particles. If either base or derived particle is empty, // (and the other isn't) it's an error. if (dParticle.isEmpty() && !bParticle.emptiable()) { throw new XMLSchemaException("cos-particle-restrict.a", null); } else if (!dParticle.isEmpty() && bParticle.isEmpty()) { throw new XMLSchemaException("cos-particle-restrict.b", null); } // // Do setup prior to invoking the Particle (Restriction) cases. // This involves: // - removing pointless occurrences for groups, and retrieving a vector of
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?