Java Code Examples for com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl#PARTICLE_WILDCARD

The following examples show how to use com.sun.org.apache.xerces.internal.impl.xs.XSParticleDecl#PARTICLE_WILDCARD . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XSDComplexTypeTraverser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static XSParticleDecl getErrorContent() {
    if (fErrorContent == null) {
        XSParticleDecl particle = new XSParticleDecl();
        particle.fType = XSParticleDecl.PARTICLE_WILDCARD;
        particle.fValue = getErrorWildcard();
        particle.fMinOccurs = 0;
        particle.fMaxOccurs = SchemaSymbols.OCCURRENCE_UNBOUNDED;
        XSModelGroupImpl group = new XSModelGroupImpl();
        group.fCompositor = XSModelGroupImpl.MODELGROUP_SEQUENCE;
        group.fParticleCount = 1;
        group.fParticles = new XSParticleDecl[1];
        group.fParticles[0] = particle;
        XSParticleDecl errorContent = new XSParticleDecl();
        errorContent.fType = XSParticleDecl.PARTICLE_MODELGROUP;
        errorContent.fValue = group;
        fErrorContent = errorContent;
    }
    return fErrorContent;
}
 
Example 2
Source File: XSDFACM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
Object findMatchingDecl(QName curElem, SubstitutionGroupHandler subGroupHandler) {
    Object matchingDecl = null;

    for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) {
        int type = fElemMapType[elemIndex] ;
        if (type == XSParticleDecl.PARTICLE_ELEMENT) {
            matchingDecl = subGroupHandler.getMatchingElemDecl(curElem, (XSElementDecl)fElemMap[elemIndex]);
            if (matchingDecl != null) {
                return matchingDecl;
            }
        }
        else if (type == XSParticleDecl.PARTICLE_WILDCARD) {
            if(((XSWildcardDecl)fElemMap[elemIndex]).allowNamespace(curElem.uri))
                return fElemMap[elemIndex];
        }
    }

    return null;
}
 
Example 3
Source File: CMBuilder.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private CMNode copyNode(CMNode node) {
    int type = node.type();
    // for choice or sequence, copy the two subtrees, and combine them
    if (type == XSModelGroupImpl.MODELGROUP_CHOICE ||
        type == XSModelGroupImpl.MODELGROUP_SEQUENCE) {
        XSCMBinOp bin = (XSCMBinOp)node;
        node = fNodeFactory.getCMBinOpNode(type, copyNode(bin.getLeft()),
                             copyNode(bin.getRight()));
    }
    // for ?+*, copy the subtree, and put it in a new ?+* node
    else if (type == XSParticleDecl.PARTICLE_ZERO_OR_MORE ||
             type == XSParticleDecl.PARTICLE_ONE_OR_MORE ||
             type == XSParticleDecl.PARTICLE_ZERO_OR_ONE) {
        XSCMUniOp uni = (XSCMUniOp)node;
        node = fNodeFactory.getCMUniOpNode(type, copyNode(uni.getChild()));
    }
    // for element/wildcard (leaf), make a new leaf node,
    // with a distinct position
    else if (type == XSParticleDecl.PARTICLE_ELEMENT ||
             type == XSParticleDecl.PARTICLE_WILDCARD) {
        XSCMLeaf leaf = (XSCMLeaf)node;
        node = fNodeFactory.getCMLeafNode(leaf.type(), leaf.getLeaf(), leaf.getParticleId(), fLeafCount++);
    }

    return node;
}
 
Example 4
Source File: XSDFACM.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
Object findMatchingDecl(QName curElem, SubstitutionGroupHandler subGroupHandler) {
    Object matchingDecl = null;

    for (int elemIndex = 0; elemIndex < fElemMapSize; elemIndex++) {
        int type = fElemMapType[elemIndex] ;
        if (type == XSParticleDecl.PARTICLE_ELEMENT) {
            matchingDecl = subGroupHandler.getMatchingElemDecl(curElem, (XSElementDecl)fElemMap[elemIndex]);
            if (matchingDecl != null) {
                return matchingDecl;
            }
        }
        else if (type == XSParticleDecl.PARTICLE_WILDCARD) {
            if(((XSWildcardDecl)fElemMap[elemIndex]).allowNamespace(curElem.uri))
                return fElemMap[elemIndex];
        }
    }

    return null;
}
 
Example 5
Source File: XSDFACM.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Post tree build initialization. */
private void postTreeBuildInit(CMNode nodeCur) throws RuntimeException {
    // Set the maximum states on this node
    nodeCur.setMaxStates(fLeafCount);

    XSCMLeaf leaf = null;
    int pos = 0;
    // Recurse as required
    if (nodeCur.type() == XSParticleDecl.PARTICLE_WILDCARD) {
        leaf = (XSCMLeaf)nodeCur;
        pos = leaf.getPosition();
        fLeafList[pos] = leaf;
        fLeafListType[pos] = XSParticleDecl.PARTICLE_WILDCARD;
    }
    else if ((nodeCur.type() == XSModelGroupImpl.MODELGROUP_CHOICE) ||
             (nodeCur.type() == XSModelGroupImpl.MODELGROUP_SEQUENCE)) {
        postTreeBuildInit(((XSCMBinOp)nodeCur).getLeft());
        postTreeBuildInit(((XSCMBinOp)nodeCur).getRight());
    }
    else if (nodeCur.type() == XSParticleDecl.PARTICLE_ZERO_OR_MORE ||
             nodeCur.type() == XSParticleDecl.PARTICLE_ONE_OR_MORE ||
             nodeCur.type() == XSParticleDecl.PARTICLE_ZERO_OR_ONE) {
        postTreeBuildInit(((XSCMUniOp)nodeCur).getChild());
    }
    else if (nodeCur.type() == XSParticleDecl.PARTICLE_ELEMENT) {
        //  Put this node in the leaf list at the current index if its
        //  a non-epsilon leaf.
        leaf = (XSCMLeaf)nodeCur;
        pos = leaf.getPosition();
        fLeafList[pos] = leaf;
        fLeafListType[pos] = XSParticleDecl.PARTICLE_ELEMENT;
    }
    else {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
}
 
Example 6
Source File: XSDFACM.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** Post tree build initialization. */
private void postTreeBuildInit(CMNode nodeCur) throws RuntimeException {
    // Set the maximum states on this node
    nodeCur.setMaxStates(fLeafCount);

    XSCMLeaf leaf = null;
    int pos = 0;
    // Recurse as required
    if (nodeCur.type() == XSParticleDecl.PARTICLE_WILDCARD) {
        leaf = (XSCMLeaf)nodeCur;
        pos = leaf.getPosition();
        fLeafList[pos] = leaf;
        fLeafListType[pos] = XSParticleDecl.PARTICLE_WILDCARD;
    }
    else if ((nodeCur.type() == XSModelGroupImpl.MODELGROUP_CHOICE) ||
             (nodeCur.type() == XSModelGroupImpl.MODELGROUP_SEQUENCE)) {
        postTreeBuildInit(((XSCMBinOp)nodeCur).getLeft());
        postTreeBuildInit(((XSCMBinOp)nodeCur).getRight());
    }
    else if (nodeCur.type() == XSParticleDecl.PARTICLE_ZERO_OR_MORE ||
             nodeCur.type() == XSParticleDecl.PARTICLE_ONE_OR_MORE ||
             nodeCur.type() == XSParticleDecl.PARTICLE_ZERO_OR_ONE) {
        postTreeBuildInit(((XSCMUniOp)nodeCur).getChild());
    }
    else if (nodeCur.type() == XSParticleDecl.PARTICLE_ELEMENT) {
        //  Put this node in the leaf list at the current index if its
        //  a non-epsilon leaf.
        leaf = (XSCMLeaf)nodeCur;
        pos = leaf.getPosition();
        fLeafList[pos] = leaf;
        fLeafListType[pos] = XSParticleDecl.PARTICLE_ELEMENT;
    }
    else {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
}
 
Example 7
Source File: XSDFACM.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dumps the tree of the current node to standard output.
 *
 * @param nodeCur The current node.
 * @param level   The maximum levels to output.
 *
 * @exception RuntimeException Thrown on error.
 */
private void dumpTree(CMNode nodeCur, int level) {
    for (int index = 0; index < level; index++)
        System.out.print("   ");

    int type = nodeCur.type();

    switch(type ) {

    case XSModelGroupImpl.MODELGROUP_CHOICE:
    case XSModelGroupImpl.MODELGROUP_SEQUENCE: {
        if (type == XSModelGroupImpl.MODELGROUP_CHOICE)
            System.out.print("Choice Node ");
        else
            System.out.print("Seq Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMBinOp)nodeCur).getLeft(), level+1);
        dumpTree(((XSCMBinOp)nodeCur).getRight(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ZERO_OR_MORE:
    case XSParticleDecl.PARTICLE_ONE_OR_MORE:
    case XSParticleDecl.PARTICLE_ZERO_OR_ONE: {
        System.out.print("Rep Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMUniOp)nodeCur).getChild(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ELEMENT: {
        System.out.print
        (
            "Leaf: (pos="
            + ((XSCMLeaf)nodeCur).getPosition()
            + "), "
            + "(elemIndex="
            + ((XSCMLeaf)nodeCur).getLeaf()
            + ") "
        );

        if (nodeCur.isNullable())
            System.out.print(" Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    }
    case XSParticleDecl.PARTICLE_WILDCARD:
          System.out.print("Any Node: ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    default: {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
    }

}
 
Example 8
Source File: XSDFACM.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * check whether this content violates UPA constraint.
 *
 * @param subGroupHandler the substitution group handler
 * @return true if this content model contains other or list wildcard
 */
public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException {
    // Unique Particle Attribution
    // store the conflict results between any two elements in fElemMap
    // 0: not compared; -1: no conflict; 1: conflict
    // initialize the conflict table (all 0 initially)
    byte conflictTable[][] = new byte[fElemMapSize][fElemMapSize];

    // for each state, check whether it has overlap transitions
    for (int i = 0; i < fTransTable.length && fTransTable[i] != null; i++) {
        for (int j = 0; j < fElemMapSize; j++) {
            for (int k = j+1; k < fElemMapSize; k++) {
                if (fTransTable[i][j] != -1 &&
                    fTransTable[i][k] != -1) {
                    if (conflictTable[j][k] == 0) {
                        if (XSConstraints.overlapUPA
                                (fElemMap[j], fElemMap[k],
                                        subGroupHandler)) {
                            if (fCountingStates != null) {
                                Occurence o = fCountingStates[i];
                                // If "i" is a counting state and exactly one of the transitions
                                // loops back to "i" then the two particles do not overlap if
                                // minOccurs == maxOccurs.
                                if (o != null &&
                                    fTransTable[i][j] == i ^ fTransTable[i][k] == i &&
                                    o.minOccurs == o.maxOccurs) {
                                    conflictTable[j][k] = (byte) -1;
                                    continue;
                                }
                            }
                            conflictTable[j][k] = (byte) 1;
                        }
                        else {
                            conflictTable[j][k] = (byte) -1;
                        }
                    }
                }
            }
        }
    }

    // report all errors
    for (int i = 0; i < fElemMapSize; i++) {
        for (int j = 0; j < fElemMapSize; j++) {
            if (conflictTable[i][j] == 1) {
                //errors.newError("cos-nonambig", new Object[]{fElemMap[i].toString(),
                //                                             fElemMap[j].toString()});
                // REVISIT: do we want to report all errors? or just one?
                throw new XMLSchemaException("cos-nonambig", new Object[]{fElemMap[i].toString(),
                                                                          fElemMap[j].toString()});
            }
        }
    }

    // if there is a other or list wildcard, we need to check this CM
    // again, if this grammar is cached.
    for (int i = 0; i < fElemMapSize; i++) {
        if (fElemMapType[i] == XSParticleDecl.PARTICLE_WILDCARD) {
            XSWildcardDecl wildcard = (XSWildcardDecl)fElemMap[i];
            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST ||
                wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
                return true;
            }
        }
    }

    return false;
}
 
Example 9
Source File: CMBuilder.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private CMNode buildCompactSyntaxTree(XSParticleDecl particle) {
    int maxOccurs = particle.fMaxOccurs;
    int minOccurs = particle.fMinOccurs;
    short type = particle.fType;
    CMNode nodeRet = null;

    if ((type == XSParticleDecl.PARTICLE_WILDCARD) ||
        (type == XSParticleDecl.PARTICLE_ELEMENT)) {
        return buildCompactSyntaxTree2(particle, minOccurs, maxOccurs);
    }
    else if (type == XSParticleDecl.PARTICLE_MODELGROUP) {
        XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
        if (group.fParticleCount == 1 && (minOccurs != 1 || maxOccurs != 1)) {
            return buildCompactSyntaxTree2(group.fParticles[0], minOccurs, maxOccurs);
        }
        else {
            CMNode temp = null;

            // when the model group is a choice of more than one particles, but
            // only one of the particle is not empty, (for example
            // <choice>
            //   <sequence/>
            //   <element name="e"/>
            // </choice>
            // ) we can't not return that one particle ("e"). instead, we should
            // treat such particle as optional ("e?").
            // the following int variable keeps track of the number of non-empty children
            int count = 0;
            for (int i = 0; i < group.fParticleCount; i++) {
                // first convert each child to a CM tree
                temp = buildCompactSyntaxTree(group.fParticles[i]);
                // then combine them using binary operation
                if (temp != null) {
                    ++count;
                    if (nodeRet == null) {
                        nodeRet = temp;
                    }
                    else {
                        nodeRet = fNodeFactory.getCMBinOpNode(group.fCompositor, nodeRet, temp);
                    }
                }
            }
            if (nodeRet != null) {
                // when the group is "choice" and the group has one or more empty children,
                // we need to create a zero-or-one (optional) node for the non-empty particles.
                if (group.fCompositor == XSModelGroupImpl.MODELGROUP_CHOICE && count < group.fParticleCount) {
                    nodeRet = fNodeFactory.getCMUniOpNode(XSParticleDecl.PARTICLE_ZERO_OR_ONE, nodeRet);
                }
            }
        }
    }
    return nodeRet;
}
 
Example 10
Source File: XSDFACM.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dumps the tree of the current node to standard output.
 *
 * @param nodeCur The current node.
 * @param level   The maximum levels to output.
 *
 * @exception RuntimeException Thrown on error.
 */
private void dumpTree(CMNode nodeCur, int level) {
    for (int index = 0; index < level; index++)
        System.out.print("   ");

    int type = nodeCur.type();

    switch(type ) {

    case XSModelGroupImpl.MODELGROUP_CHOICE:
    case XSModelGroupImpl.MODELGROUP_SEQUENCE: {
        if (type == XSModelGroupImpl.MODELGROUP_CHOICE)
            System.out.print("Choice Node ");
        else
            System.out.print("Seq Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMBinOp)nodeCur).getLeft(), level+1);
        dumpTree(((XSCMBinOp)nodeCur).getRight(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ZERO_OR_MORE:
    case XSParticleDecl.PARTICLE_ONE_OR_MORE:
    case XSParticleDecl.PARTICLE_ZERO_OR_ONE: {
        System.out.print("Rep Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMUniOp)nodeCur).getChild(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ELEMENT: {
        System.out.print
        (
            "Leaf: (pos="
            + ((XSCMLeaf)nodeCur).getPosition()
            + "), "
            + "(elemIndex="
            + ((XSCMLeaf)nodeCur).getLeaf()
            + ") "
        );

        if (nodeCur.isNullable())
            System.out.print(" Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    }
    case XSParticleDecl.PARTICLE_WILDCARD:
          System.out.print("Any Node: ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    default: {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
    }

}
 
Example 11
Source File: XSDFACM.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Dumps the tree of the current node to standard output.
 *
 * @param nodeCur The current node.
 * @param level   The maximum levels to output.
 *
 * @exception RuntimeException Thrown on error.
 */
private void dumpTree(CMNode nodeCur, int level) {
    for (int index = 0; index < level; index++)
        System.out.print("   ");

    int type = nodeCur.type();

    switch(type ) {

    case XSModelGroupImpl.MODELGROUP_CHOICE:
    case XSModelGroupImpl.MODELGROUP_SEQUENCE: {
        if (type == XSModelGroupImpl.MODELGROUP_CHOICE)
            System.out.print("Choice Node ");
        else
            System.out.print("Seq Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMBinOp)nodeCur).getLeft(), level+1);
        dumpTree(((XSCMBinOp)nodeCur).getRight(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ZERO_OR_MORE:
    case XSParticleDecl.PARTICLE_ONE_OR_MORE:
    case XSParticleDecl.PARTICLE_ZERO_OR_ONE: {
        System.out.print("Rep Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMUniOp)nodeCur).getChild(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ELEMENT: {
        System.out.print
        (
            "Leaf: (pos="
            + ((XSCMLeaf)nodeCur).getPosition()
            + "), "
            + "(elemIndex="
            + ((XSCMLeaf)nodeCur).getLeaf()
            + ") "
        );

        if (nodeCur.isNullable())
            System.out.print(" Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    }
    case XSParticleDecl.PARTICLE_WILDCARD:
          System.out.print("Any Node: ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    default: {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
    }

}
 
Example 12
Source File: CMBuilder.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private CMNode buildSyntaxTree(XSParticleDecl particle, boolean optimize) {

        int maxOccurs = particle.fMaxOccurs;
        int minOccurs = particle.fMinOccurs;
        short type = particle.fType;
        CMNode nodeRet = null;

        if ((type == XSParticleDecl.PARTICLE_WILDCARD) ||
            (type == XSParticleDecl.PARTICLE_ELEMENT)) {
            // (task 1) element and wildcard particles should be converted to
            // leaf nodes
            // REVISIT: Make a clone of the leaf particle, so that if there
            // are two references to the same group, we have two different
            // leaf particles for the same element or wildcard decl.
            // This is useful for checking UPA.
            nodeRet = fNodeFactory.getCMLeafNode(particle.fType, particle.fValue, fParticleCount++, fLeafCount++);
            // (task 2) expand occurrence values
            nodeRet = expandContentModel(nodeRet, minOccurs, maxOccurs, optimize);
        }
        else if (type == XSParticleDecl.PARTICLE_MODELGROUP) {
            // (task 1,3) convert model groups to binary trees
            XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
            CMNode temp = null;
            // when the model group is a choice of more than one particles, but
            // only one of the particle is not empty, (for example
            // <choice>
            //   <sequence/>
            //   <element name="e"/>
            // </choice>
            // ) we can't not return that one particle ("e"). instead, we should
            // treat such particle as optional ("e?").
            // the following boolean variable is true when there are at least
            // 2 non-empty children.
            boolean twoChildren = false;
            for (int i = 0; i < group.fParticleCount; i++) {
                // first convert each child to a CM tree
                temp = buildSyntaxTree(group.fParticles[i],
                        optimize &&
                        minOccurs == 1 && maxOccurs == 1 &&
                        (group.fCompositor == XSModelGroupImpl.MODELGROUP_SEQUENCE ||
                         group.fParticleCount == 1));
                // then combine them using binary operation
                if (temp != null) {
                    if (nodeRet == null) {
                        nodeRet = temp;
                    }
                    else {
                        nodeRet = fNodeFactory.getCMBinOpNode(group.fCompositor, nodeRet, temp);
                        // record the fact that there are at least 2 children
                        twoChildren = true;
                    }
                }
            }
            // (task 2) expand occurrence values
            if (nodeRet != null) {
                // when the group is "choice", there is only one non-empty
                // child, and the group had more than one children, we need
                // to create a zero-or-one (optional) node for the non-empty
                // particle.
                if (group.fCompositor == XSModelGroupImpl.MODELGROUP_CHOICE &&
                    !twoChildren && group.fParticleCount > 1) {
                    nodeRet = fNodeFactory.getCMUniOpNode(XSParticleDecl.PARTICLE_ZERO_OR_ONE, nodeRet);
                }
                nodeRet = expandContentModel(nodeRet, minOccurs, maxOccurs, false);
            }
        }

        return nodeRet;
    }
 
Example 13
Source File: XSDFACM.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dumps the tree of the current node to standard output.
 *
 * @param nodeCur The current node.
 * @param level   The maximum levels to output.
 *
 * @exception RuntimeException Thrown on error.
 */
private void dumpTree(CMNode nodeCur, int level) {
    for (int index = 0; index < level; index++)
        System.out.print("   ");

    int type = nodeCur.type();

    switch(type ) {

    case XSModelGroupImpl.MODELGROUP_CHOICE:
    case XSModelGroupImpl.MODELGROUP_SEQUENCE: {
        if (type == XSModelGroupImpl.MODELGROUP_CHOICE)
            System.out.print("Choice Node ");
        else
            System.out.print("Seq Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMBinOp)nodeCur).getLeft(), level+1);
        dumpTree(((XSCMBinOp)nodeCur).getRight(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ZERO_OR_MORE:
    case XSParticleDecl.PARTICLE_ONE_OR_MORE:
    case XSParticleDecl.PARTICLE_ZERO_OR_ONE: {
        System.out.print("Rep Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMUniOp)nodeCur).getChild(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ELEMENT: {
        System.out.print
        (
            "Leaf: (pos="
            + ((XSCMLeaf)nodeCur).getPosition()
            + "), "
            + "(elemIndex="
            + ((XSCMLeaf)nodeCur).getLeaf()
            + ") "
        );

        if (nodeCur.isNullable())
            System.out.print(" Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    }
    case XSParticleDecl.PARTICLE_WILDCARD:
          System.out.print("Any Node: ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    default: {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
    }

}
 
Example 14
Source File: XSDFACM.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
Object findMatchingDecl(QName curElem, int[] state, SubstitutionGroupHandler subGroupHandler, int elemIndex) {

        int curState = state[0];
        int nextState = 0;
        Object matchingDecl = null;

        while (++elemIndex < fElemMapSize) {
            nextState = fTransTable[curState][elemIndex];
            if (nextState == -1)
                continue;
            int type = fElemMapType[elemIndex] ;
            if (type == XSParticleDecl.PARTICLE_ELEMENT) {
                matchingDecl = subGroupHandler.getMatchingElemDecl(curElem, (XSElementDecl)fElemMap[elemIndex]);
                if (matchingDecl != null) {
                    break;
                }
            }
            else if (type == XSParticleDecl.PARTICLE_WILDCARD) {
                if (((XSWildcardDecl)fElemMap[elemIndex]).allowNamespace(curElem.uri)) {
                    matchingDecl = fElemMap[elemIndex];
                    break;
                }
            }
        }

        // if we still can't find a match, set the state to FIRST_ERROR and return null
        if (elemIndex == fElemMapSize) {
            state[1] = state[0];
            state[0] = XSCMValidator.FIRST_ERROR;
            return findMatchingDecl(curElem, subGroupHandler);
        }

        // if we found a match, set the next state and reset the
        // counter if the next state is a counting state.
        state[0] = nextState;
        final Occurence o = fCountingStates[nextState];
        if (o != null) {
            state[2] = (elemIndex == o.elemIndex) ? 1 : 0;
        }
        return matchingDecl;
    }
 
Example 15
Source File: XSDFACM.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Dumps the tree of the current node to standard output.
 *
 * @param nodeCur The current node.
 * @param level   The maximum levels to output.
 *
 * @exception RuntimeException Thrown on error.
 */
private void dumpTree(CMNode nodeCur, int level) {
    for (int index = 0; index < level; index++)
        System.out.print("   ");

    int type = nodeCur.type();

    switch(type ) {

    case XSModelGroupImpl.MODELGROUP_CHOICE:
    case XSModelGroupImpl.MODELGROUP_SEQUENCE: {
        if (type == XSModelGroupImpl.MODELGROUP_CHOICE)
            System.out.print("Choice Node ");
        else
            System.out.print("Seq Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMBinOp)nodeCur).getLeft(), level+1);
        dumpTree(((XSCMBinOp)nodeCur).getRight(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ZERO_OR_MORE:
    case XSParticleDecl.PARTICLE_ONE_OR_MORE:
    case XSParticleDecl.PARTICLE_ZERO_OR_ONE: {
        System.out.print("Rep Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMUniOp)nodeCur).getChild(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ELEMENT: {
        System.out.print
        (
            "Leaf: (pos="
            + ((XSCMLeaf)nodeCur).getPosition()
            + "), "
            + "(elemIndex="
            + ((XSCMLeaf)nodeCur).getLeaf()
            + ") "
        );

        if (nodeCur.isNullable())
            System.out.print(" Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    }
    case XSParticleDecl.PARTICLE_WILDCARD:
          System.out.print("Any Node: ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    default: {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
    }

}
 
Example 16
Source File: CMBuilder.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private CMNode buildCompactSyntaxTree(XSParticleDecl particle) {
    int maxOccurs = particle.fMaxOccurs;
    int minOccurs = particle.fMinOccurs;
    short type = particle.fType;
    CMNode nodeRet = null;

    if ((type == XSParticleDecl.PARTICLE_WILDCARD) ||
        (type == XSParticleDecl.PARTICLE_ELEMENT)) {
        return buildCompactSyntaxTree2(particle, minOccurs, maxOccurs);
    }
    else if (type == XSParticleDecl.PARTICLE_MODELGROUP) {
        XSModelGroupImpl group = (XSModelGroupImpl)particle.fValue;
        if (group.fParticleCount == 1 && (minOccurs != 1 || maxOccurs != 1)) {
            return buildCompactSyntaxTree2(group.fParticles[0], minOccurs, maxOccurs);
        }
        else {
            CMNode temp = null;

            // when the model group is a choice of more than one particles, but
            // only one of the particle is not empty, (for example
            // <choice>
            //   <sequence/>
            //   <element name="e"/>
            // </choice>
            // ) we can't not return that one particle ("e"). instead, we should
            // treat such particle as optional ("e?").
            // the following int variable keeps track of the number of non-empty children
            int count = 0;
            for (int i = 0; i < group.fParticleCount; i++) {
                // first convert each child to a CM tree
                temp = buildCompactSyntaxTree(group.fParticles[i]);
                // then combine them using binary operation
                if (temp != null) {
                    ++count;
                    if (nodeRet == null) {
                        nodeRet = temp;
                    }
                    else {
                        nodeRet = fNodeFactory.getCMBinOpNode(group.fCompositor, nodeRet, temp);
                    }
                }
            }
            if (nodeRet != null) {
                // when the group is "choice" and the group has one or more empty children,
                // we need to create a zero-or-one (optional) node for the non-empty particles.
                if (group.fCompositor == XSModelGroupImpl.MODELGROUP_CHOICE && count < group.fParticleCount) {
                    nodeRet = fNodeFactory.getCMUniOpNode(XSParticleDecl.PARTICLE_ZERO_OR_ONE, nodeRet);
                }
            }
        }
    }
    return nodeRet;
}
 
Example 17
Source File: XSDFACM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * check whether this content violates UPA constraint.
 *
 * @param subGroupHandler the substitution group handler
 * @return true if this content model contains other or list wildcard
 */
public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException {
    // Unique Particle Attribution
    // store the conflict results between any two elements in fElemMap
    // 0: not compared; -1: no conflict; 1: conflict
    // initialize the conflict table (all 0 initially)
    byte conflictTable[][] = new byte[fElemMapSize][fElemMapSize];

    // for each state, check whether it has overlap transitions
    for (int i = 0; i < fTransTable.length && fTransTable[i] != null; i++) {
        for (int j = 0; j < fElemMapSize; j++) {
            for (int k = j+1; k < fElemMapSize; k++) {
                if (fTransTable[i][j] != -1 &&
                    fTransTable[i][k] != -1) {
                    if (conflictTable[j][k] == 0) {
                        if (XSConstraints.overlapUPA
                                (fElemMap[j], fElemMap[k],
                                        subGroupHandler)) {
                            if (fCountingStates != null) {
                                Occurence o = fCountingStates[i];
                                // If "i" is a counting state and exactly one of the transitions
                                // loops back to "i" then the two particles do not overlap if
                                // minOccurs == maxOccurs.
                                if (o != null &&
                                    fTransTable[i][j] == i ^ fTransTable[i][k] == i &&
                                    o.minOccurs == o.maxOccurs) {
                                    conflictTable[j][k] = (byte) -1;
                                    continue;
                                }
                            }
                            conflictTable[j][k] = (byte) 1;
                        }
                        else {
                            conflictTable[j][k] = (byte) -1;
                        }
                    }
                }
            }
        }
    }

    // report all errors
    for (int i = 0; i < fElemMapSize; i++) {
        for (int j = 0; j < fElemMapSize; j++) {
            if (conflictTable[i][j] == 1) {
                //errors.newError("cos-nonambig", new Object[]{fElemMap[i].toString(),
                //                                             fElemMap[j].toString()});
                // REVISIT: do we want to report all errors? or just one?
                throw new XMLSchemaException("cos-nonambig", new Object[]{fElemMap[i].toString(),
                                                                          fElemMap[j].toString()});
            }
        }
    }

    // if there is a other or list wildcard, we need to check this CM
    // again, if this grammar is cached.
    for (int i = 0; i < fElemMapSize; i++) {
        if (fElemMapType[i] == XSParticleDecl.PARTICLE_WILDCARD) {
            XSWildcardDecl wildcard = (XSWildcardDecl)fElemMap[i];
            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST ||
                wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
                return true;
            }
        }
    }

    return false;
}
 
Example 18
Source File: XSDFACM.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
Object findMatchingDecl(QName curElem, int[] state, SubstitutionGroupHandler subGroupHandler, int elemIndex) {

        int curState = state[0];
        int nextState = 0;
        Object matchingDecl = null;

        while (++elemIndex < fElemMapSize) {
            nextState = fTransTable[curState][elemIndex];
            if (nextState == -1)
                continue;
            int type = fElemMapType[elemIndex] ;
            if (type == XSParticleDecl.PARTICLE_ELEMENT) {
                matchingDecl = subGroupHandler.getMatchingElemDecl(curElem, (XSElementDecl)fElemMap[elemIndex]);
                if (matchingDecl != null) {
                    break;
                }
            }
            else if (type == XSParticleDecl.PARTICLE_WILDCARD) {
                if (((XSWildcardDecl)fElemMap[elemIndex]).allowNamespace(curElem.uri)) {
                    matchingDecl = fElemMap[elemIndex];
                    break;
                }
            }
        }

        // if we still can't find a match, set the state to FIRST_ERROR and return null
        if (elemIndex == fElemMapSize) {
            state[1] = state[0];
            state[0] = XSCMValidator.FIRST_ERROR;
            return findMatchingDecl(curElem, subGroupHandler);
        }

        // if we found a match, set the next state and reset the
        // counter if the next state is a counting state.
        state[0] = nextState;
        final Occurence o = fCountingStates[nextState];
        if (o != null) {
            state[2] = (elemIndex == o.elemIndex) ? 1 : 0;
        }
        return matchingDecl;
    }
 
Example 19
Source File: XSDFACM.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * check whether this content violates UPA constraint.
 *
 * @param subGroupHandler the substitution group handler
 * @return true if this content model contains other or list wildcard
 */
public boolean checkUniqueParticleAttribution(SubstitutionGroupHandler subGroupHandler) throws XMLSchemaException {
    // Unique Particle Attribution
    // store the conflict results between any two elements in fElemMap
    // 0: not compared; -1: no conflict; 1: conflict
    // initialize the conflict table (all 0 initially)
    byte conflictTable[][] = new byte[fElemMapSize][fElemMapSize];

    // for each state, check whether it has overlap transitions
    for (int i = 0; i < fTransTable.length && fTransTable[i] != null; i++) {
        for (int j = 0; j < fElemMapSize; j++) {
            for (int k = j+1; k < fElemMapSize; k++) {
                if (fTransTable[i][j] != -1 &&
                    fTransTable[i][k] != -1) {
                    if (conflictTable[j][k] == 0) {
                        if (XSConstraints.overlapUPA
                                (fElemMap[j], fElemMap[k],
                                        subGroupHandler)) {
                            if (fCountingStates != null) {
                                Occurence o = fCountingStates[i];
                                // If "i" is a counting state and exactly one of the transitions
                                // loops back to "i" then the two particles do not overlap if
                                // minOccurs == maxOccurs.
                                if (o != null &&
                                    fTransTable[i][j] == i ^ fTransTable[i][k] == i &&
                                    o.minOccurs == o.maxOccurs) {
                                    conflictTable[j][k] = (byte) -1;
                                    continue;
                                }
                            }
                            conflictTable[j][k] = (byte) 1;
                        }
                        else {
                            conflictTable[j][k] = (byte) -1;
                        }
                    }
                }
            }
        }
    }

    // report all errors
    for (int i = 0; i < fElemMapSize; i++) {
        for (int j = 0; j < fElemMapSize; j++) {
            if (conflictTable[i][j] == 1) {
                //errors.newError("cos-nonambig", new Object[]{fElemMap[i].toString(),
                //                                             fElemMap[j].toString()});
                // REVISIT: do we want to report all errors? or just one?
                throw new XMLSchemaException("cos-nonambig", new Object[]{fElemMap[i].toString(),
                                                                          fElemMap[j].toString()});
            }
        }
    }

    // if there is a other or list wildcard, we need to check this CM
    // again, if this grammar is cached.
    for (int i = 0; i < fElemMapSize; i++) {
        if (fElemMapType[i] == XSParticleDecl.PARTICLE_WILDCARD) {
            XSWildcardDecl wildcard = (XSWildcardDecl)fElemMap[i];
            if (wildcard.fType == XSWildcardDecl.NSCONSTRAINT_LIST ||
                wildcard.fType == XSWildcardDecl.NSCONSTRAINT_NOT) {
                return true;
            }
        }
    }

    return false;
}
 
Example 20
Source File: XSDFACM.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Dumps the tree of the current node to standard output.
 *
 * @param nodeCur The current node.
 * @param level   The maximum levels to output.
 *
 * @exception RuntimeException Thrown on error.
 */
private void dumpTree(CMNode nodeCur, int level) {
    for (int index = 0; index < level; index++)
        System.out.print("   ");

    int type = nodeCur.type();

    switch(type ) {

    case XSModelGroupImpl.MODELGROUP_CHOICE:
    case XSModelGroupImpl.MODELGROUP_SEQUENCE: {
        if (type == XSModelGroupImpl.MODELGROUP_CHOICE)
            System.out.print("Choice Node ");
        else
            System.out.print("Seq Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMBinOp)nodeCur).getLeft(), level+1);
        dumpTree(((XSCMBinOp)nodeCur).getRight(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ZERO_OR_MORE:
    case XSParticleDecl.PARTICLE_ONE_OR_MORE:
    case XSParticleDecl.PARTICLE_ZERO_OR_ONE: {
        System.out.print("Rep Node ");

        if (nodeCur.isNullable())
            System.out.print("Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());

        dumpTree(((XSCMUniOp)nodeCur).getChild(), level+1);
        break;
    }
    case XSParticleDecl.PARTICLE_ELEMENT: {
        System.out.print
        (
            "Leaf: (pos="
            + ((XSCMLeaf)nodeCur).getPosition()
            + "), "
            + "(elemIndex="
            + ((XSCMLeaf)nodeCur).getLeaf()
            + ") "
        );

        if (nodeCur.isNullable())
            System.out.print(" Nullable ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    }
    case XSParticleDecl.PARTICLE_WILDCARD:
          System.out.print("Any Node: ");

        System.out.print("firstPos=");
        System.out.print(nodeCur.firstPos().toString());
        System.out.print(" lastPos=");
        System.out.println(nodeCur.lastPos().toString());
        break;
    default: {
        throw new RuntimeException("ImplementationMessages.VAL_NIICM");
    }
    }

}