Search in sources :

Example 6 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SDOTypesGenerator method processUnion.

private void processUnion(String targetNamespace, String defaultNamespace, String sdoTypeName, Union union, SDOType type) {
    if (union != null) {
        java.util.List allMemberTypes = union.getAllMemberTypes();
        String firstInstanceClassName = null;
        for (int i = 0; i < allMemberTypes.size(); i++) {
            String nextMemberType = (String) allMemberTypes.get(i);
            SDOType typeForMemberType = getTypeForName(targetNamespace, defaultNamespace, nextMemberType);
            QName baseQName = this.getQNameForString(defaultNamespace, nextMemberType);
            if (!typeForMemberType.isFinalized() && baseQName.getNamespaceURI().equals(targetNamespace)) {
                SimpleType baseSimpleType = rootSchema.getTopLevelSimpleTypes().get(baseQName.getLocalPart());
                processSimpleType(targetNamespace, defaultNamespace, baseQName.getLocalPart(), baseSimpleType);
            }
            if (i == 0) {
                firstInstanceClassName = typeForMemberType.getInstanceClassName();
                if (firstInstanceClassName == null) {
                    break;
                }
            } else {
                String nextClassName = typeForMemberType.getInstanceClassName();
                if (!firstInstanceClassName.equals(nextClassName)) {
                    type.setInstanceClass(java.lang.Object.class);
                    return;
                }
            }
        }
        if (firstInstanceClassName != null) {
            type.setInstanceClassName(firstInstanceClassName);
        } else {
            type.setInstanceClass(java.lang.Object.class);
        }
    }
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) QName(javax.xml.namespace.QName) SDOType(org.eclipse.persistence.sdo.SDOType)

Example 7 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SDOTypesGenerator method processExtension.

private void processExtension(String targetNamespace, String defaultNamespace, SDOType owningType, Extension extension, boolean simpleContent) {
    if (extension != null) {
        String qualifiedType = extension.getBaseType();
        SDOType baseType = getSDOTypeForName(targetNamespace, defaultNamespace, qualifiedType);
        QName baseQName = getQNameForString(defaultNamespace, qualifiedType);
        if (baseType != null) {
            if (!baseType.isFinalized() && baseQName.getNamespaceURI().equals(targetNamespace)) {
                if (baseType.isDataType()) {
                    SimpleType baseSimpleType = rootSchema.getTopLevelSimpleTypes().get(baseQName.getLocalPart());
                    if (baseSimpleType != null) {
                        processGlobalSimpleType(targetNamespace, defaultNamespace, baseSimpleType);
                    }
                } else {
                    ComplexType baseComplexType = rootSchema.getTopLevelComplexTypes().get(baseQName.getLocalPart());
                    if (baseComplexType != null) {
                        processGlobalComplexType(targetNamespace, defaultNamespace, baseComplexType);
                    }
                }
            }
            owningType.setOpen(owningType.isOpen() || baseType.isOpen());
        }
        if (qualifiedType != null) {
            processBaseType(baseType, targetNamespace, defaultNamespace, owningType, qualifiedType, simpleContent);
        }
        if (extension.getChoice() != null) {
            processChoice(targetNamespace, defaultNamespace, owningType, extension.getChoice(), false);
        } else if (extension.getSequence() != null) {
            processSequence(targetNamespace, defaultNamespace, owningType, extension.getSequence(), false);
        } else if (extension.getAll() != null) {
        }
        processOrderedAttributes(targetNamespace, defaultNamespace, owningType, extension.getOrderedAttributes());
    }
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) QName(javax.xml.namespace.QName) SDOType(org.eclipse.persistence.sdo.SDOType) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 8 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SDOTypesGenerator method processSimpleAttribute.

private void processSimpleAttribute(String targetNamespace, String defaultNamespace, SDOType owningType, Attribute attribute, boolean isGlobal, boolean isQualified, SDOType sdoPropertyType) {
    if (attribute == null) {
        return;
    }
    SDOProperty p = null;
    String typeName = null;
    String mappingUri = null;
    if (owningType != null) {
        mappingUri = owningType.getURI();
    }
    if (attribute.getRef() != null) {
        String ref = attribute.getRef();
        String localName = null;
        String uri = null;
        int index = ref.indexOf(':');
        if (index != -1) {
            String prefix = ref.substring(0, index);
            localName = ref.substring(index + 1, ref.length());
            uri = getURIForPrefix(prefix);
        } else {
            localName = ref;
            uri = defaultNamespace;
        }
        Property lookedUp = owningType.getProperty(localName);
        if (lookedUp != null) {
            if (inRestriction) {
                return;
            }
            updateCollisionProperty(owningType, (SDOProperty) lookedUp);
        } else {
            SDOProperty theProp = new SDOProperty(aHelperContext);
            SDOProperty lookedUpProp = getExistingGlobalProperty(uri, localName, false);
            if (lookedUpProp != null) {
                theProp.setNamespaceQualified(lookedUpProp.isNamespaceQualified());
                theProp.setUri(uri);
                theProp.setType(lookedUpProp.getType());
            }
            theProp.setName(localName);
            theProp.setGlobal(false);
            theProp.setContainment(false);
            theProp.setXsd(true);
            theProp.setMany(false);
            if (attribute.getAnnotation() != null) {
                java.util.List doc = attribute.getAnnotation().getDocumentation();
                if (doc != null) {
                    theProp.setInstanceProperty(SDOConstants.DOCUMENTATION_PROPERTY, doc);
                }
            }
            theProp.setFinalized(true);
            GlobalRef globalRef = new GlobalRef();
            globalRef.setProperty(theProp);
            owningType.addDeclaredProperty(theProp);
            globalRef.setIsElement(false);
            globalRef.setOwningType(owningType);
            globalRef.setUri(uri);
            globalRef.setLocalName(localName);
            addGlobalRef(globalRef);
        }
        return;
    } else {
        if (isGlobal) {
            SDOProperty lookedUpProp = getExistingGlobalProperty(targetNamespace, attribute.getName(), false);
            if (lookedUpProp != null && lookedUpProp.isFinalized()) {
                return;
            }
        }
        p = createNewProperty(targetNamespace, attribute.getName(), isQualified, isGlobal, false, false, attribute.getAnnotation());
        if (attribute.getAnnotation() != null) {
            p.setAppInfoElements(attribute.getAnnotation().getAppInfo());
        }
        typeName = attribute.getType();
        if (typeName != null) {
            p.setName(attribute.getName());
            QName qname = getQNameForString(defaultNamespace, typeName);
            if (isGlobal) {
                // if type is found set it other wise process new type
                processGlobalItem(targetNamespace, defaultNamespace, typeName);
            }
            if ((qname.equals(XMLConstants.QNAME_QNAME)) || (qname.equals(XMLConstants.BASE_64_BINARY_QNAME)) || (qname.equals(XMLConstants.HEX_BINARY_QNAME)) || (qname.equals(XMLConstants.DATE_QNAME)) || (qname.equals(XMLConstants.TIME_QNAME)) || (qname.equals(XMLConstants.DATE_TIME_QNAME))) {
                p.setXsdType(qname);
            }
            sdoPropertyType = getSDOTypeForName(targetNamespace, defaultNamespace, typeName);
            if (!sdoPropertyType.isFinalized() && qname.getNamespaceURI().equals(targetNamespace)) {
                if (sdoPropertyType.isDataType()) {
                    SimpleType baseSimpleType = rootSchema.getTopLevelSimpleTypes().get(qname.getLocalPart());
                    processGlobalSimpleType(targetNamespace, defaultNamespace, baseSimpleType);
                }
            }
            if ((p.getXsdType() == null) && (sdoPropertyType.getXsdType() != null)) {
                p.setXsdType(sdoPropertyType.getXsdType());
            }
        } else if (attribute.getSimpleType() != null) {
            p.setName(attribute.getName());
            typeName = attribute.getName();
        } else {
            p.setName(attribute.getName());
            sdoPropertyType = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getSDOTypeFromXSDType(SDOConstants.ANY_TYPE_QNAME);
        }
    }
    sdoPropertyType = processSimpleComponentAnnotations(owningType, attribute, p, targetNamespace, defaultNamespace, sdoPropertyType);
    p.setType(sdoPropertyType);
    p.setContainment(false);
    setDefaultValue(p, attribute);
    if (p.getType().isChangeSummaryType()) {
        p.setReadOnly(true);
    }
    if (owningType != null) {
        updateOwnerAndBuildMapping(owningType, p, defaultNamespace, targetNamespace, attribute, typeName, mappingUri);
    }
    p.setFinalized(true);
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) QName(javax.xml.namespace.QName) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Example 9 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SDOTypesGenerator method processSimpleElement.

private // 
void processSimpleElement(// 
String targetNamespace, // 
String defaultNamespace, // 
SDOType owningType, // 
SDOType sdoPropertyType, // 
TypeDefParticle typeDefParticle, // 
Element element, // 
boolean isQualified, // 
boolean isGlobal, boolean isMany) {
    if (element == null) {
        return;
    }
    String manyValue = element.getAttributesMap().get(SDOConstants.SDOXML_MANY_QNAME);
    if (manyValue != null) {
        isMany = Boolean.parseBoolean(manyValue);
    }
    SDOProperty p = null;
    String typeName = null;
    String mappingUri = null;
    if (typeDefParticle != null) {
        mappingUri = owningType.getURI();
    }
    if (element.getRef() != null) {
        String ref = element.getRef();
        String localName = null;
        String uri = null;
        int index = ref.indexOf(':');
        if (index != -1) {
            String prefix = ref.substring(0, index);
            localName = ref.substring(index + 1, ref.length());
            uri = getURIForPrefix(prefix);
        } else {
            localName = ref;
            uri = defaultNamespace;
        }
        Property lookedUp = owningType.getProperty(localName);
        if (lookedUp != null) {
            if (inRestriction) {
                return;
            }
            updateCollisionProperty(owningType, (SDOProperty) lookedUp);
        } else {
            SDOProperty theProp = new SDOProperty(aHelperContext);
            theProp.setName(localName);
            theProp.setGlobal(false);
            theProp.setContainment(true);
            theProp.setXsd(true);
            theProp.setMany(isMany);
            theProp.setInstanceProperty(SDOConstants.XMLELEMENT_PROPERTY, Boolean.TRUE);
            if (element.getAnnotation() != null) {
                java.util.List doc = element.getAnnotation().getDocumentation();
                if (doc != null) {
                    theProp.setInstanceProperty(SDOConstants.DOCUMENTATION_PROPERTY, doc);
                }
            }
            owningType.addDeclaredProperty(theProp);
            GlobalRef globalRef = new GlobalRef();
            globalRef.setProperty(theProp);
            globalRef.setIsElement(true);
            globalRef.setOwningType(owningType);
            globalRef.setUri(uri);
            globalRef.setLocalName(localName);
            addGlobalRef(globalRef);
        }
        return;
    } else {
        if (isGlobal) {
            SDOProperty lookedUpProp = getExistingGlobalProperty(targetNamespace, element.getName(), true);
            if (lookedUpProp != null && lookedUpProp.isFinalized()) {
                return;
            }
        }
        p = createNewProperty(targetNamespace, element.getName(), isQualified, isGlobal, true, element.isNillable(), element.getAnnotation());
        if (element.getAnnotation() != null) {
            p.setAppInfoElements(element.getAnnotation().getAppInfo());
        }
        if (element.getType() != null) {
            typeName = element.getType();
            p.setName(element.getName());
            QName qname = getQNameForString(defaultNamespace, typeName);
            if (isGlobal) {
                // only process the root schema's global items if qname uri == target namespace
                if (qname.getNamespaceURI().equals(targetNamespace)) {
                    // if type is found set it other wise process new type
                    processGlobalItem(targetNamespace, defaultNamespace, qname.getLocalPart());
                }
            }
            if ((qname.equals(XMLConstants.QNAME_QNAME)) || (qname.equals(XMLConstants.BASE_64_BINARY_QNAME)) || (qname.equals(XMLConstants.HEX_BINARY_QNAME)) || (qname.equals(XMLConstants.DATE_QNAME)) || (qname.equals(XMLConstants.TIME_QNAME)) || (qname.equals(XMLConstants.DATE_TIME_QNAME))) {
                p.setXsdType(qname);
            }
            String mimeType = element.getAttributesMap().get(SDOConstants.XML_MIME_TYPE_QNAME);
            if (mimeType != null) {
                p.setInstanceProperty(SDOConstants.MIME_TYPE_PROPERTY, mimeType);
            }
            String mimeTypePropName = element.getAttributesMap().get(SDOConstants.XML_MIME_TYPE_PROPERTY_QNAME);
            if (mimeTypePropName != null) {
                p.setInstanceProperty(SDOConstants.MIME_TYPE_PROPERTY_PROPERTY, mimeTypePropName);
            }
            sdoPropertyType = getSDOTypeForName(targetNamespace, defaultNamespace, typeName);
            if (!sdoPropertyType.isFinalized() && qname.getNamespaceURI().equals(targetNamespace)) {
                if (sdoPropertyType.isDataType()) {
                    SimpleType baseSimpleType = rootSchema.getTopLevelSimpleTypes().get(qname.getLocalPart());
                    processGlobalSimpleType(targetNamespace, defaultNamespace, baseSimpleType);
                }
            }
            if ((p.getXsdType() == null) && (sdoPropertyType.getXsdType() != null)) {
                p.setXsdType(sdoPropertyType.getXsdType());
            }
            if (sdoPropertyType.isDataType()) {
                p.setContainment(false);
            }
        } else if (element.getComplexType() != null) {
            typeName = element.getName();
            p.setName(element.getComplexType().getNameOrOwnerName());
        } else if (element.getSimpleType() != null) {
            typeName = element.getName();
            p.setName(element.getName());
            if (sdoPropertyType.isDataType()) {
                p.setContainment(false);
            }
        } else {
            // we assume the xsd type to be any simple type
            p.setName(element.getName());
            sdoPropertyType = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getSDOTypeFromXSDType(SDOConstants.ANY_TYPE_QNAME);
        }
    }
    sdoPropertyType = processSimpleComponentAnnotations(owningType, element, p, targetNamespace, defaultNamespace, sdoPropertyType);
    p.setType(sdoPropertyType);
    setDefaultValue(p, element);
    p.setMany(isMany);
    if (p.getType().isChangeSummaryType()) {
        p.setReadOnly(true);
    }
    if (typeDefParticle != null) {
        updateOwnerAndBuildMapping(owningType, p, defaultNamespace, targetNamespace, element, typeName, mappingUri);
    }
    if (isGlobal) {
        // we have a global element
        addRootElementToDescriptor(p, targetNamespace, element.getName());
    }
    p.setFinalized(true);
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) QName(javax.xml.namespace.QName) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Example 10 with SimpleType

use of org.eclipse.persistence.internal.oxm.schema.model.SimpleType in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method buildSimpleType.

/**
 * Create and return a SimpleType for a given XMLDescriptor.
 */
protected SimpleType buildSimpleType(Descriptor desc, Schema workingSchema, boolean global) {
    SimpleType st;
    if (global) {
        st = buildNewSimpleType(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
    } else {
        st = new SimpleType();
    }
    CoreMapping mapping = (CoreMapping) desc.getMappings().get(0);
    QName qname = conversionManager.schemaType(mapping.getAttributeClassification());
    String baseType = qname.getLocalPart();
    if (qname.getNamespaceURI() != null) {
        String prefix = workingSchema.getNamespaceResolver().resolveNamespaceURI(qname.getNamespaceURI());
        if (prefix == null) {
            prefix = workingSchema.getNamespaceResolver().generatePrefix();
            workingSchema.getNamespaceResolver().put(prefix, qname.getNamespaceURI());
        }
        baseType = prefix + Constants.COLON + baseType;
    }
    Restriction restriction = new Restriction();
    restriction.setBaseType(baseType);
    st.setRestriction(restriction);
    return st;
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) Restriction(org.eclipse.persistence.internal.oxm.schema.model.Restriction) QName(javax.xml.namespace.QName) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping)

Aggregations

SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)18 QName (javax.xml.namespace.QName)10 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)6 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)6 ArrayList (java.util.ArrayList)5 SDOType (org.eclipse.persistence.sdo.SDOType)5 List (java.util.List)4 Attribute (org.eclipse.persistence.internal.oxm.schema.model.Attribute)4 Restriction (org.eclipse.persistence.internal.oxm.schema.model.Restriction)4 AnyAttribute (org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute)3 Property (commonj.sdo.Property)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)2 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)2 SimpleContent (org.eclipse.persistence.internal.oxm.schema.model.SimpleContent)2 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)2 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)2 XmlSchemaType (jakarta.xml.bind.annotation.XmlSchemaType)1