Search in sources :

Example 1 with XSFacet

use of com.sun.xml.xsom.XSFacet in project atlasmap by atlasmap.

the class SchemaWriter method restrictionSimpleType.

public void restrictionSimpleType(XSRestrictionSimpleType type) {
    if (type.getBaseType() == null) {
        // don't print anySimpleType
        if (!type.getName().equals("anySimpleType"))
            throw new InternalError();
        if (!Const.schemaNamespace.equals(type.getTargetNamespace()))
            throw new InternalError();
        return;
    }
    XSSimpleType baseType = type.getSimpleBaseType();
    println(MessageFormat.format("<restriction{0}>", baseType.isLocal() ? "" : " base=\"{" + baseType.getTargetNamespace() + '}' + baseType.getName() + '\"'));
    indent++;
    if (baseType.isLocal())
        simpleType(baseType);
    Iterator itr = type.iterateDeclaredFacets();
    while (itr.hasNext()) facet((XSFacet) itr.next());
    indent--;
    println("</restriction>");
}
Also used : XSFacet(com.sun.xml.xsom.XSFacet) XSSimpleType(com.sun.xml.xsom.XSSimpleType) Iterator(java.util.Iterator)

Example 2 with XSFacet

use of com.sun.xml.xsom.XSFacet 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)

Example 3 with XSFacet

use of com.sun.xml.xsom.XSFacet in project BIMserver by opensourceBIM.

the class XSDSchemaReader method createSimpleType.

private void createSimpleType(XSSimpleType simpleType) {
    if (simpleType instanceof RestrictionSimpleTypeImpl) {
        RestrictionSimpleTypeImpl restrictionSimpleTypeImpl = (RestrictionSimpleTypeImpl) simpleType;
        String typeName = restrictionSimpleTypeImpl.getBaseType().getName();
        if (typeName.equals("string")) {
            EEnum eEnum = ecoreFactory.createEEnum();
            eEnum.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eEnum);
            int i = 0;
            for (XSFacet facet : restrictionSimpleTypeImpl.getDeclaredFacets()) {
                EEnumLiteral eEnumLiteral = ecoreFactory.createEEnumLiteral();
                eEnumLiteral.setValue(i++);
                eEnum.getELiterals().add(eEnumLiteral);
                eEnumLiteral.setName(facet.getValue().toString().toUpperCase());
            }
        } else if (typeName.equals("double")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else if (typeName.equals("normalizedString")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else if (typeName.equals("boolean")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else if (typeName.equals("long")) {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        } else {
            EClass eClass = ecoreFactory.createEClass();
            eClass.setName(simpleType.getName());
            ePackage.getEClassifiers().add(eClass);
        }
    } else {
        System.out.println(simpleType.getName());
    }
}
Also used : XSFacet(com.sun.xml.xsom.XSFacet) EClass(org.eclipse.emf.ecore.EClass) RestrictionSimpleTypeImpl(com.sun.xml.xsom.impl.RestrictionSimpleTypeImpl) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EEnum(org.eclipse.emf.ecore.EEnum)

Aggregations

XSFacet (com.sun.xml.xsom.XSFacet)3 XSRestrictionSimpleType (com.sun.xml.xsom.XSRestrictionSimpleType)1 XSSimpleType (com.sun.xml.xsom.XSSimpleType)1 XSType (com.sun.xml.xsom.XSType)1 RestrictionSimpleTypeImpl (com.sun.xml.xsom.impl.RestrictionSimpleTypeImpl)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 Iterator (java.util.Iterator)1 List (java.util.List)1 EClass (org.eclipse.emf.ecore.EClass)1 EEnum (org.eclipse.emf.ecore.EEnum)1 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)1