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());
}
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;
}
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);
}
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);
}
}
}
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()));
}
}
}
Aggregations