Search in sources :

Example 6 with XSTerm

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

the class XmlAligner method determineIsParentOfSingleMultipleOccurringChildElement.

protected ChildOccurrence determineIsParentOfSingleMultipleOccurringChildElement(XSParticle particle) {
    if (particle == null) {
        log.warn("Particle is null, is this a problem? Appearantly not");
        return ChildOccurrence.EMPTY;
    }
    XSTerm term = particle.getTerm();
    if (term == null) {
        throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement particle.term is null");
    }
    if (log.isTraceEnabled())
        log.trace("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 (log.isTraceEnabled())
                        log.trace("sequence or all particles [" + ToStringBuilder.reflectionToString(particles) + "]");
                    ChildOccurrence result = ChildOccurrence.EMPTY;
                    for (int i = 0; i < particles.getLength(); i++) {
                        XSParticle childParticle = (XSParticle) particles.item(i);
                        ChildOccurrence current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
                        if (log.isTraceEnabled())
                            log.trace("sequence or all, particle [" + i + "] current result [" + current + "]");
                        switch(current) {
                            case EMPTY:
                                break;
                            case ONE_SINGLE_OCCURRING_ELEMENT:
                            case ONE_MULTIPLE_OCCURRING_ELEMENT:
                                if (result.ordinal() > ChildOccurrence.EMPTY.ordinal()) {
                                    if (log.isTraceEnabled())
                                        log.trace("sequence or all, result [" + result + "] current [" + current + "]");
                                    return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                                }
                                result = current;
                                break;
                            case MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING:
                                return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                            default:
                                throw new IllegalStateException("determineIsParentOfSingleMultipleOccurringChildElement child occurrence [" + current + "]");
                        }
                    }
                    if (log.isTraceEnabled())
                        log.trace("end of sequence or all, returning [" + result + "]");
                    return result;
                }
            case XSModelGroup.COMPOSITOR_CHOICE:
                {
                    if (log.isTraceEnabled())
                        log.trace("choice particles [" + ToStringBuilder.reflectionToString(particles) + "]");
                    if (particles.getLength() == 0) {
                        if (log.isTraceEnabled())
                            log.trace("choice length 0, returning [" + ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING + "]");
                        return ChildOccurrence.EMPTY;
                    }
                    ChildOccurrence result = determineIsParentOfSingleMultipleOccurringChildElement((XSParticle) particles.item(0));
                    if (result == ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING) {
                        if (log.isTraceEnabled())
                            log.trace("choice single mixed, returning [" + ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING + "]");
                        return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                    }
                    for (int i = 1; i < particles.getLength(); i++) {
                        XSParticle childParticle = (XSParticle) particles.item(i);
                        ChildOccurrence current = determineIsParentOfSingleMultipleOccurringChildElement(childParticle);
                        if (current != result) {
                            if (log.isTraceEnabled())
                                log.trace("break out of choice, returning [" + ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING + "]");
                            return ChildOccurrence.MULTIPLE_ELEMENTS_OR_NOT_MULTIPLE_OCCURRING;
                        }
                    }
                    if (log.isTraceEnabled())
                        log.trace("end of choice, returning [" + 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 (log.isTraceEnabled())
            log.trace("ElementDeclaration name [" + elementName + "] unbounded [" + particle.getMaxOccursUnbounded() + "] maxOccurs [" + particle.getMaxOccurs() + "]");
        if (particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1) {
            return ChildOccurrence.ONE_MULTIPLE_OCCURRING_ELEMENT;
        }
        if (particle.getMaxOccurs() == 1) {
            return ChildOccurrence.ONE_SINGLE_OCCURRING_ELEMENT;
        }
        return ChildOccurrence.EMPTY;
    }
    if (term instanceof XSWildcard) {
        return ChildOccurrence.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 7 with XSTerm

use of org.apache.xerces.xs.XSTerm 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 (log.isTraceEnabled())
            log.trace("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)

Example 8 with XSTerm

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

the class XmlTypeToJsonSchemaConverter method buildSkippableArrayContainer.

private void buildSkippableArrayContainer(XSParticle childParticle, JsonObjectBuilder builder) {
    JsonObjectBuilder refBuilder = Json.createObjectBuilder();
    handleParticle(refBuilder, childParticle, null, false);
    XSTerm childTerm = childParticle.getTerm();
    if (childTerm instanceof XSElementDeclaration) {
        XSElementDeclaration elementDeclaration = (XSElementDeclaration) childTerm;
        XSTypeDefinition elementTypeDefinition = elementDeclaration.getTypeDefinition();
        JsonStructure definition = getDefinition(elementTypeDefinition, true);
        builder.add("type", "array");
        if (elementDeclaration.getNillable()) {
            definition = nillable(definition);
        }
        builder.add("items", definition);
    }
}
Also used : XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) XSTerm(org.apache.xerces.xs.XSTerm) XSElementDeclaration(org.apache.xerces.xs.XSElementDeclaration) JsonObjectBuilder(javax.json.JsonObjectBuilder) JsonStructure(javax.json.JsonStructure)

Example 9 with XSTerm

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

the class XmlAligner method findMultipleOccurringChildElements.

protected Set<String> findMultipleOccurringChildElements(XSParticle particle) {
    Set<String> result = new HashSet<String>();
    if (particle == null) {
        log.warn("typeDefinition particle is null, is this a problem?");
        return result;
    }
    XSTerm term = particle.getTerm();
    if (term == null) {
        throw new IllegalStateException("findMultipleOccurringChildElements particle.term is null");
    }
    if (log.isTraceEnabled())
        log.trace("term name [" + term.getName() + "] occurring unbounded [" + particle.getMaxOccursUnbounded() + "] max occur [" + particle.getMaxOccurs() + "] term [" + ToStringBuilder.reflectionToString(term) + "]");
    if (particle.getMaxOccursUnbounded() || particle.getMaxOccurs() > 1) {
        collectChildElements(particle, result);
        return result;
    }
    if (term instanceof XSModelGroup) {
        XSModelGroup modelGroup = (XSModelGroup) term;
        XSObjectList particles = modelGroup.getParticles();
        if (log.isTraceEnabled())
            log.trace("modelGroup particles [" + ToStringBuilder.reflectionToString(particles) + "]");
        for (int i = 0; i < particles.getLength(); i++) {
            XSParticle childParticle = (XSParticle) particles.item(i);
            result.addAll(findMultipleOccurringChildElements(childParticle));
        }
    }
    return result;
}
Also used : XSObjectList(org.apache.xerces.xs.XSObjectList) XSTerm(org.apache.xerces.xs.XSTerm) XSParticle(org.apache.xerces.xs.XSParticle) HashSet(java.util.HashSet) XSModelGroup(org.apache.xerces.xs.XSModelGroup)

Aggregations

XSTerm (org.apache.xerces.xs.XSTerm)9 XSElementDeclaration (org.apache.xerces.xs.XSElementDeclaration)7 XSParticle (org.apache.xerces.xs.XSParticle)7 XSModelGroup (org.apache.xerces.xs.XSModelGroup)6 XSObjectList (org.apache.xerces.xs.XSObjectList)6 XSTypeDefinition (org.apache.xerces.xs.XSTypeDefinition)3 ArrayList (java.util.ArrayList)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 QName (javax.xml.namespace.QName)2 XSSimpleType (org.apache.xerces.impl.dv.XSSimpleType)2 XSComplexTypeDefinition (org.apache.xerces.xs.XSComplexTypeDefinition)2 XSModel (org.apache.xerces.xs.XSModel)2 XSWildcard (org.apache.xerces.xs.XSWildcard)2 HasTargetNamespace (org.eclipse.winery.model.tosca.HasTargetNamespace)2 XsdImportManager (org.eclipse.winery.repository.backend.xsd.XsdImportManager)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObject (javax.json.JsonObject)1