Search in sources :

Example 11 with XSTypeDefinition

use of org.apache.xerces.xs.XSTypeDefinition 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 12 with XSTypeDefinition

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

the class XmlTo method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
    boolean xmlArrayContainer = aligner.isParentOfSingleMultipleOccurringChildElement();
    boolean repeatedElement = aligner.isMultipleOccurringChildInParentElement(localName);
    XSTypeDefinition typeDefinition = aligner.getTypeDefinition();
    if (!localName.equals(topElement)) {
        if (topElement != null) {
            if (log.isTraceEnabled())
                log.trace("endElementGroup [" + topElement + "]");
            documentContainer.endElementGroup(topElement);
        }
        if (log.isTraceEnabled())
            log.trace("startElementGroup [" + localName + "]");
        documentContainer.startElementGroup(localName, xmlArrayContainer, repeatedElement, typeDefinition);
        topElement = localName;
    }
    element.push(topElement);
    topElement = null;
    if (log.isTraceEnabled())
        log.trace("startElement [" + localName + "] xml array container [" + aligner.isParentOfSingleMultipleOccurringChildElement() + "] repeated element [" + aligner.isMultipleOccurringChildInParentElement(localName) + "]");
    documentContainer.startElement(localName, xmlArrayContainer, repeatedElement, typeDefinition);
    super.startElement(uri, localName, qName, atts);
    if (aligner.isNil(atts)) {
        documentContainer.setNull();
    } else {
        if (writeAttributes) {
            XSObjectList attributeUses = aligner.getAttributeUses();
            XSWildcard wildcard = typeDefinition instanceof XSComplexTypeDefinition ? ((XSComplexTypeDefinition) typeDefinition).getAttributeWildcard() : null;
            if (attributeUses == null && wildcard == null) {
                if (atts.getLength() > 0) {
                    log.warn("found [" + atts.getLength() + "] attributes, but no declared AttributeUses");
                }
            } else {
                if (wildcard != null) {
                    // if wildcard (xs:anyAttribute namespace="##any" processContents="lax") is present, then any attribute will be parsed
                    for (int i = 0; i < atts.getLength(); i++) {
                        String name = atts.getLocalName(i);
                        String namespace = atts.getURI(i);
                        String value = atts.getValue(i);
                        XSSimpleTypeDefinition attTypeDefinition = findAttributeTypeDefinition(attributeUses, namespace, name);
                        if (log.isTraceEnabled())
                            log.trace("startElement [" + localName + "] attribute [" + namespace + ":" + name + "] value [" + value + "]");
                        if (StringUtils.isNotEmpty(value)) {
                            documentContainer.setAttribute(name, value, attTypeDefinition);
                        }
                    }
                } else {
                    // if no wildcard is found, then only declared attributes will be parsed
                    for (int i = 0; i < attributeUses.getLength(); i++) {
                        XSAttributeUse attributeUse = (XSAttributeUse) attributeUses.item(i);
                        XSAttributeDeclaration attributeDeclaration = attributeUse.getAttrDeclaration();
                        XSSimpleTypeDefinition attTypeDefinition = attributeDeclaration.getTypeDefinition();
                        String attName = attributeDeclaration.getName();
                        String attNS = attributeDeclaration.getNamespace();
                        if (log.isTraceEnabled())
                            log.trace("startElement [" + localName + "] searching attribute [" + attNS + ":" + attName + "]");
                        int attIndex = attNS != null ? atts.getIndex(attNS, attName) : atts.getIndex(attName);
                        if (attIndex >= 0) {
                            String value = atts.getValue(attIndex);
                            if (log.isTraceEnabled())
                                log.trace("startElement [" + localName + "] attribute [" + attNS + ":" + attName + "] value [" + value + "]");
                            if (StringUtils.isNotEmpty(value)) {
                                documentContainer.setAttribute(attName, value, attTypeDefinition);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : XSTypeDefinition(org.apache.xerces.xs.XSTypeDefinition) XSObjectList(org.apache.xerces.xs.XSObjectList) XSAttributeDeclaration(org.apache.xerces.xs.XSAttributeDeclaration) XSAttributeUse(org.apache.xerces.xs.XSAttributeUse) XSWildcard(org.apache.xerces.xs.XSWildcard) XSComplexTypeDefinition(org.apache.xerces.xs.XSComplexTypeDefinition) XSSimpleTypeDefinition(org.apache.xerces.xs.XSSimpleTypeDefinition)

Aggregations

XSTypeDefinition (org.apache.xerces.xs.XSTypeDefinition)12 XSComplexTypeDefinition (org.apache.xerces.xs.XSComplexTypeDefinition)6 XSElementDeclaration (org.apache.xerces.xs.XSElementDeclaration)6 XSObjectList (org.apache.xerces.xs.XSObjectList)4 JsonObjectBuilder (javax.json.JsonObjectBuilder)3 XSModel (org.apache.xerces.xs.XSModel)3 XSParticle (org.apache.xerces.xs.XSParticle)3 XSTerm (org.apache.xerces.xs.XSTerm)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 JsonStructure (javax.json.JsonStructure)2 QName (javax.xml.namespace.QName)2 XSSimpleType (org.apache.xerces.impl.dv.XSSimpleType)2 ElementPSVI (org.apache.xerces.xs.ElementPSVI)2 XSAttributeDeclaration (org.apache.xerces.xs.XSAttributeDeclaration)2 XSAttributeUse (org.apache.xerces.xs.XSAttributeUse)2 XSModelGroup (org.apache.xerces.xs.XSModelGroup)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