Search in sources :

Example 11 with XmlComplexType

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

the class XmlSchemaInspectionTest method testInspectShipOrderSchemaFile.

@Test
public void testInspectShipOrderSchemaFile() throws Exception {
    File schemaFile = Paths.get("src/test/resources/inspect/ship-order-schema.xsd").toFile();
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument xmlDocument = service.inspectSchema(schemaFile);
    Assert.assertNotNull(xmlDocument);
    Assert.assertNotNull(xmlDocument.getFields());
    Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
    XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
    Assert.assertNotNull(root);
    Assert.assertThat(root.getXmlFields().getXmlField().size(), Is.is(4));
    // @orderId
    XmlField orderIdAttr = root.getXmlFields().getXmlField().get(0);
    Assert.assertNotNull(orderIdAttr);
    Assert.assertThat(orderIdAttr.getName(), Is.is("orderid"));
    Assert.assertThat(orderIdAttr.getValue(), Is.is("2"));
    Assert.assertThat(orderIdAttr.getPath(), Is.is("/shiporder/@orderid"));
    Assert.assertThat(orderIdAttr.getFieldType(), Is.is(FieldType.STRING));
    // orderperson
    XmlField orderPerson = root.getXmlFields().getXmlField().get(1);
    Assert.assertNotNull(orderPerson);
    Assert.assertThat(orderPerson.getName(), Is.is("orderperson"));
    Assert.assertNull(orderPerson.getValue());
    Assert.assertThat(orderPerson.getPath(), Is.is("/shiporder/orderperson"));
    Assert.assertThat(orderPerson.getFieldType(), Is.is(FieldType.STRING));
    // shipTo
    XmlField shipTo = root.getXmlFields().getXmlField().get(2);
    Assert.assertNotNull(shipTo);
    Assert.assertTrue(shipTo instanceof XmlComplexType);
    Assert.assertThat(((XmlComplexType) shipTo).getXmlFields().getXmlField().size(), Is.is(4));
    // item
    XmlField item = root.getXmlFields().getXmlField().get(3);
    Assert.assertNotNull(item);
    Assert.assertTrue(item instanceof XmlComplexType);
    Assert.assertThat(((XmlComplexType) item).getXmlFields().getXmlField().size(), Is.is(4));
// debugFields(xmlDocument.getFields());
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) Test(org.junit.Test)

Example 12 with XmlComplexType

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

the class XmlComplexTypeFactory method createXmlComlexField.

public static XmlComplexType createXmlComlexField() {
    XmlComplexType xmlComplexField = new XmlComplexType();
    xmlComplexField.setFieldType(FieldType.COMPLEX);
    return xmlComplexField;
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType)

Example 13 with XmlComplexType

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

the class InstanceInspector method mapNodeToXmlField.

private void mapNodeToXmlField(Node node, XmlComplexType parentComplexType) {
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    StringBuffer sb = new StringBuffer(1024);
    getXmlPath(node, sb);
    xmlField.setPath(sb.toString());
    xmlField.setValue(node.getTextContent());
    xmlField.setFieldType(FieldType.STRING);
    xmlField.setName(node.getNodeName());
    xmlField.setStatus(FieldStatus.SUPPORTED);
    parentComplexType.getXmlFields().getXmlField().add(xmlField);
}
Also used : XmlField(io.atlasmap.xml.v2.XmlField)

Example 14 with XmlComplexType

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

the class SchemaInspector method printSchemaSet.

private void printSchemaSet(XSSchemaSet schemaSet) throws Exception {
    if (schemaSet == null) {
        throw new XmlInspectionException("Schema set is null");
    }
    XSSchema schema = rootNamespace != null ? schemaSet.getSchema(rootNamespace) : schemaSet.getSchema("");
    // we only care about declared elements...
    Iterator<XSElementDecl> jtr = schema.iterateElementDecls();
    while (jtr.hasNext()) {
        XSElementDecl e = jtr.next();
        String rootName = getNameNS(e);
        if (e.getType().isComplexType()) {
            XmlComplexType rootComplexType = getXmlComplexType();
            rootComplexType.setName(rootName);
            rootComplexType.setPath("/" + rootName);
            rootComplexType.setFieldType(FieldType.COMPLEX);
            xmlDocument.getFields().getField().add(rootComplexType);
            printComplexType(e.getType().asComplexType(), "/" + rootName, rootComplexType);
        } else if (e.getType().isSimpleType()) {
            XmlField xmlField = AtlasXmlModelFactory.createXmlField();
            xmlField.setName(rootName);
            xmlField.setPath("/" + rootName);
            xmlDocument.getFields().getField().add(xmlField);
            printSimpleType(e.getType().asSimpleType(), xmlField);
        }
    }
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlField(io.atlasmap.xml.v2.XmlField) XSElementDecl(com.sun.xml.xsom.XSElementDecl) XSSchema(com.sun.xml.xsom.XSSchema)

Example 15 with XmlComplexType

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

the class XmlSchemaInspectionMultipleNamespacesTest method testMultipleNamespaces.

@Test
public void testMultipleNamespaces() throws Exception {
    File schemaFile = Paths.get("src/test/resources/inspect/multiple-namespaces-schemaset.xml").toFile();
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument answer = service.inspectSchema(schemaFile);
    Assert.assertEquals(3, answer.getXmlNamespaces().getXmlNamespace().size());
    for (XmlNamespace namespace : answer.getXmlNamespaces().getXmlNamespace()) {
        switch(namespace.getAlias()) {
            case "tns":
                Assert.assertEquals("io.atlasmap.xml.test:Root", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            case "first":
                Assert.assertEquals("io.atlasmap.xml.test:First", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            case "second":
                Assert.assertEquals("io.atlasmap.xml.test:Second", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            default:
                Assert.fail(String.format("Unknown alias '%s'", namespace.getAlias()));
        }
    }
    List<Field> fields = answer.getFields().getField();
    Assert.assertEquals(1, fields.size());
    XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
    Assert.assertEquals("tns:RootDocument", complex.getName());
    List<XmlField> rootFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(4, rootFields.size());
    for (XmlField xmlField : rootFields) {
        switch(xmlField.getName()) {
            case "tns:Name":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/tns:Name", xmlField.getPath());
                break;
            case "tns:Value":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/tns:Value", xmlField.getPath());
                break;
            case "first:FirstElement":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/first:FirstElement", xmlField.getPath());
                List<XmlField> firstFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, firstFields.size());
                for (XmlField firstField : firstFields) {
                    switch(firstField.getName()) {
                        case "first:Name":
                            Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Name", firstField.getPath());
                            break;
                        case "first:Value":
                            Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Value", firstField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", firstField.getPath()));
                    }
                }
                break;
            case "second:SecondElement":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/second:SecondElement", xmlField.getPath());
                List<XmlField> secondFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, secondFields.size());
                for (XmlField secondField : secondFields) {
                    switch(secondField.getName()) {
                        case "second:Name":
                            Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Name", secondField.getPath());
                            break;
                        case "second:Value":
                            Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Value", secondField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", secondField.getPath()));
                    }
                }
                break;
            default:
                Assert.fail(String.format("Unknown field '%s'", xmlField.getPath()));
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) Test(org.junit.Test)

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