Search in sources :

Example 21 with Element

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

the class SchemaModelGenerator method processXMLBinaryDataMapping.

/**
 * Process a given XMLBinaryDataMapping.
 */
protected void processXMLBinaryDataMapping(BinaryDataMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    Field xmlField = (Field) mapping.getField();
    XPathFragment frag = xmlField.getXPathFragment();
    String schemaTypeString;
    if (mapping.isSwaRef()) {
        schemaTypeString = getSchemaTypeString(Constants.SWA_REF_QNAME, workingSchema);
        Import newImport = new Import();
        newImport.setNamespace(Constants.REF_URL);
        newImport.setSchemaLocation(SWAREF_LOCATION);
        workingSchema.getImports().add(newImport);
    } else {
        schemaTypeString = getSchemaTypeString(Constants.BASE_64_BINARY_QNAME, workingSchema);
    }
    seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
    frag = getTargetXPathFragment(frag);
    Element elem = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), seq);
    if (elem == null) {
        if (frag.getNamespaceURI() != null) {
            elem = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, null, schemaTypeString);
        } else {
            elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
        }
        if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
            elem.setNillable(true);
        }
        if (xmlField.isRequired()) {
            elem.setMinOccurs("1");
        }
        if (mapping.getMimeType() != null) {
            elem.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, mapping.getMimeType());
        }
        seq.addElement(elem);
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) Import(org.eclipse.persistence.internal.oxm.schema.model.Import) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Example 22 with Element

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

the class SchemaModelGenerator method processXMLBinaryDataCollectionMapping.

/**
 * Process a given XMLBinaryDataCollectionMapping.
 */
protected void processXMLBinaryDataCollectionMapping(BinaryDataCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    Field xmlField = (Field) mapping.getField();
    XPathFragment frag = xmlField.getXPathFragment();
    String schemaTypeString;
    if (mapping.isSwaRef()) {
        schemaTypeString = getSchemaTypeString(Constants.SWA_REF_QNAME, workingSchema);
    } else {
        schemaTypeString = getSchemaTypeString(Constants.BASE_64_BINARY_QNAME, workingSchema);
    }
    seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
    frag = getTargetXPathFragment(frag);
    Element elem = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), seq);
    if (elem == null) {
        if (frag.getNamespaceURI() != null) {
            elem = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, null, schemaTypeString);
            elem.setMaxOccurs(Occurs.UNBOUNDED);
        } else {
            elem = buildElement(frag, schemaTypeString, Occurs.ZERO, Occurs.UNBOUNDED);
        }
        if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
            elem.setNillable(true);
        }
        if (xmlField.isRequired()) {
            elem.setMinOccurs("1");
        }
        if (mapping.getMimeType() != null) {
            elem.getAttributesMap().put(Constants.EXPECTED_CONTENT_TYPES_QNAME, mapping.getMimeType());
        }
        seq.addElement(elem);
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment)

Example 23 with Element

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

the class SchemaModelGenerator method processChoiceMapping.

/**
 * Process a given XMLChoiceMapping.
 */
protected void processChoiceMapping(Map<Field, Class<?>> fieldToClassMap, List<XMLChoiceFieldToClassAssociation> choiceFieldToClassList, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean isCollection) {
    Choice theChoice = new Choice();
    if (isCollection) {
        theChoice.setMaxOccurs(Occurs.UNBOUNDED);
    }
    for (XMLChoiceFieldToClassAssociation next : choiceFieldToClassList) {
        Field field = next.getXmlField();
        Element element = buildElement(field.getXPathFragment().getShortName(), Occurs.ZERO, null);
        QName schemaTypeQName = field.getSchemaType();
        if (schemaTypeQName != null) {
            element.setType(getSchemaTypeString(schemaTypeQName, workingSchema));
        } else {
            element = processReferenceDescriptor(element, getDescriptorByClass(fieldToClassMap.get(field), descriptors), schemaForNamespace, workingSchema, properties, descriptors, field, false);
        }
        theChoice.addElement(element);
    }
    seq.addChoice(theChoice);
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) XMLChoiceFieldToClassAssociation(org.eclipse.persistence.internal.oxm.XMLChoiceFieldToClassAssociation) Choice(org.eclipse.persistence.internal.oxm.schema.model.Choice) QName(javax.xml.namespace.QName) Element(org.eclipse.persistence.internal.oxm.schema.model.Element)

Example 24 with Element

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

the class SchemaModelGenerator method processXMLDirectMapping.

/**
 * Process a given XMLDirectMapping.
 */
protected void processXMLDirectMapping(DirectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    Field xmlField = (Field) mapping.getField();
    XPathFragment frag = xmlField.getXPathFragment();
    if (frag.isSelfFragment()) {
        // do nothing;
        return;
    }
    // Handle ID
    boolean isPk = isFragPrimaryKey(frag, mapping);
    String schemaTypeString = null;
    if (isPk) {
        schemaTypeString = Constants.SCHEMA_PREFIX + Constants.COLON + ID;
    } else {
        schemaTypeString = getSchemaTypeForDirectMapping(mapping, workingSchema);
    }
    // Handle enumerations
    Class<?> attributeClassification = mapping.getAttributeClassification();
    if (attributeClassification != null && Enum.class.isAssignableFrom(attributeClassification)) {
        CoreConverter converter = mapping.getConverter();
        if (converter != null && converter instanceof EnumTypeConverter) {
            processEnumeration(schemaTypeString, frag, mapping, seq, ct, workingSchema, converter);
            return;
        }
    }
    if (frag.isAttribute()) {
        Attribute attr = buildAttribute(mapping, schemaTypeString);
        if (xmlField.isRequired()) {
            attr.setUse(Attribute.REQUIRED);
        }
        ct.getOrderedAttributes().add(attr);
    } else {
        seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
        frag = getTargetXPathFragment(frag);
        Element elem = elementExistsInSequence(frag.getLocalName(), frag.getShortName(), seq);
        if (elem == null) {
            if (frag.getNamespaceURI() != null) {
                elem = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, null, schemaTypeString);
            } else {
                elem = buildElement(frag, schemaTypeString, Occurs.ZERO, null);
            }
            if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
                elem.setNillable(true);
            }
            if (xmlField.isRequired()) {
                elem.setMinOccurs("1");
            }
            seq.addElement(elem);
        }
    }
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) AnyAttribute(org.eclipse.persistence.internal.oxm.schema.model.AnyAttribute) Attribute(org.eclipse.persistence.internal.oxm.schema.model.Attribute) EnumTypeConverter(org.eclipse.persistence.mappings.converters.EnumTypeConverter) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) CoreConverter(org.eclipse.persistence.core.mappings.converters.CoreConverter)

Example 25 with Element

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

the class SchemaModelGenerator method processXMLCompositeMapping.

/**
 * Process a given XML composite mapping - either an XMLCompositeObjectMapping, or an
 * XMLCompositeCollectionMapping.  For XMLCompositeDirectCollectionMappings the
 * processXMLCompositeDirectCollectionMapping method should be used.
 */
protected void processXMLCompositeMapping(CompositeObjectMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors, boolean collection) {
    Field xmlField = (Field) mapping.getField();
    String refClassName = mapping.getReferenceClassName();
    Descriptor refDesc = getDescriptorByName(refClassName, descriptors);
    if (refDesc == null) {
        throw DescriptorException.descriptorIsMissing(refClassName, (DatabaseMapping) mapping);
    }
    XPathFragment frag = xmlField.getXPathFragment();
    seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
    frag = getTargetXPathFragment(frag);
    Element element = buildElement(frag, null, Occurs.ZERO, (collection ? Occurs.UNBOUNDED : null));
    ComplexType ctype = null;
    // if the reference descriptor's schema context is null we need to generate an anonymous complex type
    if (refDesc.getSchemaReference() == null) {
        ctype = buildComplexType(true, refDesc, schemaForNamespace, workingSchema, properties, descriptors);
    } else {
        element.setType(getSchemaTypeString(refDesc.getSchemaReference().getSchemaContextAsQName(workingSchema.getNamespaceResolver()), workingSchema));
    }
    if (frag.getNamespaceURI() != null) {
        // may need to add a global element
        element = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, element, ctype, refDesc);
    } else if (ctype != null) {
        // set an anonymous complex type
        element.setComplexType(ctype);
    }
    boolean isNillable = false;
    if (!collection) {
        isNillable = mapping.getNullPolicy().isNullRepresentedByXsiNil();
    } else {
        isNillable = mapping.getNullPolicy().isNullRepresentedByXsiNil();
    }
    element.setNillable(isNillable);
    if (xmlField.isRequired()) {
        element.setMinOccurs("1");
    }
    seq.addElement(element);
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) Element(org.eclipse.persistence.internal.oxm.schema.model.Element) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) 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