Search in sources :

Example 26 with XmlComplexType

use of io.atlasmap.xml.v2.XmlComplexType in project atlasmap by atlasmap.

the class SchemaInspector method printAttributes.

private void printAttributes(XSComplexType xsComplexType, String rootName, XmlComplexType xmlComplexType) {
    Collection<? extends XSAttributeUse> c = xsComplexType.getDeclaredAttributeUses();
    for (XSAttributeUse aC : c) {
        XmlField xmlField = AtlasXmlModelFactory.createXmlField();
        XSAttributeDecl attributeDecl = aC.getDecl();
        xmlField.setName(getNameNS(attributeDecl));
        if (attributeDecl.getDefaultValue() != null) {
            xmlField.setValue(attributeDecl.getDefaultValue().value);
        } else if (attributeDecl.getFixedValue() != null) {
            xmlField.setValue(attributeDecl.getFixedValue().value);
        }
        xmlField.setPath(rootName + "/" + "@" + getNameNS(attributeDecl));
        FieldType attrType = getFieldType(attributeDecl.getType().getName());
        xmlField.setFieldType(attrType);
        if (xmlField.getFieldType() == null) {
            // check the simple types in the schema....
            XSSimpleType simpleType = xsComplexType.getRoot().getSimpleType(xsComplexType.getTargetNamespace(), attributeDecl.getType().getName());
            if (simpleType != null) {
                FieldType fieldType = getFieldType(simpleType.getBaseType().getName());
                xmlField.setFieldType(fieldType);
                xmlField.setTypeName(attributeDecl.getType().getName());
                if (simpleType.asRestriction() != null) {
                    mapRestrictions(xmlField, simpleType.asRestriction());
                }
            } else {
                // cannot figure it out....
                xmlField.setFieldType(FieldType.UNSUPPORTED);
            }
        }
        xmlComplexType.getXmlFields().getXmlField().add(xmlField);
    }
}
Also used : XSSimpleType(com.sun.xml.xsom.XSSimpleType) XmlField(io.atlasmap.xml.v2.XmlField) XSAttributeDecl(com.sun.xml.xsom.XSAttributeDecl) XSAttributeUse(com.sun.xml.xsom.XSAttributeUse) FieldType(io.atlasmap.v2.FieldType)

Example 27 with XmlComplexType

use of io.atlasmap.xml.v2.XmlComplexType in project atlasmap by atlasmap.

the class SchemaInspector method getXmlComplexType.

private XmlComplexType getXmlComplexType() {
    XmlComplexType rootComplexType = XmlComplexTypeFactory.createXmlComlexField();
    rootComplexType.setFieldType(FieldType.COMPLEX);
    rootComplexType.setXmlFields(new XmlFields());
    return rootComplexType;
}
Also used : XmlFields(io.atlasmap.xml.v2.XmlFields) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType)

Example 28 with XmlComplexType

use of io.atlasmap.xml.v2.XmlComplexType in project atlasmap by atlasmap.

the class InstanceInspector method getXmlComplexType.

private XmlComplexType getXmlComplexType(Node childNode) {
    XmlComplexType childComplexType = XmlComplexTypeFactory.createXmlComlexField();
    childComplexType.setXmlFields(new XmlFields());
    childComplexType.setName(childNode.getNodeName());
    StringBuffer stringBuffer = new StringBuffer();
    getXmlPath(childNode, stringBuffer);
    childComplexType.setPath(stringBuffer.toString());
    return childComplexType;
}
Also used : XmlFields(io.atlasmap.xml.v2.XmlFields) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType)

Example 29 with XmlComplexType

use of io.atlasmap.xml.v2.XmlComplexType in project atlasmap by atlasmap.

the class InstanceInspector method mapParentNode.

private void mapParentNode(Node node, XmlComplexType parent) {
    if (node.hasChildNodes()) {
        NodeList childNodes = node.getChildNodes();
        XmlComplexType childParent = getXmlComplexType(node);
        StringBuffer stringBuffer = new StringBuffer();
        getXmlPath(node, stringBuffer);
        if (node.hasAttributes()) {
            mapAttributes(node, childParent);
        }
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node e = childNodes.item(i);
            if (e.getNodeType() == Node.ELEMENT_NODE) {
                // do we have child elements?
                NodeList childElements = ((Element) e).getElementsByTagName("*");
                if (childElements.getLength() > 0) {
                    mapParentNode(e, childParent);
                } else {
                    mapNodeToXmlField(e, childParent);
                    if (e.hasAttributes()) {
                        mapAttributes(e, childParent);
                    }
                }
            }
        }
        mapCollectionType(childParent, (Element) node);
        parent.getXmlFields().getXmlField().add(childParent);
    }
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 30 with XmlComplexType

use of io.atlasmap.xml.v2.XmlComplexType in project atlasmap by atlasmap.

the class InstanceInspector method parseDocument.

private void parseDocument(Node rootNode) {
    if (rootNode.getParentNode() != null && rootNode.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
        XmlComplexType rootComplexType = getXmlComplexType(rootNode);
        xmlDocument.getFields().getField().add(rootComplexType);
        mapAttributes(rootNode, rootComplexType);
        if (rootNode.hasChildNodes()) {
            mapChildNodes(rootNode.getChildNodes(), rootComplexType);
        }
    }
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType)

Aggregations

XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)28 XmlDocument (io.atlasmap.xml.v2.XmlDocument)20 Test (org.junit.Test)20 XmlField (io.atlasmap.xml.v2.XmlField)13 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)9 File (java.io.File)8 Field (io.atlasmap.v2.Field)3 XmlFields (io.atlasmap.xml.v2.XmlFields)2 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)1 XSAttributeUse (com.sun.xml.xsom.XSAttributeUse)1 XSElementDecl (com.sun.xml.xsom.XSElementDecl)1 XSRestrictionSimpleType (com.sun.xml.xsom.XSRestrictionSimpleType)1 XSSchema (com.sun.xml.xsom.XSSchema)1 XSSimpleType (com.sun.xml.xsom.XSSimpleType)1 FieldType (io.atlasmap.v2.FieldType)1 Restriction (io.atlasmap.xml.v2.Restriction)1 XmlInspectionRequest (io.atlasmap.xml.v2.XmlInspectionRequest)1 XmlInspectionResponse (io.atlasmap.xml.v2.XmlInspectionResponse)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1