use of io.atlasmap.xml.v2.XmlField 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.XmlField 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.XmlField in project atlasmap by atlasmap.
the class SchemaInspector method mapRestrictions.
private void mapRestrictions(XmlField xmlField, XSRestrictionSimpleType restrictionSimpleType) {
SimpleTypeRestriction simpleTypeRestriction = new SimpleTypeRestriction();
simpleTypeRestriction.initRestrictions(restrictionSimpleType);
Restrictions restrictions = new Restrictions();
xmlField.setRestrictions(restrictions);
mapSimpleRestrictionToRestriction(simpleTypeRestriction, xmlField);
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentMixedNamespacesNoNSDocument.
@Test
public void testReadDocumentMixedNamespacesNoNSDocument() throws Exception {
String doc = getDocumentString("src/test/resources/simple_example.xml");
reader.setDocument(doc, false);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
// there is no namespace on the document but there is this field....
xmlField.setPath("/ns:orders/order/id");
assertNull(xmlField.getValue());
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(xmlField);
reader.read(session);
assertNotNull(xmlField.getValue());
assertThat(xmlField.getValue(), is("12312"));
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentElementWithMultipleNamespaceComplex.
@Test
public void testReadDocumentElementWithMultipleNamespaceComplex() throws Exception {
String doc = getDocumentString("src/test/resources/complex_example_multiple_ns.xml");
reader.setDocument(doc, true);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setPath("/orders/q:order/id/@y:custId");
assertNull(xmlField.getValue());
Map<String, String> namespaces = new LinkedHashMap<>();
namespaces.put("http://www.example.com/q/", "q");
namespaces.put("http://www.example.com/y/", "y");
namespaces.put("http://www.example.com/x/", "");
reader.setNamespaces(namespaces);
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(xmlField);
reader.read(session);
assertNotNull(xmlField.getValue());
assertThat(xmlField.getValue(), is("cx"));
XmlField xmlField2 = AtlasXmlModelFactory.createXmlField();
xmlField2.setPath("/orders/order/id/@y:custId");
assertNull(xmlField2.getValue());
when(session.head().getSourceField()).thenReturn(xmlField2);
reader.read(session);
assertNotNull(xmlField2.getValue());
assertThat(xmlField2.getValue(), is("aa"));
XmlField xmlField3 = AtlasXmlModelFactory.createXmlField();
xmlField3.setPath("/orders/q:order[1]/id/@y:custId");
assertNull(xmlField3.getValue());
when(session.head().getSourceField()).thenReturn(xmlField3);
reader.read(session);
assertNotNull(xmlField3.getValue());
assertThat(xmlField3.getValue(), is("ea"));
}
Aggregations