Search in sources :

Example 11 with XSElementDeclaration

use of org.apache.xerces.xs.XSElementDeclaration in project iaf by ibissource.

the class XmlAligner method determineIsParentOfSingleMultipleOccurringChildElement.

protected int determineIsParentOfSingleMultipleOccurringChildElement(XSParticle particle) {
    if (particle == null) {
        log.warn("Particle is null, is this a problem? Appearantly not");
        return CHILD_OCCURRENCE_EMPTY;
    }
    XSTerm term = particle.getTerm();
    if (term == null) {
        throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement particle.term is null");
    }
    if (DEBUG)
        log.debug("determineIsParentOfSingleMultipleOccurringChildElement() term name [" + term.getName() + "] occurring unbounded [" + particle.getMaxOccursUnbounded() + "] max occur [" + particle.getMaxOccurs() + "] term [" + ToStringBuilder.reflectionToString(term) + "]");
    if (term instanceof XSModelGroup) {
        XSModelGroup modelGroup = (XSModelGroup) term;
        short compositor = modelGroup.getCompositor();
        XSObjectList particles = modelGroup.getParticles();
        switch(compositor) {
            case XSModelGroup.COMPOSITOR_SEQUENCE:
            case XSModelGroup.COMPOSITOR_ALL:
                {
                    if (DEBUG)
                        log.debug("determineIsParentOfSingleMultipleOccurringChildElement() sequence or all particles [" + ToStringBuilder.reflectionToString(particles) + "]");
                    int result = CHILD_OCCURRENCE_EMPTY;
                    for (int i = 0; i < particles.getLength(); i++) {
                        XSParticle childParticle = (XSParticle) particles.item(i);
                        int current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
                        if (DEBUG)
                            log.debug("determineIsParentOfSingleMultipleOccurringChildElement() sequence or all, particle [" + i + "] current result [" + CHILD_OCCURRENCE_DESCRIPTION[current] + "]");
                        switch(current) {
                            case CHILD_OCCURRENCE_EMPTY:
                                break;
                            case CHILD_OCCURRENCE_ONE_SINGLE_OCCURRING_ELEMENT:
                            case CHILD_OCCURRENCE_ONE_MULTIPLE_OCCURRING_ELEMENT:
                                if (result > CHILD_OCCURRENCE_EMPTY) {
                                    if (DEBUG)
                                        log.debug("determineIsParentOfSingleMultipleOccurringChildElement() sequence or all, result [" + CHILD_OCCURRENCE_DESCRIPTION[result] + "] current [" + CHILD_OCCURRENCE_DESCRIPTION[current] + "]");
                                    return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                                }
                                result = current;
                                break;
                            case CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING:
                                return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                            default:
                                throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement child occurrence [" + CHILD_OCCURRENCE_DESCRIPTION[current] + "]");
                        }
                    }
                    if (DEBUG)
                        log.debug("determineIsParentOfSingleMultipleOccurringChildElement() end of sequence or all, returning [" + CHILD_OCCURRENCE_DESCRIPTION[result] + "]");
                    return result;
                }
            case XSModelGroup.COMPOSITOR_CHOICE:
                {
                    if (DEBUG)
                        log.debug("determineIsParentOfSingleMultipleOccurringChildElement() choice particles [" + ToStringBuilder.reflectionToString(particles) + "]");
                    if (particles.getLength() == 0) {
                        if (DEBUG)
                            log.debug("determineIsParentOfSingleMultipleOccurringChildElement() choice length 0, returning [" + CHILD_OCCURRENCE_DESCRIPTION[CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING] + "]");
                        return CHILD_OCCURRENCE_EMPTY;
                    }
                    int result = determineIsParentOfSingleMultipleOccurringChildElement((XSParticle) particles.item(0));
                    if (result == CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING) {
                        if (DEBUG)
                            log.debug("determineIsParentOfSingleMultipleOccurringChildElement() choice single mixed, returning [" + CHILD_OCCURRENCE_DESCRIPTION[CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING] + "]");
                        return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                    }
                    for (int i = 1; i < particles.getLength(); i++) {
                        XSParticle childParticle = (XSParticle) particles.item(i);
                        int current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
                        if (current != result) {
                            if (DEBUG)
                                log.debug("determineIsParentOfSingleMultipleOccurringChildElement() break out of choice, returning [" + CHILD_OCCURRENCE_DESCRIPTION[CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING] + "]");
                            return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                        }
                    }
                    if (DEBUG)
                        log.debug("determineIsParentOfSingleMultipleOccurringChildElement() end of choice, returning [" + CHILD_OCCURRENCE_DESCRIPTION[result] + "]");
                    return result;
                }
            default:
                throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement modelGroup.compositor is not COMPOSITOR_SEQUENCE, COMPOSITOR_ALL or COMPOSITOR_CHOICE, but [" + compositor + "]");
        }
    }
    if (term instanceof XSElementDeclaration) {
        XSElementDeclaration elementDeclaration = (XSElementDeclaration) term;
        String elementName = elementDeclaration.getName();
        if (DEBUG)
            log.debug("determineIsParentOfSingleMultipleOccurringChildElement() ElementDeclaration name [" + elementName + "] unbounded [" + particle.getMaxOccursUnbounded() + "] maxOccurs [" + particle.getMaxOccurs() + "]");
        if (particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1) {
            return CHILD_OCCURRENCE_ONE_MULTIPLE_OCCURRING_ELEMENT;
        }
        if (particle.getMaxOccurs() == 1) {
            return CHILD_OCCURRENCE_ONE_SINGLE_OCCURRING_ELEMENT;
        }
        return CHILD_OCCURRENCE_EMPTY;
    }
    if (term instanceof XSWildcard) {
        return CHILD_OCCURRENCE_MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
    }
    throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement unknown Term type [" + term.getClass().getName() + "]");
}
Also used : XSObjectList(org.apache.xerces.xs.XSObjectList) XSTerm(org.apache.xerces.xs.XSTerm) XSParticle(org.apache.xerces.xs.XSParticle) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) XSWildcard(org.apache.xerces.xs.XSWildcard) XSModelGroup(org.apache.xerces.xs.XSModelGroup)

Example 12 with XSElementDeclaration

use of org.apache.xerces.xs.XSElementDeclaration in project iaf by ibissource.

the class XmlAligner method collectChildElements.

protected void collectChildElements(XSParticle particle, Set<String> elementNames) {
    if (particle == null) {
        log.warn("collectChildElements() particle is null, is this a problem?");
        return;
    }
    XSTerm term = particle.getTerm();
    if (term == null) {
        throw new IllegalStateException("collectChildElements particle.term is null");
    }
    if (term instanceof XSModelGroup) {
        XSModelGroup modelGroup = (XSModelGroup) term;
        XSObjectList particles = modelGroup.getParticles();
        for (int i = 0; i < particles.getLength(); i++) {
            XSParticle childParticle = (XSParticle) particles.item(i);
            collectChildElements(childParticle, elementNames);
        }
        return;
    }
    if (term instanceof XSElementDeclaration) {
        XSElementDeclaration elementDeclaration = (XSElementDeclaration) term;
        String elementName = elementDeclaration.getName();
        if (DEBUG)
            log.debug("collectChildElements() ElementDeclaration name [" + elementName + "]");
        elementNames.add(elementName);
    }
    return;
}
Also used : XSObjectList(org.apache.xerces.xs.XSObjectList) XSTerm(org.apache.xerces.xs.XSTerm) XSParticle(org.apache.xerces.xs.XSParticle) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) XSModelGroup(org.apache.xerces.xs.XSModelGroup)

Aggregations

XSElementDeclaration (org.apache.xerces.xs.XSElementDeclaration)12 XSModel (org.apache.xerces.xs.XSModel)5 XSParticle (org.apache.xerces.xs.XSParticle)5 CMBuilder (org.apache.xerces.impl.xs.models.CMBuilder)4 CMNodeFactory (org.apache.xerces.impl.xs.models.CMNodeFactory)4 XSCMValidator (org.apache.xerces.impl.xs.models.XSCMValidator)4 XSComplexTypeDefinition (org.apache.xerces.xs.XSComplexTypeDefinition)4 XSModelGroup (org.apache.xerces.xs.XSModelGroup)4 XSObjectList (org.apache.xerces.xs.XSObjectList)4 XSTerm (org.apache.xerces.xs.XSTerm)4 Vector (java.util.Vector)3 XSElementDecl (org.apache.xerces.impl.xs.XSElementDecl)3 XSTypeDefinition (org.apache.xerces.xs.XSTypeDefinition)3 SAXException (org.xml.sax.SAXException)3 XmlTag (com.intellij.psi.xml.XmlTag)2 XSWildcard (org.apache.xerces.xs.XSWildcard)2 Nullable (org.jetbrains.annotations.Nullable)2 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 XmlFile (com.intellij.psi.xml.XmlFile)1