Package org.apache.xerces.xs

Examples of org.apache.xerces.xs.XSParticle


         }

         // handleContentTypeElementsWithDerivationNone
         if (xc.getContentType() != XSComplexTypeDefinition.CONTENTTYPE_EMPTY)
         {
            XSParticle xp = xc.getParticle();
            if (xp != null)
            {
               XSTerm xterm = xp.getTerm();
               if (xterm instanceof XSModelGroup)
                  xm = (XSModelGroup)xterm;
            }
         }
View Full Code Here


    protected StateMachineRootNode build(XSParticle particle) {
        if (particle.getTerm() instanceof XSModelGroup) {
            XSModelGroup modelGroup = (XSModelGroup) particle.getTerm();
            boolean foundNestedModelGroup = false;
            for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
                XSParticle subParticle = (XSParticle) modelGroup.getParticles().item(i);
                if (subParticle.getTerm() instanceof XSModelGroup) {
                    foundNestedModelGroup = true;
                    break;
                }
            }
            if (!foundNestedModelGroup) {
View Full Code Here

        switch (modelGroup.getCompositor()) {

        case XSModelGroup.COMPOSITOR_SEQUENCE:
            for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
                XSParticle particle = (XSParticle) modelGroup.getParticles().item(i);

                if (particle.getTerm() instanceof XSElementDeclaration) {
                    StateMachineNode newNode = new StateMachineNode(particle.getTerm().getName());
                    rootNode.registerNode(newNode.getName(), newNode);

                    if (particle.getMaxOccursUnbounded()) {
                        newNode.addFollowing(newNode);
                    }

                    List<StateMachineNode> tmp = new ArrayList<StateMachineNode>();
                    for (StateMachineNode prevNode : previousNodes) {
                        prevNode.addFollowing(newNode);

                        if (particle.getMinOccurs() == 0) {
                            tmp.add(prevNode);
                        }
                    }
                    previousNodes = tmp;
                    previousNodes.add(newNode);

                    if (i == 0) {
                        returnLists.beginStates.add(newNode);
                    }

                } else if (particle.getTerm() instanceof XSModelGroup) {
                    ListPair listPair = handleModelGroup((XSModelGroup) particle.getTerm(), previousNodes, rootNode,
                            particle);
                    previousNodes = listPair.endStates;

                    if (i == 0) {
                        returnLists.beginStates.addAll(listPair.beginStates);
                    }
                }

            }
            returnLists.endStates = previousNodes;
            break;

        case XSModelGroup.COMPOSITOR_CHOICE:
            for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
                XSParticle particle = (XSParticle) modelGroup.getParticles().item(i);

                if (particle.getTerm() instanceof XSElementDeclaration) {
                    StateMachineNode newNode = new StateMachineNode(particle.getTerm().getName());
                    rootNode.registerNode(newNode.getName(), newNode);
                    returnLists.endStates.add(newNode);
                    returnLists.beginStates.add(newNode);

                    if (particle.getMinOccurs() == 0) {
                        for (StateMachineNode prevNode : previousNodes) {
                            if (!returnLists.endStates.contains(prevNode)) {
                                returnLists.endStates.add(prevNode);
                            }
                        }
                    }
                    if (particle.getMaxOccursUnbounded()) {
                        newNode.addFollowing(newNode);
                    }

                    for (StateMachineNode prevNode : previousNodes) {
                        prevNode.addFollowing(newNode);
                    }

                } else if (particle.getTerm() instanceof XSModelGroup) {
                    ListPair listPair = handleModelGroup((XSModelGroup) particle.getTerm(), previousNodes, rootNode,
                            particle);
                    returnLists.endStates.addAll(listPair.endStates);
                    returnLists.beginStates.addAll(listPair.beginStates);
                }
            }
View Full Code Here

        XSModelGroup modelGroup = null;
        boolean complexTypeMaxOccursUnbounded = false;
        int complexTypeMinOccurs = -1;
        int complexTypeMaxOccurs = -1;
        if (complexType != null) {
          XSParticle complexTypeParticle = complexType.getParticle();
            if (complexTypeParticle != null) {
              complexTypeMaxOccursUnbounded = complexTypeParticle.getMaxOccursUnbounded();
              complexTypeMinOccurs = complexTypeParticle.getMinOccurs();
              complexTypeMaxOccurs = complexTypeParticle.getMaxOccurs();
                if (complexTypeParticle.getTerm() instanceof XSModelGroup) {
                 
                    modelGroup = (XSModelGroup) complexType.getParticle().getTerm();
                }
            }
        }
        XSParticle particle = null;
        if (modelGroup != null && modelGroup.getParticles() != null) {
            for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
                XSObject particleObject = modelGroup.getParticles().item(i);
                if (particleObject instanceof XSParticle) {
                    XSParticle currentParticle = (XSParticle) particleObject;
                    if (currentParticle.getTerm() instanceof XSElementDeclaration) {
                        XSElementDeclaration particleElement = (XSElementDeclaration) currentParticle.getTerm();
                        if (particleElement.getName().equals(element.getName())) {
                            particle = currentParticle;
                            break;
                        }
                    }
                }
            }
        }
       
        Config config = dataProvider.getConfig();
        int iterationCounter = 0;
        while (tmpl.contains(Constants.TEMPLATE_DELIMITER_COMPLEX_VALIDATION)) {
            iterationCounter++;
            if (iterationCounter > config.getMaxTemplateResolvingIterations()) {
                System.err.println("********************************************");
                System.err.println("Could not resolve template:");
                System.err.println(fillInTemplate(tmpl, cppElementName, null, null, null, null, null, dataProvider));
                System.err.println("********************************************");
                break;
            }

            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_STRUCT_TYPE)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_STRUCT_TYPE, cppValidationDataStructType);
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_STRUCT_NAME)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_STRUCT_NAME, config
                        .getComplexValidationDataStructVariableName());
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_PARENT_STRUCT_NAME)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_PARENT_STRUCT_NAME, config
                        .getComplexValidationDataParentStructVariableName());
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_STRUCT_MEMBER)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_STRUCT_MEMBER, Util
                        .createComplexValidationDataStructMemberName(element, config));
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_CHECK_MAX_OCCURENCE)) {
                String maxOccCheck = config.getTemplateComplexValidationCheckMaxOccurence();
                if (particle == null || (particle != null && particle.getMaxOccursUnbounded()) || complexTypeMaxOccursUnbounded ) {
                    maxOccCheck = "";
                }
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_CHECK_MAX_OCCURENCE, maxOccCheck);
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_GET_VALIDATION_DATA)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_GET_VALIDATION_DATA, config
                        .getTemplateComplexValidationGetTopValidationData());
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_DELETE_VALIDATION_DATA)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_DELETE_VALIDATION_DATA, config
                        .getTemplateComplexValidationDeleteValidationData());
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_GET_PARENT_VALIDATION_DATA)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_GET_PARENT_VALIDATION_DATA, config
                        .getTemplateComplexValidationGetTopParentValidationData());
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_INCREMENT_OCCURENCE)) {
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_INCREMENT_OCCURENCE, config
                        .getTemplateComplexValidationIncrementOccurence());
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_MAX_OCCURENCE)) {
                int maxOccurence = 0;
                if (particle != null) {
                    maxOccurence = particle.getMaxOccurs();
                }
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_MAX_OCCURENCE, String.valueOf(maxOccurence));
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_CHECK_MIN_OCCURENCE_OF_CHILDREN)) {
                String childrenCheck = "";
                if (modelGroup != null && modelGroup.getParticles() != null) {
                    switch (modelGroup.getCompositor()) {
                    case XSModelGroup.COMPOSITOR_ALL:
                    case XSModelGroup.COMPOSITOR_SEQUENCE:
                        for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
                            XSObject item = modelGroup.getParticles().item(i);
                            if (item instanceof XSParticle) {
                                XSParticle child = (XSParticle) item;
                                if (child.getMinOccurs() == 0) {
                                    continue;
                                }
                                String particleTmpl = config.getTemplateComplexValidationCheckMinOccurencOfChildren();
                                childrenCheck += fillInComplexValidationParticleTemplate(particleTmpl, child, config);
                            }
                        }
                        break;
                    case XSModelGroup.COMPOSITOR_CHOICE:
                        boolean allChildrenHaveMinOccurs = true;
                        for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
                            XSObject item = modelGroup.getParticles().item(i);
                            if (item instanceof XSParticle) {
                                XSParticle child = (XSParticle) item;
                                if (child.getMinOccurs() == 0) {
                                    allChildrenHaveMinOccurs = false;
                                    continue;
                                }
                                String particleTmpl = config
                                        .getTemplateComplexValidationChoiceCheckMinOccurencOfChildren();
                                childrenCheck += fillInComplexValidationParticleTemplate(particleTmpl, child, config);
                            }
                        }
                        if (allChildrenHaveMinOccurs) {
                            childrenCheck += config.getTemplateComplexValidationChoiceCheckOneChildPresent();
                            if (childrenCheck.contains(Constants.TMPL_COMPLEX_VALI_CHOICE_ONE_CHILD_PER_CHILD)) {
                                for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
                                    XSObject item = modelGroup.getParticles().item(i);
                                    if (item instanceof XSParticle) {
                                        XSParticle child = (XSParticle) item;
                                        String perChild = config
                                                .getTemplateComplexValidationChoiceCheckOneChildPresentPerChild();
                                        if (i != modelGroup.getParticles().getLength() - 1) {
                                            perChild += " && " + Constants.TMPL_CONTINUE_LOOP;
                                        }
                                        childrenCheck = childrenCheck.replace(
                                                Constants.TMPL_COMPLEX_VALI_CHOICE_ONE_CHILD_PER_CHILD, perChild);
                                        childrenCheck = fillInComplexValidationParticleTemplate(childrenCheck, child,
                                                config);

                                        if (childrenCheck.contains(Constants.TMPL_CONTINUE_LOOP)) {
                                            childrenCheck = childrenCheck.replace(Constants.TMPL_CONTINUE_LOOP,
                                                    Constants.TMPL_COMPLEX_VALI_CHOICE_ONE_CHILD_PER_CHILD);
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    }
                }
                tmpl = tmpl.replace(Constants.TMPL_COMPLEX_VALI_CHECK_MIN_OCCURENCE_OF_CHILDREN, childrenCheck);
            }
            if (tmpl.contains(Constants.TMPL_COMPLEX_VALI_CHECK_SIBLINGS)) {
                String siblingsCheck = "";
                if (modelGroup != null && modelGroup.getParticles() != null) {
                    switch (modelGroup.getCompositor()) {
                    case XSModelGroup.COMPOSITOR_SEQUENCE:
                        List<XSParticle> previousSiblings = new ArrayList<XSParticle>();
                        List<XSParticle> followingSiblings = new ArrayList<XSParticle>();
                        Util.splitParticlesForSequence(modelGroup, particle, previousSiblings, followingSiblings);
                        for (int i = previousSiblings.size() - 1; i >= 0; i--) {
                            XSParticle prevSib = previousSiblings.get(i);
                            if (prevSib.getMinOccurs() == 0) {
                                continue;
                            }
                            String particleTmpl = config.getTemplateComplexValidationSequCheckPrev();
                            siblingsCheck += fillInComplexValidationParticleTemplate(particleTmpl, prevSib, config);
                            break;
View Full Code Here

            checkedGroups.add(modelGroup);
            XSObjectList particles = modelGroup.getParticles();
            for (int i = 0; i < particles.getLength(); i++) {
                XSObject item = particles.item(i);
                if (item instanceof XSParticle) {
                    XSParticle particle = (XSParticle) item;
                    if (particle.getTerm() instanceof XSModelGroup) {
                        XSModelGroup nestedModelGroup = (XSModelGroup) particle.getTerm();
                        String indent = "  ";
                        if (nestedHierarchy != 0) {
                            for (int j = 0; j < nestedHierarchy; j++) {
                                indent += indent;
                            }
                        }
                        if (nestedHierarchy == 0)
                            outFile.println("nested model group: ");
                        else {
                            outFile.println(indent + "nested nested model group: ");
                        }
                        outFile.println(indent + "element: " + getElementStack().peek().getName());
                        outFile.println(indent + "outer compositor: " + getCompositorString(modelGroup));
                        outFile.println(indent + "inner compositor: " + getCompositorString(nestedModelGroup));
                        outFile.println(indent + "inner min/max Occ: " + particle.getMinOccurs() + ", "
                                + particle.getMaxOccurs());
                        if (nestedModelGroup.getParticles() != null) {
                            for (int j = 0; j < nestedModelGroup.getParticles().getLength(); j++) {
                                XSParticle nestedChildParticle = (XSParticle) nestedModelGroup.getParticles().item(j);
                                if (nestedChildParticle.getMinOccurs() != 1 && nestedChildParticle.getMaxOccurs() != 1)
                                    outFile.println(indent + "inner child " + j + " min/max Occ: "
                                            + nestedChildParticle.getMinOccurs() + ", "
                                            + nestedChildParticle.getMaxOccurs());
                            }
                        }

                        checkModelGroup(nestedModelGroup, ++nestedHierarchy);
                    }
View Full Code Here

      XSComplexTypeDefinition xc = (XSComplexTypeDefinition)xst;
      if (xc.getContentType() == XSComplexTypeDefinition.CONTENTTYPE_EMPTY)
         return null;

      XSParticle xsp = xc.getParticle();
      if (xsp == null)
         return null;

      XSTerm xsterm = xsp.getTerm();
      if (xsterm instanceof XSModelGroup == false)
         return null;

      XSModelGroup xm = (XSModelGroup)xsterm;
      XSObjectList xo = xm.getParticles();
      if (xo.getLength() != 1)
         return null;

      XSParticle xp = (XSParticle)xo.item(0);
      XSTerm term = xp.getTerm();
      if ((xp.getMaxOccursUnbounded() || xp.getMaxOccurs() > 1) == false || term instanceof XSElementDeclaration == false)
         return null;

      return (XSElementDeclaration)term;
   }
View Full Code Here

    public static List<XSParticle> splitParticlesForChoice(XSModelGroup modelGroup, XSParticle particle) {
        List<XSParticle> siblings = new ArrayList<XSParticle>();
        for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
            XSObject item = modelGroup.getParticles().item(i);
            if (item instanceof XSParticle) {
                XSParticle currentParticle = (XSParticle) item;
                if (currentParticle != particle) {
                    siblings.add(currentParticle);
                }
            }
        }
View Full Code Here

            List<XSParticle> previousSiblings, List<XSParticle> followingSiblings) {
        boolean foundSelf = false;
        for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
            XSObject item = modelGroup.getParticles().item(i);
            if (item instanceof XSParticle) {
                XSParticle currentParticle = (XSParticle) item;
                if (!foundSelf) {
                    if (currentParticle == particle) {
                        foundSelf = true;
                    } else {
                        previousSiblings.add(currentParticle);
View Full Code Here

     * @return True if traversing shall continue, false for abort.
     */
    public boolean handleModelGroup(XSModelGroup modelGroup) {
        XSObjectList particles = modelGroup.getParticles();
        for (int i = 0; i < particles.getLength(); i++) {
            XSParticle particle = (XSParticle) particles.item(i);
            boolean success = handleParticle(particle);
            if (!success) {
                return false;
            }
        }
View Full Code Here

    /**
     * Handles model group for children collection.
     */
    protected void handleModelGroup(XSModelGroup modelGroup) {
        for (int i = 0; i < modelGroup.getParticles().getLength(); i++) {
            XSParticle particle = (XSParticle) modelGroup.getParticles().item(i);
            handleParticle(particle);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.xerces.xs.XSParticle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.