Search in sources :

Example 11 with Element

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

the class SchemaModelGenerator method buildElement.

/**
 * Build and return an Element for a given XPathFragment.
 */
protected Element buildElement(XPathFragment frag, String schemaType, String minOccurs, String maxOccurs) {
    Element element = new Element();
    element.setName(frag.getLocalName());
    element.setMinOccurs(minOccurs);
    element.setMaxOccurs(frag.containsIndex() ? Occurs.UNBOUNDED : maxOccurs);
    if (schemaType != null) {
        element.setType(schemaType);
    }
    return element;
}
Also used : Element(org.eclipse.persistence.internal.oxm.schema.model.Element)

Example 12 with Element

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

the class SchemaModelGenerator method processDescriptor.

/**
 * Process a given descriptor.  Global complex types will be generated for based on
 * schema context, and global elements based on default root element.
 */
protected void processDescriptor(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    // determine if a simple type (or complex type with simple content) or complex type is required
    boolean simple = isSimple(desc);
    XMLSchemaReference schemaRef = desc.getSchemaReference();
    if (schemaRef != null) {
        if (schemaRef.getType() == org.eclipse.persistence.platform.xml.XMLSchemaReference.COMPLEX_TYPE) {
            workingSchema.addTopLevelComplexTypes(buildComplexType(false, desc, schemaForNamespace, workingSchema, properties, descriptors));
        } else if (schemaRef.getType() == org.eclipse.persistence.platform.xml.XMLSchemaReference.SIMPLE_TYPE) {
            workingSchema.addTopLevelSimpleTypes(buildSimpleType(desc, workingSchema, true));
        } else if (schemaRef.getType() == org.eclipse.persistence.platform.xml.XMLSchemaReference.ELEMENT) {
            workingSchema.addTopLevelElement(buildElement(desc, schemaForNamespace, workingSchema, properties, descriptors, simple));
        }
        for (DatabaseTable table : (Vector<DatabaseTable>) desc.getTables()) {
            String localName = getDefaultRootElementAsQName(desc, table.getName()).getLocalPart();
            // don't overwrite existing top level elements
            if (workingSchema.getTopLevelElements().get(localName) != null) {
                continue;
            }
            Element topLevelElement = new Element();
            topLevelElement.setName(localName);
            QName qname = schemaRef.getSchemaContextAsQName(workingSchema.getNamespaceResolver());
            String elementType = qname.getLocalPart();
            String elementTypeUri = qname.getNamespaceURI();
            String elementTypePrefix = workingSchema.getNamespaceResolver().resolveNamespaceURI(elementTypeUri);
            if (elementTypePrefix != null) {
                elementType = elementTypePrefix + Constants.COLON + elementType;
            }
            topLevelElement.setType(elementType);
            workingSchema.addTopLevelElement(topLevelElement);
        }
    } else {
        // there is a default root element set we need to generate a global element
        for (DatabaseTable table : (Vector<DatabaseTable>) desc.getTables()) {
            String localName = getDefaultRootElementAsQName(desc, table.getName()).getLocalPart();
            // a global element may have been created while generating an element ref
            if (workingSchema.getTopLevelElements().get(localName) == null) {
                Element topLevelElement = new Element();
                topLevelElement.setName(localName);
                if (simple) {
                    if (isComplexTypeWithSimpleContentRequired(desc)) {
                        topLevelElement.setComplexType(buildComplexTypeWithSimpleContent(desc, schemaForNamespace, workingSchema, properties, descriptors));
                    } else {
                        topLevelElement.setSimpleType(buildSimpleType(desc, workingSchema, false));
                    }
                } else {
                    topLevelElement.setComplexType(buildComplexType(true, desc, schemaForNamespace, workingSchema, properties, descriptors));
                }
                workingSchema.addTopLevelElement(topLevelElement);
            }
        }
    }
}
Also used : XMLSchemaReference(org.eclipse.persistence.oxm.schema.XMLSchemaReference) QName(javax.xml.namespace.QName) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) DatabaseTable(org.eclipse.persistence.internal.helper.DatabaseTable) Vector(java.util.Vector)

Example 13 with Element

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

the class SchemaModelGenerator method processXMLObjectReferenceMapping.

/**
 * Process a given XMLObjectReferenceMapping.  In the case of an XMLCollectionReferenceMapping,
 * i.e. the isCollection flag is set to true, maxOccurs will be set to 'unbounded' on any
 * source elements
 */
protected void processXMLObjectReferenceMapping(ObjectReferenceMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) {
    String tgtClassName = mapping.getReferenceClassName();
    Descriptor tgtDesc = getDescriptorByName(tgtClassName, descriptors);
    if (tgtDesc == null) {
        throw DescriptorException.descriptorIsMissing(tgtClassName, (DatabaseMapping) mapping);
    }
    // get the target mapping(s) to determine the appropriate type(s)
    String schemaTypeString = null;
    Map<Field, Field> associations = mapping.getSourceToTargetKeyFieldAssociations();
    for (Entry<Field, Field> entry : associations.entrySet()) {
        Field tgtField = entry.getValue();
        Vector mappings = tgtDesc.getMappings();
        // schemaTypeString = Constants.SCHEMA_PREFIX + COLON + IDREF;
        for (Enumeration mappingsNum = mappings.elements(); mappingsNum.hasMoreElements(); ) {
            Mapping nextMapping = (Mapping) mappingsNum.nextElement();
            if (nextMapping.getField() != null && nextMapping.getField() instanceof Field) {
                Field xFld = (Field) nextMapping.getField();
                if (xFld == tgtField) {
                    schemaTypeString = getSchemaTypeForElement(tgtField, nextMapping.getAttributeClassification(), workingSchema);
                }
            }
        }
        if (schemaTypeString == null) {
            schemaTypeString = getSchemaTypeString(Constants.STRING_QNAME, workingSchema);
        }
        XPathFragment frag = entry.getKey().getXPathFragment();
        if (frag.isAttribute()) {
            Attribute attr = buildAttribute(frag, schemaTypeString);
            ct.getOrderedAttributes().add(attr);
        } else {
            Element elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
            if (isCollection) {
                elem.setMaxOccurs(Occurs.UNBOUNDED);
            }
            seq.addElement(elem);
        }
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) Enumeration(java.util.Enumeration) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) Vector(java.util.Vector)

Example 14 with Element

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

the class SchemaModelGenerator method buildElement.

/**
 * Create and return an Element for a given XMLDescriptor.
 */
protected Element buildElement(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean simple) {
    Element element = new Element();
    element.setName(desc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()).getLocalPart());
    if (simple) {
        if (isComplexTypeWithSimpleContentRequired(desc)) {
            element.setComplexType(buildComplexTypeWithSimpleContent(desc, schemaForNamespace, workingSchema, properties, descriptors));
        } else {
            element.setSimpleType(buildSimpleType(desc, workingSchema, false));
        }
    } else {
        element.setComplexType(buildComplexType(true, desc, schemaForNamespace, workingSchema, properties, descriptors));
    }
    return element;
}
Also used : Element(org.eclipse.persistence.internal.oxm.schema.model.Element)

Example 15 with Element

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

the class SchemaModelGenerator method processReferenceDescriptor.

/**
 */
protected Element processReferenceDescriptor(Element element, Descriptor refDesc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, Field field, boolean isCollection) {
    ComplexType ctype = null;
    if (refDesc.getSchemaReference() == null) {
        ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors);
    } else {
        element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
    }
    XPathFragment frag = field.getXPathFragment();
    String fragUri = frag.getNamespaceURI();
    if (fragUri != null) {
        // may need to add a global element
        Schema s = getSchema(fragUri, null, schemaForNamespace, properties);
        String targetNS = workingSchema.getTargetNamespace();
        if ((s.isElementFormDefault() && !fragUri.equals(targetNS)) || (!s.isElementFormDefault() && fragUri.length() > 0)) {
            if (s.getTopLevelElements().get(frag.getShortName()) == null) {
                Element globalElement = new Element();
                globalElement.setName(frag.getLocalName());
                if (ctype != null) {
                    globalElement.setComplexType(ctype);
                } else {
                    globalElement.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
                }
                s.getTopLevelElements().put(frag.getShortName(), globalElement);
            }
            element = new Element();
            element.setMinOccurs(Occurs.ZERO);
            if (isCollection) {
                element.setMaxOccurs(Occurs.UNBOUNDED);
            }
            element.setRef(frag.getShortName());
        } else {
            element.setComplexType(ctype);
        }
    } else if (ctype != null) {
        element.setComplexType(ctype);
    }
    return element;
}
Also used : Schema(org.eclipse.persistence.internal.oxm.schema.model.Schema) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType)

Aggregations

Element (org.eclipse.persistence.internal.oxm.schema.model.Element)36 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)15 Schema (org.eclipse.persistence.internal.oxm.schema.model.Schema)15 QName (javax.xml.namespace.QName)9 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)8 Field (org.eclipse.persistence.internal.oxm.mappings.Field)7 Sequence (org.eclipse.persistence.internal.oxm.schema.model.Sequence)7 SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)7 XmlVirtualAccessMethodsSchema (org.eclipse.persistence.jaxb.xmlmodel.XmlVirtualAccessMethodsSchema)7 Attribute (org.eclipse.persistence.internal.oxm.schema.model.Attribute)5 Choice (org.eclipse.persistence.internal.oxm.schema.model.Choice)5 TypeDefParticle (org.eclipse.persistence.internal.oxm.schema.model.TypeDefParticle)5 ArrayList (java.util.ArrayList)4 AnyAttribute (org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute)4 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)4 List (java.util.List)3 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)3 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)3 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2