Search in sources :

Example 16 with XmlField

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);
}
Also used : XmlField(io.atlasmap.xml.v2.XmlField)

Example 17 with 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);
        }
    }
}
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 18 with 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);
}
Also used : Restrictions(io.atlasmap.xml.v2.Restrictions)

Example 19 with 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"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 20 with XmlField

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"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

XmlField (io.atlasmap.xml.v2.XmlField)46 Test (org.junit.Test)31 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)21 Head (io.atlasmap.spi.AtlasInternalSession.Head)21 XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)11 XmlDocument (io.atlasmap.xml.v2.XmlDocument)8 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 Mapping (io.atlasmap.v2.Mapping)7 Field (io.atlasmap.v2.Field)6 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)6 File (java.io.File)6 Validation (io.atlasmap.v2.Validation)4 FieldType (io.atlasmap.v2.FieldType)3 Restriction (io.atlasmap.xml.v2.Restriction)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)2 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)2