xsconstraints.java

来自「JAVA 所有包」· Java 代码 · 共 1,445 行 · 第 1/4 页

JAVA
1,445
字号
                // 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) {                      if (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 (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});                      }                  }                  else {                      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       //     non-pointless children       //   - turning top-level elements with substitution groups into CHOICE groups.       //       short dType = dParticle.fType;       //       // Handle pointless groups for the derived particle       //       if (dType == XSParticleDecl.PARTICLE_MODELGROUP) {         dType = ((XSModelGroupImpl)dParticle.fValue).fCompositor;         // Find a group, starting with this particle, with more than 1 child.   There         // may be none, and the particle of interest trivially becomes an element or         // wildcard.         XSParticleDecl dtmp = getNonUnaryGroup(dParticle);         if (dtmp != dParticle) {            // Particle has been replaced.   Retrieve new type info.            dParticle = dtmp;            dType = dParticle.fType;            if (dType == XSParticleDecl.PARTICLE_MODELGROUP)               dType = ((XSModelGroupImpl)dParticle.fValue).fCompositor;         }         // Fill in a vector with the children of the particle, removing any         // pointless model groups in the process.         dChildren = removePointlessChildren(dParticle);       }       int dMinOccurs = dParticle.fMinOccurs;       int dMaxOccurs = dParticle.fMaxOccurs;       //       // For elements which are the heads of substitution groups, treat as CHOICE       //       if (dSGHandler != null && dType == XSParticleDecl.PARTICLE_ELEMENT) {           XSElementDecl dElement = (XSElementDecl)dParticle.fValue;           if (dElement.fScope == XSConstants.SCOPE_GLOBAL) {             // Check for subsitution groups.   Treat any element that has a             // subsitution group as a choice.   Fill in the children vector with the             // members of the substitution group             XSElementDecl[] subGroup = dSGHandler.getSubstitutionGroup(dElement);             if (subGroup.length >0 ) {                // Now, set the type to be CHOICE.  The "group" will have the same                // occurrence information as the original particle.                dType = XSModelGroupImpl.MODELGROUP_CHOICE;                dMinEffectiveTotalRange = dMinOccurs;                dMaxEffectiveTotalRange = dMaxOccurs;                // Fill in the vector of children                dChildren = new Vector(subGroup.length+1);                for (int i = 0; i < subGroup.length; i++) {                  addElementToParticleVector(dChildren, subGroup[i]);                }                addElementToParticleVector(dChildren, dElement);                // Set the handler to null, to indicate that we've finished handling                // substitution groups for this particle.                dSGHandler = null;             }           }       }       short bType = bParticle.fType;       //       // Handle pointless groups for the base particle       //       if (bType == XSParticleDecl.PARTICLE_MODELGROUP) {         bType = ((XSModelGroupImpl)bParticle.fValue).fCompositor;         // Find a group, starting with this particle, with more than 1 child.   There         // may be none, and the particle of interest trivially becomes an element or         // wildcard.         XSParticleDecl btmp = getNonUnaryGroup(bParticle);         if (btmp != bParticle) {            // Particle has been replaced.   Retrieve new type info.            bParticle = btmp;            bType = bParticle.fType;            if (bType == XSParticleDecl.PARTICLE_MODELGROUP)               bType = ((XSModelGroupImpl)bParticle.fValue).fCompositor;         }         // Fill in a vector with the children of the particle, removing any         // pointless model groups in the process.         bChildren = removePointlessChildren(bParticle);       }       int bMinOccurs = bParticle.fMinOccurs;       int bMaxOccurs = bParticle.fMaxOccurs;       if (bSGHandler != null && bType == XSParticleDecl.PARTICLE_ELEMENT) {           XSElementDecl bElement = (XSElementDecl)bParticle.fValue;           if (bElement.fScope == XSConstants.SCOPE_GLOBAL) {             // Check for subsitution groups.   Treat any element that has a             // subsitution group as a choice.   Fill in the children vector with the             // members of the substitution group             XSElementDecl[] bsubGroup = bSGHandler.getSubstitutionGroup(bElement);             if (bsubGroup.length >0 ) {                // Now, set the type to be CHOICE                bType = XSModelGroupImpl.MODELGROUP_CHOICE;                bChildren = new Vector(bsubGroup.length+1);                for (int i = 0; i < bsubGroup.length; i++) {                  addElementToParticleVector(bChildren, bsubGroup[i]);                }                addElementToParticleVector(bChildren, bElement);                // Set the handler to null, to indicate that we've finished handling                // substitution groups for this particle.                bSGHandler = null;             }           }       }       //       // O.K. - Figure out which particle derivation rule applies and call it       //       switch (dType) {         case XSParticleDecl.PARTICLE_ELEMENT:         {            switch (bType) {              // Elt:Elt NameAndTypeOK              case XSParticleDecl.PARTICLE_ELEMENT:              {                 checkNameAndTypeOK((XSElementDecl)dParticle.fValue,dMinOccurs,dMaxOccurs,                                    (XSElementDecl)bParticle.fValue,bMinOccurs,bMaxOccurs);                 return;              }              // Elt:Any NSCompat              case XSParticleDecl.PARTICLE_WILDCARD:              {                 checkNSCompat((XSElementDecl)dParticle.fValue,dMinOccurs,dMaxOccurs,                               (XSWildcardDecl)bParticle.fValue,bMinOccurs,bMaxOccurs,                               checkWCOccurrence);                 return;              }              // Elt:All RecurseAsIfGroup              case XSModelGroupImpl.MODELGROUP_CHOICE:              {                 // Treat the element as if it were in a group of the same type                 // as the base Particle                 dChildren = new Vector();                 dChildren.addElement(dParticle);                 checkRecurseLax(dChildren, 1, 1, dSGHandler,                                 bChildren, bMinOccurs, bMaxOccurs, bSGHandler);                 return;              }              case XSModelGroupImpl.MODELGROUP_SEQUENCE:              case XSModelGroupImpl.MODELGROUP_ALL:              {                 // Treat the element as if it were in a group of the same type                 // as the base Particle                 dChildren = new Vector();                 dChildren.addElement(dParticle);                 checkRecurse(dChildren, 1, 1, dSGHandler,                              bChildren, bMinOccurs, bMaxOccurs, bSGHandler);                 return;              }              default:              {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?