use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentWithMultipleNamespaceComplex.
@Test
public void testReadDocumentWithMultipleNamespaceComplex() throws Exception {
String doc = getDocumentString("src/test/resources/complex_example_ns.xml");
reader.setDocument(doc, true);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setPath("/orders/order[2]/id[1]/@y:custId");
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("b"));
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadDocumentSetAttributeValueComplex.
@Test
public void testReadDocumentSetAttributeValueComplex() throws Exception {
String doc = getDocumentString("src/test/resources/complex_example.xml");
reader.setDocument(doc, false);
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setPath("/orders/order[2]/id[1]/@custId");
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("b"));
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class SchemaInspector method printElement.
private void printElement(XSElementDecl element, String root, XmlComplexType xmlComplexType, CollectionType collectionType) throws Exception {
String rootName = root;
if (element.getType().isComplexType()) {
XmlComplexType complexType = getXmlComplexType();
rootName = rootName + "/" + getNameNS(element);
complexType.setName(getNameNS(element));
complexType.setPath(rootName);
complexType.setCollectionType(collectionType);
xmlComplexType.getXmlFields().getXmlField().add(complexType);
printComplexType(element.getType().asComplexType(), rootName, complexType);
} else {
if (element.getType() != null && element.getType().asSimpleType() != null) {
XmlField xmlField = AtlasXmlModelFactory.createXmlField();
xmlField.setName(getNameNS(element));
xmlField.setPath(rootName + "/" + getNameNS(element));
xmlComplexType.getXmlFields().getXmlField().add(xmlField);
if (element.getDefaultValue() != null) {
xmlField.setValue(element.getDefaultValue());
} else if (element.getFixedValue() != null) {
xmlField.setValue(element.getFixedValue());
}
XSRestrictionSimpleType typeRestriction = element.getType().asSimpleType().asRestriction();
if (typeRestriction != null) {
xmlField.setFieldType(XS_TYPE_TO_FIELD_TYPE_MAP.get(typeRestriction.getBaseType().getName()));
mapRestrictions(xmlField, typeRestriction);
}
printSimpleType(element.getType().asSimpleType(), xmlField);
}
}
}
use of io.atlasmap.xml.v2.XmlField 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);
}
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class SchemaInspector method mapSimpleRestrictionToRestriction.
private void mapSimpleRestrictionToRestriction(SimpleTypeRestriction simpleTypeRestriction, XmlField xmlField) {
for (Field field : SimpleTypeRestriction.class.getDeclaredFields()) {
field.setAccessible(true);
try {
// do we even care about this restriction?
if (typeRestrictionExists(field.getName())) {
Object value = field.get(simpleTypeRestriction);
if (value != null) {
Restriction restriction = new Restriction();
restriction.setValue((String) value);
restriction.setType(RestrictionType.fromValue(field.getName()));
xmlField.getRestrictions().getRestriction().add(restriction);
}
}
} catch (IllegalAccessException e) {
// eat it...
}
}
}
Aggregations