xsconstraints.java

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

JAVA
1,445
字号
                              throws XMLSchemaException {      // check Occurrence ranges      if (checkWCOccurrence && !checkOccurrenceRange(min1,max1,min2,max2)) {        throw new XMLSchemaException("rcase-NSCompat.2",                                  new Object[]{                                    elem.fName,                                    Integer.toString(min1),                                    max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1),                                    Integer.toString(min2),                                    max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)});      }      // check wildcard allows namespace of element      if (!wildcard.allowNamespace(elem.fTargetNamespace))  {        throw new XMLSchemaException("rcase-NSCompat.1",                                  new Object[]{elem.fName,elem.fTargetNamespace});      }    }    private static void checkNSSubset(XSWildcardDecl dWildcard, int min1, int max1,                                      XSWildcardDecl bWildcard, int min2, int max2)                              throws XMLSchemaException {      // check Occurrence ranges      if (!checkOccurrenceRange(min1,max1,min2,max2)) {        throw new XMLSchemaException("rcase-NSSubset.2", new Object[]{                                     Integer.toString(min1),                                     max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1),                                     Integer.toString(min2),                                     max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)});      }      // check wildcard subset      if (!dWildcard.isSubsetOf(bWildcard)) {         throw new XMLSchemaException("rcase-NSSubset.1", null);      }      if (dWildcard.weakerProcessContents(bWildcard)) {          throw new XMLSchemaException("rcase-NSSubset.3",                                       new Object[]{dWildcard.getProcessContentsAsString(),                                                    bWildcard.getProcessContentsAsString()});      }    }    private static void checkNSRecurseCheckCardinality(Vector children, int min1, int max1,                                          SubstitutionGroupHandler dSGHandler,                                          XSParticleDecl wildcard, int min2, int max2,                                          boolean checkWCOccurrence)                                          throws XMLSchemaException {      // check Occurrence ranges      if (checkWCOccurrence && !checkOccurrenceRange(min1,max1,min2,max2)) {         throw new XMLSchemaException("rcase-NSRecurseCheckCardinality.2", new Object[]{                                        Integer.toString(min1),                                        max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1),                                        Integer.toString(min2),                                        max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)});      }      // Check that each member of the group is a valid restriction of the wildcard      int count = children.size();      try {        for (int i = 0; i < count; i++) {           XSParticleDecl particle1 = (XSParticleDecl)children.elementAt(i);           particleValidRestriction(particle1, dSGHandler, wildcard, null, false);        }      }      // REVISIT: should we really just ignore original cause of this error?      //          how can we report it?      catch (XMLSchemaException e) {         throw new XMLSchemaException("rcase-NSRecurseCheckCardinality.1", null);      }    }    private static void checkRecurse(Vector dChildren, int min1, int max1,                                     SubstitutionGroupHandler dSGHandler,                                     Vector bChildren, int min2, int max2,                                     SubstitutionGroupHandler bSGHandler)                                     throws XMLSchemaException {      // check Occurrence ranges      if (!checkOccurrenceRange(min1,max1,min2,max2)) {        throw new XMLSchemaException("rcase-Recurse.1", new Object[]{                                       Integer.toString(min1),                                       max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1),                                       Integer.toString(min2),                                       max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)});      }      int count1= dChildren.size();      int count2= bChildren.size();      int current = 0;      label: for (int i = 0; i<count1; i++) {        XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i);        for (int j = current; j<count2; j++) {           XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j);           current +=1;           try {             particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler);             continue label;           }           catch (XMLSchemaException e) {             if (!particle2.emptiable())                throw new XMLSchemaException("rcase-Recurse.2", null);           }        }        throw new XMLSchemaException("rcase-Recurse.2", null);      }      // Now, see if there are some elements in the base we didn't match up      for (int j=current; j < count2; j++) {        XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j);        if (!particle2.emptiable()) {          throw new XMLSchemaException("rcase-Recurse.2", null);        }      }    }    private static void checkRecurseUnordered(Vector dChildren, int min1, int max1,                                       SubstitutionGroupHandler dSGHandler,                                       Vector bChildren, int min2, int max2,                                       SubstitutionGroupHandler bSGHandler)                                       throws XMLSchemaException {      // check Occurrence ranges      if (!checkOccurrenceRange(min1,max1,min2,max2)) {        throw new XMLSchemaException("rcase-RecurseUnordered.1", new Object[]{                                       Integer.toString(min1),                                       max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1),                                       Integer.toString(min2),                                       max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)});      }      int count1= dChildren.size();      int count2 = bChildren.size();      boolean foundIt[] = new boolean[count2];      label: for (int i = 0; i<count1; i++) {        XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i);        for (int j = 0; j<count2; j++) {           XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j);           try {             particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler);             if (foundIt[j])                throw new XMLSchemaException("rcase-RecurseUnordered.2", null);             else                foundIt[j]=true;             continue label;           }           catch (XMLSchemaException e) {           }        }        // didn't find a match.  Detect an error        throw new XMLSchemaException("rcase-RecurseUnordered.2", null);      }      // Now, see if there are some elements in the base we didn't match up      for (int j=0; j < count2; j++) {        XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j);        if (!foundIt[j] && !particle2.emptiable()) {          throw new XMLSchemaException("rcase-RecurseUnordered.2", null);        }      }    }    private static void checkRecurseLax(Vector dChildren, int min1, int max1,                                       SubstitutionGroupHandler dSGHandler,                                       Vector bChildren, int min2, int max2,                                       SubstitutionGroupHandler  bSGHandler)                                       throws XMLSchemaException {      // check Occurrence ranges      if (!checkOccurrenceRange(min1,max1,min2,max2)) {        throw new XMLSchemaException("rcase-RecurseLax.1", new Object[]{                                       Integer.toString(min1),                                       max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1),                                       Integer.toString(min2),                                       max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)});      }      int count1= dChildren.size();      int count2 = bChildren.size();      int current = 0;      label: for (int i = 0; i<count1; i++) {        XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i);        for (int j = current; j<count2; j++) {           XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j);           current +=1;           try {             particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler);             continue label;           }           catch (XMLSchemaException e) {           }        }        // didn't find a match.  Detect an error        throw new XMLSchemaException("rcase-RecurseLax.2", null);      }    }    private static void checkMapAndSum(Vector dChildren, int min1, int max1,                                       SubstitutionGroupHandler dSGHandler,                                       Vector bChildren, int min2, int max2,                                       SubstitutionGroupHandler bSGHandler)                                       throws XMLSchemaException {      // See if the sequence group is a valid restriction of the choice      // Here is an example of a valid restriction:      //   <choice minOccurs="2">      //       <a/>      //       <b/>      //       <c/>      //   </choice>      //      //   <sequence>      //        <b/>      //        <a/>      //   </sequence>      // check Occurrence ranges      if (!checkOccurrenceRange(min1,max1,min2,max2)) {        throw new XMLSchemaException("rcase-MapAndSum.2",                                     new Object[]{Integer.toString(min1),                                        max1==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max1),                                        Integer.toString(min2),                                        max2==SchemaSymbols.OCCURRENCE_UNBOUNDED?"unbounded":Integer.toString(max2)});      }      int count1 = dChildren.size();      int count2 = bChildren.size();      label: for (int i = 0; i<count1; i++) {        XSParticleDecl particle1 = (XSParticleDecl)dChildren.elementAt(i);        for (int j = 0; j<count2; j++) {           XSParticleDecl particle2 = (XSParticleDecl)bChildren.elementAt(j);           try {             particleValidRestriction(particle1, dSGHandler, particle2, bSGHandler);             continue label;           }           catch (XMLSchemaException e) {           }        }        // didn't find a match.  Detect an error        throw new XMLSchemaException("rcase-MapAndSum.1", null);      }    }    // to check whether two element overlap, as defined in constraint UPA    public static boolean overlapUPA(XSElementDecl element1,                                     XSElementDecl element2,                                     SubstitutionGroupHandler sgHandler) {        // if the two element have the same name and namespace,        if (element1.fName == element2.fName &&            element1.fTargetNamespace == element2.fTargetNamespace) {            return true;        }        // or if there is an element decl in element1's substitution group,        // who has the same name/namespace with element2        XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(element1);        for (int i = subGroup.length-1; i >= 0; i--) {            if (subGroup[i].fName == element2.fName &&                subGroup[i].fTargetNamespace == element2.fTargetNamespace) {                return true;            }        }        // or if there is an element decl in element2's substitution group,        // who has the same name/namespace with element1        subGroup = sgHandler.getSubstitutionGroup(element2);        for (int i = subGroup.length-1; i >= 0; i--) {            if (subGroup[i].fName == element1.fName &&                subGroup[i].fTargetNamespace == element1.fTargetNamespace) {                return true;            }        }        return false;    }    // to check whether an element overlaps with a wildcard,    // as defined in constraint UPA    public static boolean overlapUPA(XSElementDecl element,                                     XSWildcardDecl wildcard,                                     SubstitutionGroupHandler sgHandler) {        // if the wildcard allows the element        if (wildcard.allowNamespace(element.fTargetNamespace))            return true;        // or if the wildcard allows any element in the substitution group        XSElementDecl[] subGroup = sgHandler.getSubstitutionGroup(element);        for (int i = subGroup.length-1; i >= 0; i--) {            if (wildcard.allowNamespace(subGroup[i].fTargetNamespace))                return true;        }        return false;    }    public static boolean overlapUPA(XSWildcardDecl wildcard1,                                     XSWildcardDecl wildcard2) {        // if the intersection of the two wildcard is not empty list        XSWildcardDecl intersect = wildcard1.performIntersectionWith(wildcard2, wildcard1.fProcessContents);        if (intersect == null ||            intersect.fType != XSWildcardDecl.NSCONSTRAINT_LIST ||            intersect.fNamespaceList.length != 0) {            return true;        }        return false;    }    // call one of the above methods according to the type of decls    public static boolean overlapUPA(Object decl1, Object decl2,                                     SubstitutionGroupHandler sgHandler) {        if (decl1 instanceof XSElementDecl) {            if (decl2 instanceof XSElementDecl) {                return overlapUPA((XSElementDecl)decl1,                                  (XSElementDecl)decl2,                                  sgHandler);            } else {                return overlapUPA((XSElementDecl)decl1,                                  (XSWildcardDecl)decl2,                                  sgHandler);            }        } else {            if (decl2 instanceof XSElementDecl) {                return overlapUPA((XSElementDecl)decl2,                                  (XSWildcardDecl)decl1,                                  sgHandler);            } else {                return overlapUPA((XSWildcardDecl)decl1,                                  (XSWildcardDecl)decl2);            }        }    }} // class XSContraints

⌨️ 快捷键说明

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