Search in sources :

Example 26 with ComplexType

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

the class SDOTypesGenerator method processGlobalItem.

private void processGlobalItem(String targetNamespace, String defaultNamespace, String qualifiedName) {
    if (rootSchema == null) {
        return;
    }
    String localName = null;
    int index = qualifiedName.indexOf(':');
    if (index != -1) {
        localName = qualifiedName.substring(index + 1, qualifiedName.length());
    } else {
        localName = qualifiedName;
    }
    SimpleType simpleType = rootSchema.getTopLevelSimpleTypes().get(localName);
    if (simpleType == null) {
        ComplexType complexType = rootSchema.getTopLevelComplexTypes().get(localName);
        if (complexType == null) {
            Element element = rootSchema.getTopLevelElements().get(localName);
            if (element == null) {
                Attribute attribute = rootSchema.getTopLevelAttributes().get(localName);
                if (attribute != null) {
                    processGlobalAttribute(targetNamespace, defaultNamespace, attribute);
                }
            } else {
                processGlobalElement(targetNamespace, defaultNamespace, element);
            }
        } else {
            processGlobalComplexType(targetNamespace, defaultNamespace, complexType);
        }
    } else {
        processGlobalSimpleType(targetNamespace, defaultNamespace, simpleType);
    }
}
Also used : SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 27 with ComplexType

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

the class SDOTypesGenerator method processElement.

private SDOType processElement(String targetNamespace, String defaultNamespace, SDOType owningType, TypeDefParticle typeDefParticle, Element element, boolean isGlobal, boolean isMany) {
    SDOType type = null;
    boolean addedNR = addNextNamespaceResolver(element.getAttributesMap());
    ComplexType complexType = element.getComplexType();
    boolean qualified = true;
    if (!isGlobal) {
        qualified = rootSchema.isElementFormDefault();
    }
    if (!isMany && maxOccursGreaterThanOne(element.getMaxOccurs())) {
        isMany = true;
    }
    if (complexType != null) {
        type = processComplexType(targetNamespace, defaultNamespace, element.getName(), complexType);
        type.setXsdLocalName(element.getName());
        type.setXsd(true);
        processSimpleElement(targetNamespace, defaultNamespace, owningType, type, typeDefParticle, element, qualified, isGlobal, isMany);
    } else if (element.getSimpleType() != null) {
        type = processSimpleType(targetNamespace, defaultNamespace, element.getName(), element.getSimpleType());
        type.setXsdLocalName(element.getName());
        type.setXsd(true);
        processSimpleElement(targetNamespace, defaultNamespace, owningType, type, typeDefParticle, element, qualified, isGlobal, isMany);
    } else {
        processSimpleElement(targetNamespace, defaultNamespace, owningType, null, typeDefParticle, element, qualified, isGlobal, isMany);
    }
    if (addedNR) {
        namespaceResolvers.remove(namespaceResolvers.size() - 1);
    }
    return type;
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 28 with ComplexType

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

the class SDOTypesGenerator method processBaseType.

private Type processBaseType(String targetNamespace, String defaultNamespace, SDOType owningType, String qualifiedName, boolean simpleContentExtension, Restriction restriction) {
    if (qualifiedName == null) {
        return null;
    }
    SDOType baseType = getSDOTypeForName(targetNamespace, defaultNamespace, qualifiedName);
    QName baseQName = getQNameForString(defaultNamespace, qualifiedName);
    if (!baseType.isFinalized() && baseQName.getNamespaceURI().equals(targetNamespace)) {
        if (baseType.isDataType()) {
            SimpleType baseSimpleType = rootSchema.getTopLevelSimpleTypes().get(baseQName.getLocalPart());
            processGlobalSimpleType(targetNamespace, defaultNamespace, baseSimpleType);
        } else {
            ComplexType baseComplexType = rootSchema.getTopLevelComplexTypes().get(baseQName.getLocalPart());
            processGlobalComplexType(targetNamespace, defaultNamespace, baseComplexType);
        }
    }
    // Java instance class is int
    if (baseQName.equals(XMLConstants.INTEGER_QNAME) || baseQName.equals(SDOConstants.POSITIVEINTEGER_QNAME) || baseQName.equals(SDOConstants.NEGATIVEINTEGER_QNAME) || baseQName.equals(SDOConstants.NONPOSITIVEINTEGER_QNAME) || baseQName.equals(SDOConstants.NONNEGATIVEINTEGER_QNAME) || baseQName.equals(XMLConstants.LONG_QNAME) || baseQName.equals(SDOConstants.UNSIGNEDLONG_QNAME)) {
        boolean alreadySet = false;
        String value = restriction.getMaxInclusive();
        if (value != null) {
            if (Integer.parseInt(value) <= Integer.MAX_VALUE) {
                baseType = getTypeForXSDQName(XMLConstants.INT_QNAME);
                alreadySet = true;
            }
        }
        // if maxInclusive was processed, no need to handle maxExclusive
        if (!alreadySet) {
            value = restriction.getMaxExclusive();
            if (value != null) {
                if (Integer.parseInt(value) < Integer.MAX_VALUE) {
                    baseType = getTypeForXSDQName(XMLConstants.INT_QNAME);
                }
            }
        }
    }
    processBaseType(baseType, targetNamespace, defaultNamespace, owningType, qualifiedName, simpleContentExtension);
    return baseType;
}
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 29 with ComplexType

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

the class BaseDBWSBuilderHelper method buildSchema.

/**
 * Build the schema
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void buildSchema(NamingConventionTransformer nct) {
    Project oxProject = dbwsBuilder.getOxProject();
    Schema schema = null;
    List<Descriptor> descriptorsToProcess = new ArrayList<Descriptor>();
    for (Descriptor desc : (List<Descriptor>) (List) oxProject.getOrderedDescriptors()) {
        String alias = desc.getAlias();
        if (!DEFAULT_SIMPLE_XML_FORMAT_TAG.equals(alias)) {
            descriptorsToProcess.add(desc);
        }
    }
    if (descriptorsToProcess.size() > 0) {
        // need a deep-copy clone of oxProject; simplest way is to marshall/unmarshall to a stream
        StringWriter sw = new StringWriter();
        XMLProjectWriter.write(oxProject, sw);
        XRDynamicClassLoader specialLoader = new XRDynamicClassLoader(this.getClass().getClassLoader());
        Project oxProjectClone = XMLProjectReader.read(new StringReader(sw.toString()), specialLoader);
        ProjectHelper.fixOROXAccessors(oxProjectClone, null);
        XMLLogin xmlLogin = new XMLLogin();
        DOMPlatform domPlatform = new DOMPlatform();
        domPlatform.getConversionManager().setLoader(specialLoader);
        xmlLogin.setPlatform(domPlatform);
        oxProjectClone.setLogin(xmlLogin);
        // initialize reference descriptors
        oxProjectClone.createDatabaseSession();
        SchemaModelGenerator schemaGenerator = new SchemaModelGenerator(XMLConversionManager.getDefaultXMLManager(), true);
        SchemaModelGeneratorProperties sgProperties = new SchemaModelGeneratorProperties();
        // set element form default to qualified for target namespace
        sgProperties.addProperty(dbwsBuilder.getTargetNamespace(), ELEMENT_FORM_QUALIFIED_KEY, true);
        Map<String, Schema> schemaMap = schemaGenerator.generateSchemas(descriptorsToProcess, sgProperties);
        Schema s = schemaMap.get(dbwsBuilder.getTargetNamespace());
        // check existing schema for any top-level ComplexTypes
        if (dbwsBuilder.getSchema() != null && s != null) {
            Map<String, ComplexType> topLevelComplexTypes = dbwsBuilder.getSchema().getTopLevelComplexTypes();
            for (Map.Entry<String, ComplexType> me : topLevelComplexTypes.entrySet()) {
                s.addTopLevelComplexTypes(me.getValue());
            }
            // add any additional namespaces
            NamespaceResolver snr = s.getNamespaceResolver();
            NamespaceResolver nr = dbwsBuilder.getSchema().getNamespaceResolver();
            // we only want to add prefix/uri pairs for prefixes that don't already exist
            for (String prefix : nr.getPrefixesToNamespaces().keySet()) {
                if (snr.resolveNamespacePrefix(prefix) == null) {
                    snr.put(prefix, nr.resolveNamespacePrefix(prefix));
                }
            }
            // switch
            schema = s;
            schema.setNamespaceResolver(snr);
        }
    } else {
        schema = new Schema();
        addSimpleXMLFormat(schema);
        schema.setTargetNamespace(dbwsBuilder.getTargetNamespace());
    }
    dbwsBuilder.setSchema(schema);
}
Also used : DOMPlatform(org.eclipse.persistence.oxm.platform.DOMPlatform) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XRDynamicClassLoader(org.eclipse.persistence.internal.xr.XRDynamicClassLoader) ArrayList(java.util.ArrayList) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) Project(org.eclipse.persistence.sessions.Project) SchemaModelProject(org.eclipse.persistence.internal.oxm.schema.SchemaModelProject) DBWSModelProject(org.eclipse.persistence.dbws.DBWSModelProject) ObjectPersistenceWorkbenchXMLProject(org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject) SimpleXMLFormatProject(org.eclipse.persistence.internal.xr.sxf.SimpleXMLFormatProject) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) Util.buildOXDescriptor(org.eclipse.persistence.tools.dbws.Util.buildOXDescriptor) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) Util.buildORDescriptor(org.eclipse.persistence.tools.dbws.Util.buildORDescriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) SchemaModelGeneratorProperties(org.eclipse.persistence.internal.oxm.schema.SchemaModelGeneratorProperties) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) ArrayList(java.util.ArrayList) List(java.util.List) SchemaModelGenerator(org.eclipse.persistence.internal.oxm.schema.SchemaModelGenerator) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)29 Element (org.eclipse.persistence.internal.oxm.schema.model.Element)14 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)13 QName (javax.xml.namespace.QName)12 Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)9 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)7 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)7 SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)6 SDOType (org.eclipse.persistence.sdo.SDOType)5 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)4 SchemaModelProject (org.eclipse.persistence.internal.oxm.schema.SchemaModelProject)4 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)4 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)4 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)4 XMLContext (org.eclipse.persistence.oxm.XMLContext)4 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)4 StringReader (java.io.StringReader)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3