Search in sources :

Example 1 with ComplexContent

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

the class SchemaGenerator method createComplexTypeForClass.

private ComplexType createComplexTypeForClass(JavaClass myClass, TypeInfo info) {
    Schema schema = getSchemaForNamespace(info.getClassNamespace());
    ComplexType type = new ComplexType();
    JavaClass superClass = CompilerHelper.getNextMappedSuperClass(myClass, this.typeInfo, this.helper);
    // Handle abstract class
    if (myClass.isAbstract()) {
        type.setAbstractValue(true);
    }
    Extension extension = null;
    if (superClass != null) {
        TypeInfo parentTypeInfo = this.typeInfo.get(superClass.getQualifiedName());
        if (parentTypeInfo != null) {
            extension = new Extension();
            // may need to qualify the type
            String parentPrefix = getPrefixForNamespace(schema, parentTypeInfo.getClassNamespace());
            if (parentPrefix != null) {
                extension.setBaseType(parentPrefix + COLON + parentTypeInfo.getSchemaTypeName());
            } else {
                extension.setBaseType(parentTypeInfo.getSchemaTypeName());
            }
            if (parentTypeInfo.getXmlValueProperty() != null) {
                SimpleContent content = new SimpleContent();
                content.setExtension(extension);
                type.setSimpleContent(content);
                return type;
            } else {
                ComplexContent content = new ComplexContent();
                content.setExtension(extension);
                type.setComplexContent(content);
            }
        }
    }
    TypeDefParticle compositor = null;
    String[] propOrder = null;
    if (info.isSetPropOrder()) {
        propOrder = info.getPropOrder();
    }
    if (propOrder != null && propOrder.length == 0) {
        // requires the extension case to use sequences
        if (info.hasElementRefs()) {
            // generate a sequence to satisfy TCK
            compositor = new Sequence();
            if (extension != null) {
                extension.setSequence((Sequence) compositor);
            } else {
                type.setSequence((Sequence) compositor);
            }
        } else if (extension != null) {
            compositor = new All();
            extension.setAll((All) compositor);
        } else {
            compositor = new All();
            type.setAll((All) compositor);
        }
    } else {
        // generate a sequence to satisfy TCK
        compositor = new Sequence();
        if (extension != null) {
            extension.setSequence((Sequence) compositor);
        } else {
            type.setSequence((Sequence) compositor);
        }
    }
    return type;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) All(org.eclipse.persistence.internal.oxm.schema.model.All) TypeDefParticle(org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) XmlVirtualAccessMethodsSchema(org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema) SimpleContent(org.eclipse.persistence.internal.oxm.schema.model.SimpleContent) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) ComplexContent(org.eclipse.persistence.internal.oxm.schema.model.ComplexContent) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Example 2 with ComplexContent

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

the class SchemaModelGenerator method buildComplexType.

/**
 * Create and return a ComplexType for a given XMLDescriptor.  Assumes that the descriptor has a schema context
 * set.
 */
protected ComplexType buildComplexType(boolean anonymous, Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    ComplexType ct = new ComplexType();
    if (!anonymous) {
        ct.setName(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
    }
    CoreInheritancePolicy inheritancePolicy = desc.getInheritancePolicyOrNull();
    Extension extension = null;
    if (inheritancePolicy != null && inheritancePolicy.getParentClass() != null) {
        extension = new Extension();
        extension.setBaseType(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
        ComplexContent complexContent = new ComplexContent();
        complexContent.setExtension(extension);
        ct.setComplexContent(complexContent);
    }
    Sequence seq = new Sequence();
    for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
        processMapping(mapping, seq, ct, schemaForNamespace, workingSchema, properties, descriptors);
    }
    if (extension != null) {
        extension.setSequence(seq);
    } else {
        ct.setSequence(seq);
    }
    return ct;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) Sequence(org.eclipse.persistence.internal.oxm.schema.model.Sequence) CoreInheritancePolicy(org.eclipse.persistence.core.descriptors.CoreInheritancePolicy) ComplexContent(org.eclipse.persistence.internal.oxm.schema.model.ComplexContent) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Vector(java.util.Vector)

Aggregations

ComplexContent (org.eclipse.persistence.internal.oxm.schema.model.ComplexContent)2 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)2 Extension (org.eclipse.persistence.internal.oxm.schema.model.Extension)2 Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)2 Vector (java.util.Vector)1 CoreInheritancePolicy (org.eclipse.persistence.core.descriptors.CoreInheritancePolicy)1 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)1 All (org.eclipse.persistence.internal.oxm.schema.model.All)1 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)1 SimpleContent (org.eclipse.persistence.internal.oxm.schema.model.SimpleContent)1 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)1