use of io.atlasmap.xml.v2.Restriction in project atlasmap by atlasmap.
the class BaseXmlInspectionServiceTest method printXmlField.
protected void printXmlField(XmlField xmlField) {
System.out.println("Name --> " + xmlField.getName());
System.out.println("Path --> " + xmlField.getPath());
System.out.println("Attribute? --> " + xmlField.isAttribute());
System.out.println("Value --> " + xmlField.getValue());
if (xmlField.getFieldType() != null) {
System.out.println("Type --> " + xmlField.getFieldType().name());
}
if (xmlField.getTypeName() != null) {
System.out.println("Type Name --> " + xmlField.getTypeName());
}
if (xmlField.getCollectionType() != null) {
System.out.println("Collection Type --> " + xmlField.getCollectionType().name());
}
if (xmlField.getRestrictions() != null && !xmlField.getRestrictions().getRestriction().isEmpty()) {
for (Restriction restriction : xmlField.getRestrictions().getRestriction()) {
if (restriction != null) {
System.out.println("Restriction Type--> " + restriction.getType());
System.out.println("Restriction Type Value--> " + restriction.getValue());
}
}
}
System.out.println();
}
use of io.atlasmap.xml.v2.Restriction in project atlasmap by atlasmap.
the class XmlSchemaInspector 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 instanceof String[]) {
String[] values = (String[]) value;
for (String v : values) {
Restriction restriction = new Restriction();
restriction.setValue(v.toString());
restriction.setType(RestrictionType.fromValue(field.getName()));
xmlField.getRestrictions().getRestriction().add(restriction);
}
} else if (value != null) {
Restriction restriction = new Restriction();
restriction.setValue(value.toString());
restriction.setType(RestrictionType.fromValue(field.getName()));
xmlField.getRestrictions().getRestriction().add(restriction);
}
}
} catch (IllegalAccessException e) {
// eat it...
}
}
}
use of io.atlasmap.xml.v2.Restriction 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...
}
}
}
use of io.atlasmap.xml.v2.Restriction in project atlasmap by atlasmap.
the class XmlSchemaInspectionTest method testInspectPOExampleSchemaFile.
@Test
public void testInspectPOExampleSchemaFile() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/po-example-schema.xsd").toFile();
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectSchema(schemaFile);
assertNotNull(xmlDocument);
assertNotNull(xmlDocument.getFields());
assertEquals(2, xmlDocument.getFields().getField().size());
// PurchaseOrderType
XmlComplexType purchaseOrder = (XmlComplexType) xmlDocument.getFields().getField().get(0);
assertNotNull(purchaseOrder);
assertEquals(5, purchaseOrder.getXmlFields().getXmlField().size());
// orderDate
XmlField orderDateAttr = purchaseOrder.getXmlFields().getXmlField().get(0);
assertNotNull(orderDateAttr);
assertEquals("orderDate", orderDateAttr.getName());
assertNull(orderDateAttr.getValue());
assertEquals("/tns:purchaseOrder/@orderDate", orderDateAttr.getPath());
assertEquals(FieldType.DATE, orderDateAttr.getFieldType());
assertEquals(true, orderDateAttr.isAttribute());
// shipTo
XmlField shipTo = purchaseOrder.getXmlFields().getXmlField().get(1);
assertNotNull(shipTo);
assertEquals("shipTo", shipTo.getName());
assertNull(shipTo.getValue());
assertEquals("/tns:purchaseOrder/shipTo", shipTo.getPath());
assertEquals(FieldType.COMPLEX, shipTo.getFieldType());
assertEquals(6, ((XmlComplexType) shipTo).getXmlFields().getXmlField().size());
// shipTo/@country
XmlField shipToCountry = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(0);
assertNotNull(shipTo);
assertEquals("country", shipToCountry.getName());
assertEquals("US", shipToCountry.getValue());
assertEquals("/tns:purchaseOrder/shipTo/@country", shipToCountry.getPath());
assertEquals(FieldType.STRING, shipToCountry.getFieldType());
assertEquals(true, shipToCountry.isAttribute());
XmlField shipToName = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(1);
assertNotNull(shipToName);
assertEquals("name", shipToName.getName());
assertNull(shipToName.getValue());
assertEquals("/tns:purchaseOrder/shipTo/name", shipToName.getPath());
assertEquals(FieldType.STRING, shipToName.getFieldType());
assertEquals(false, shipToName.isAttribute());
XmlField shipToStreet = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(2);
assertNotNull(shipToStreet);
assertEquals("street", shipToStreet.getName());
assertNull(shipToStreet.getValue());
assertEquals("/tns:purchaseOrder/shipTo/street", shipToStreet.getPath());
assertEquals(FieldType.STRING, shipToStreet.getFieldType());
assertEquals(false, shipToStreet.isAttribute());
XmlField shipToCity = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(3);
assertNotNull(shipToCity);
assertEquals("city", shipToCity.getName());
assertNull(shipToCity.getValue());
assertEquals("/tns:purchaseOrder/shipTo/city", shipToCity.getPath());
assertEquals(FieldType.STRING, shipToCity.getFieldType());
assertEquals(false, shipToCity.isAttribute());
XmlField shipToState = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(4);
assertNotNull(shipToState);
assertEquals("state", shipToState.getName());
assertNull(shipToState.getValue());
assertEquals("/tns:purchaseOrder/shipTo/state", shipToState.getPath());
assertEquals(FieldType.STRING, shipToState.getFieldType());
assertEquals(false, shipToState.isAttribute());
XmlField shipToZip = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(5);
assertNotNull(shipToZip);
assertEquals("zip", shipToZip.getName());
assertNull(shipToZip.getValue());
assertEquals("/tns:purchaseOrder/shipTo/zip", shipToZip.getPath());
assertEquals(FieldType.DECIMAL, shipToZip.getFieldType());
assertEquals(false, shipToZip.isAttribute());
// comment
XmlField comment = purchaseOrder.getXmlFields().getXmlField().get(3);
assertNotNull(comment);
assertEquals("tns:comment", comment.getName());
assertNull(comment.getValue());
assertEquals("/tns:purchaseOrder/tns:comment", comment.getPath());
assertEquals(FieldType.STRING, comment.getFieldType());
assertEquals(false, comment.isAttribute());
// items
XmlField items = purchaseOrder.getXmlFields().getXmlField().get(4);
assertNotNull(items);
assertEquals("items", items.getName());
assertNull(items.getValue());
assertEquals("/tns:purchaseOrder/items", items.getPath());
assertEquals(FieldType.COMPLEX, items.getFieldType());
assertEquals(false, items.isAttribute());
assertEquals(1, ((XmlComplexType) items).getXmlFields().getXmlField().size());
// items/item
XmlComplexType item = (XmlComplexType) ((XmlComplexType) items).getXmlFields().getXmlField().get(0);
assertNotNull(item);
assertEquals("item", item.getName());
assertNull(item.getValue());
assertEquals("/tns:purchaseOrder/items/item<>", item.getPath());
assertEquals(FieldType.COMPLEX, item.getFieldType());
assertEquals(false, item.isAttribute());
assertEquals(CollectionType.LIST, item.getCollectionType());
assertEquals(6, item.getXmlFields().getXmlField().size());
// partNum
XmlField partNum = item.getXmlFields().getXmlField().get(0);
assertNotNull(partNum);
assertEquals("partNum", partNum.getName());
assertNull(partNum.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/@partNum", partNum.getPath());
assertEquals(FieldType.STRING, partNum.getFieldType());
assertEquals("SKU", partNum.getTypeName());
assertEquals(true, partNum.isAttribute());
// productName
XmlField productName = item.getXmlFields().getXmlField().get(1);
assertNotNull(productName);
assertEquals("productName", productName.getName());
assertNull(productName.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/productName", productName.getPath());
assertEquals(FieldType.STRING, productName.getFieldType());
assertEquals(false, productName.isAttribute());
// quantity
XmlField quantity = item.getXmlFields().getXmlField().get(2);
assertNotNull(quantity);
assertEquals("quantity", quantity.getName());
assertNull(quantity.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/quantity", quantity.getPath());
assertEquals(FieldType.BIG_INTEGER, quantity.getFieldType());
assertEquals(false, quantity.isAttribute());
assertNotNull(quantity.getRestrictions().getRestriction());
assertEquals(1, quantity.getRestrictions().getRestriction().size());
Restriction qRestriction = quantity.getRestrictions().getRestriction().get(0);
assertNotNull(qRestriction);
assertNotNull(qRestriction.getType());
assertEquals(RestrictionType.MAX_EXCLUSIVE, qRestriction.getType());
assertNotNull(qRestriction.getValue());
assertEquals("99", qRestriction.getValue());
// USPrice
XmlField usPrice = item.getXmlFields().getXmlField().get(3);
assertNotNull(usPrice);
assertEquals("USPrice", usPrice.getName());
assertNull(usPrice.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/USPrice", usPrice.getPath());
assertEquals(FieldType.DECIMAL, usPrice.getFieldType());
assertEquals(false, usPrice.isAttribute());
// comment
XmlField itemComment = item.getXmlFields().getXmlField().get(4);
assertNotNull(itemComment);
assertEquals("tns:comment", itemComment.getName());
assertNull(itemComment.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/tns:comment", itemComment.getPath());
assertEquals(FieldType.STRING, itemComment.getFieldType());
assertEquals(false, itemComment.isAttribute());
// shipDate
XmlField shipDate = item.getXmlFields().getXmlField().get(5);
assertNotNull(shipDate);
assertEquals("shipDate", shipDate.getName());
assertNull(shipDate.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/shipDate", shipDate.getPath());
assertEquals(FieldType.DATE, shipDate.getFieldType());
assertEquals(false, shipDate.isAttribute());
// namespaces
assertNotNull(xmlDocument.getXmlNamespaces());
assertEquals(1, xmlDocument.getXmlNamespaces().getXmlNamespace().size());
XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
assertEquals("tns", namespace.getAlias());
assertEquals("http://tempuri.org/po.xsd", namespace.getUri());
// debugFields(xmlDocument.getFields());
}
Aggregations