Search in sources :

Example 1 with XmlEnumFields

use of io.atlasmap.xml.v2.XmlEnumFields in project atlasmap by atlasmap.

the class XmlSchemaInspector method printElement.

private void printElement(XSElementDecl element, XmlComplexType parentXmlComplexType, CollectionType collectionType, Set<String> cachedComplexType) throws Exception {
    String parentPath = parentXmlComplexType.getPath();
    String elementName = getNameNS(element);
    String typeName = getNameNS(element.getType());
    XSType elementType = element.getType();
    if (elementType == null) {
        return;
    }
    if (elementType.isComplexType()) {
        XmlComplexType complexType = getXmlComplexType();
        String path = parentPath + "/" + elementName + getCollectionPathSuffix(collectionType);
        complexType.setName(elementName);
        complexType.setPath(path);
        complexType.setCollectionType(collectionType);
        parentXmlComplexType.getXmlFields().getXmlField().add(complexType);
        if (typeName != null && !typeName.isEmpty() && cachedComplexType.contains(typeName)) {
            complexType.setStatus(FieldStatus.CACHED);
        } else if (typeName != null) {
            cachedComplexType.add(typeName);
        }
        if (complexType.getStatus() != FieldStatus.CACHED) {
            printComplexType(element.getType().asComplexType(), complexType, cachedComplexType);
            if (LOG.isTraceEnabled()) {
                LOG.trace("Element: {}/{}", parentPath, getNameNS(element));
            }
        }
    } else if (elementType.asSimpleType() != null) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Element: {}/{}", parentPath, getNameNS(element));
        }
        XSRestrictionSimpleType restrictionType = elementType.asSimpleType().asRestriction();
        List<XSFacet> enumerations = restrictionType != null ? restrictionType.getFacets("enumeration") : null;
        if (enumerations != null && !enumerations.isEmpty()) {
            XmlComplexType complexType = getXmlComplexType();
            String path = parentPath + "/" + elementName + getCollectionPathSuffix(collectionType);
            complexType.setName(elementName);
            complexType.setPath(path);
            complexType.setCollectionType(collectionType);
            complexType.setEnumeration(true);
            parentXmlComplexType.getXmlFields().getXmlField().add(complexType);
            XmlEnumFields enums = new XmlEnumFields();
            complexType.setXmlEnumFields(enums);
            for (XSFacet enumFacet : enumerations) {
                XmlEnumField f = new XmlEnumField();
                f.setName(enumFacet.getValue().toString());
                enums.getXmlEnumField().add(f);
            }
            return;
        }
        XmlField xmlField = AtlasXmlModelFactory.createXmlField();
        xmlField.setName(elementName);
        xmlField.setPath(parentPath + "/" + elementName + getCollectionPathSuffix(collectionType));
        xmlField.setCollectionType(collectionType);
        parentXmlComplexType.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);
    }
}
Also used : XSType(com.sun.xml.xsom.XSType) XSFacet(com.sun.xml.xsom.XSFacet) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XSRestrictionSimpleType(com.sun.xml.xsom.XSRestrictionSimpleType) XmlEnumFields(io.atlasmap.xml.v2.XmlEnumFields) XmlEnumField(io.atlasmap.xml.v2.XmlEnumField) XmlField(io.atlasmap.xml.v2.XmlField) List(java.util.List)

Aggregations

XSFacet (com.sun.xml.xsom.XSFacet)1 XSRestrictionSimpleType (com.sun.xml.xsom.XSRestrictionSimpleType)1 XSType (com.sun.xml.xsom.XSType)1 XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)1 XmlEnumField (io.atlasmap.xml.v2.XmlEnumField)1 XmlEnumFields (io.atlasmap.xml.v2.XmlEnumFields)1 XmlField (io.atlasmap.xml.v2.XmlField)1 List (java.util.List)1