Search in sources :

Example 11 with Field

use of org.eclipse.persistence.internal.oxm.mappings.Field 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 12 with Field

use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method processXMLCompositeDirectCollectionMapping.

/**
 * Process a given XMLCompositeDirectCollectionMapping.
 */
protected void processXMLCompositeDirectCollectionMapping(DirectCollectionMapping mapping, Sequence seq, ComplexType ct, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties) {
    Field xmlField = ((Field) (mapping).getField());
    XPathFragment frag = xmlField.getXPathFragment();
    seq = buildSchemaComponentsForXPath(frag, seq, schemaForNamespace, workingSchema, properties);
    frag = getTargetXPathFragment(frag);
    String schemaTypeString = getSchemaTypeForElement(xmlField, mapping.getAttributeElementClass(), workingSchema);
    Element element = null;
    if (xmlField.usesSingleNode()) {
        SimpleType st = new SimpleType();
        org.eclipse.persistence.internal.oxm.schema.model.List list = new org.eclipse.persistence.internal.oxm.schema.model.List();
        if (schemaTypeString == null) {
            schemaTypeString = getSchemaTypeString(Constants.ANY_SIMPLE_TYPE_QNAME, workingSchema);
        }
        list.setItemType(schemaTypeString);
        st.setList(list);
        element = buildElement(xmlField.getXPathFragment(), null, Occurs.ZERO, null);
        element.setSimpleType(st);
    } else {
        if (frag.getNamespaceURI() != null) {
            element = handleFragNamespace(frag, schemaForNamespace, workingSchema, properties, element, schemaTypeString);
            element.setMaxOccurs(Occurs.UNBOUNDED);
        } else {
            element = buildElement(frag, schemaTypeString, Occurs.ZERO, Occurs.UNBOUNDED);
        }
    }
    if (mapping.getNullPolicy().isNullRepresentedByXsiNil()) {
        element.setNillable(true);
    }
    if (xmlField.isRequired()) {
        element.setMinOccurs("1");
    }
    seq.addElement(element);
}
Also used : Element(org.eclipse.persistence.internal.oxm.schema.model.Element) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) Field(org.eclipse.persistence.internal.oxm.mappings.Field) SimpleType(org.eclipse.persistence.internal.oxm.schema.model.SimpleType) List(java.util.List) ArrayList(java.util.ArrayList)

Example 13 with Field

use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.

the class SchemaModelGenerator method buildComplexTypeWithSimpleContent.

/**
 * Create and return a ComplexType containing simple content for a given XMLDescriptor.  Assumes
 * that the descriptor has a schema context set.
 */
private ComplexType buildComplexTypeWithSimpleContent(Descriptor desc, HashMap<String, Schema> schemaForNamespace, Schema workingSchema, SchemaModelGeneratorProperties properties, List<Descriptor> descriptors) {
    ComplexType ct = new ComplexType();
    SimpleContent sc = new SimpleContent();
    Extension extension = new Extension();
    sc.setExtension(extension);
    ct.setSimpleContent(sc);
    for (CoreMapping mapping : (Vector<CoreMapping>) desc.getMappings()) {
        Field xFld = (Field) mapping.getField();
        if (xFld.getXPath().equals(TEXT)) {
            extension.setBaseType(getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema));
        } else if (xFld.getXPathFragment().isAttribute()) {
            String schemaTypeString = getSchemaTypeForDirectMapping((DirectMapping) mapping, workingSchema);
            Attribute attr = buildAttribute((DirectMapping) mapping, schemaTypeString);
            extension.getOrderedAttributes().add(attr);
        }
    }
    return ct;
}
Also used : Extension(org.eclipse.persistence.internal.oxm.schema.model.Extension) 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) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) SimpleContent(org.eclipse.persistence.internal.oxm.schema.model.SimpleContent) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) ComplexType(org.eclipse.persistence.internal.oxm.schema.model.ComplexType) Vector(java.util.Vector)

Example 14 with Field

use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.

the class XMLVariableXPathMappingNodeValue method marshalSingleValue.

@Override
public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord marshalRecord, Object object, Object value, CoreAbstractSession session, NamespaceResolver namespaceResolver, MarshalContext marshalContext) {
    if (null == value) {
        return false;
    }
    Object originalValue = value;
    VariableXPathObjectMapping mapping = this.getMapping();
    Descriptor descriptor = (Descriptor) mapping.getReferenceDescriptor();
    if (descriptor.hasInheritance()) {
        Class<?> objectValueClass = value.getClass();
        if (!(objectValueClass == descriptor.getJavaClass())) {
            descriptor = (Descriptor) session.getDescriptor(objectValueClass);
        }
    }
    Marshaller marshaller = marshalRecord.getMarshaller();
    ObjectBuilder objectBuilder = (ObjectBuilder) descriptor.getObjectBuilder();
    List extraNamespaces = objectBuilder.addExtraNamespacesToNamespaceResolver(descriptor, marshalRecord, session, true, true);
    // Change to get the value from the object
    String defaultRootElementString = descriptor.getDefaultRootElement();
    marshalRecord.beforeContainmentMarshal(value);
    XPathFragment rootFragment = mapping.getXPathFragmentForValue(value, marshalRecord.getNamespaceResolver(), marshalRecord.isNamespaceAware(), marshalRecord.getNamespaceSeparator());
    XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);
    if (mapping.isAttribute()) {
        ObjectBuilder tob = (ObjectBuilder) mapping.getReferenceDescriptor().getObjectBuilder();
        MappingNodeValue textMappingNodeValue = (MappingNodeValue) tob.getRootXPathNode().getTextNode().getMarshalNodeValue();
        Mapping textMapping = textMappingNodeValue.getMapping();
        if (textMapping.isAbstractDirectMapping()) {
            DirectMapping xmlDirectMapping = (DirectMapping) textMapping;
            Object fieldValue = xmlDirectMapping.getFieldValue(xmlDirectMapping.valueFromObject(value, xmlDirectMapping.getField(), session), session, marshalRecord);
            QName schemaType = ((Field) xmlDirectMapping.getField()).getSchemaTypeForValue(fieldValue, session);
            marshalRecord.attribute(rootFragment, namespaceResolver, fieldValue, schemaType);
            // marshalRecord.closeStartGroupingElements(groupingFragment);
            return true;
        } else {
            return textMappingNodeValue.marshalSingleValue(rootFragment, marshalRecord, value, textMapping.getAttributeValueFromObject(value), session, namespaceResolver, marshalContext);
        }
    } else {
        marshalRecord.closeStartGroupingElements(groupingFragment);
        getXPathNode().startElement(marshalRecord, rootFragment, object, session, marshalRecord.getNamespaceResolver(), objectBuilder, value);
        writeExtraNamespaces(extraNamespaces, marshalRecord, session);
        marshalRecord.addXsiTypeAndClassIndicatorIfRequired(descriptor, (Descriptor) mapping.getReferenceDescriptor(), (Field) mapping.getField(), originalValue, value, false, false);
        objectBuilder.buildRow(marshalRecord, value, session, marshaller, null);
        marshalRecord.afterContainmentMarshal(object, value);
        marshalRecord.endElement(rootFragment, namespaceResolver);
        marshalRecord.removeExtraNamespacesFromNamespaceResolver(extraNamespaces, session);
    }
    return true;
}
Also used : QName(javax.xml.namespace.QName) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) Field(org.eclipse.persistence.internal.oxm.mappings.Field) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) List(java.util.List) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping)

Example 15 with Field

use of org.eclipse.persistence.internal.oxm.mappings.Field in project eclipselink by eclipse-ee4j.

the class XMLVariableXPathMappingNodeValue method attribute.

@Override
public void attribute(UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) {
    Descriptor referenceDescriptor = (Descriptor) getMapping().getReferenceDescriptor();
    ObjectBuilder treeObjectBuilder = (ObjectBuilder) referenceDescriptor.getObjectBuilder();
    MappingNodeValue textMappingNodeValue = (MappingNodeValue) treeObjectBuilder.getRootXPathNode().getTextNode().getNodeValue();
    Mapping textMapping = textMappingNodeValue.getMapping();
    Object childObject = referenceDescriptor.getInstantiationPolicy().buildNewInstance();
    if (textMapping.isAbstractDirectMapping()) {
        DirectMapping xmlDirectMapping = (DirectMapping) textMappingNodeValue.getMapping();
        Field xmlField = (Field) xmlDirectMapping.getField();
        Object realValue = unmarshalRecord.getXMLReader().convertValueBasedOnSchemaType(xmlField, value, (ConversionManager) unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager(), unmarshalRecord);
        Object convertedValue = xmlDirectMapping.getAttributeValue(realValue, unmarshalRecord.getSession(), unmarshalRecord);
        xmlDirectMapping.setAttributeValueInObject(childObject, convertedValue);
    } else {
        Object oldChildObject = unmarshalRecord.getCurrentObject();
        CompositeObjectMapping nestedXMLCompositeObjectMapping = (CompositeObjectMapping) textMappingNodeValue.getMapping();
        unmarshalRecord.setCurrentObject(childObject);
        textMappingNodeValue.attribute(unmarshalRecord, namespaceURI, localName, value);
        unmarshalRecord.setCurrentObject(oldChildObject);
    }
    setXPathInObject(namespaceURI, localName, childObject);
    setOrAddAttributeValue(unmarshalRecord, childObject, null, null);
}
Also used : Field(org.eclipse.persistence.internal.oxm.mappings.Field) Descriptor(org.eclipse.persistence.internal.oxm.mappings.Descriptor) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)

Aggregations

Field (org.eclipse.persistence.internal.oxm.mappings.Field)65 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)20 XMLField (org.eclipse.persistence.oxm.XMLField)20 QName (javax.xml.namespace.QName)18 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)18 JavaField (org.eclipse.persistence.jaxb.javamodel.JavaField)16 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)14 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)13 CompositeObjectMapping (org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping)12 ArrayList (java.util.ArrayList)11 Mapping (org.eclipse.persistence.internal.oxm.mappings.Mapping)11 AbstractNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy)11 List (java.util.List)10 BinaryDataMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)10 CoreMapping (org.eclipse.persistence.core.mappings.CoreMapping)9 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)8 SAXException (org.xml.sax.SAXException)8 CoreConverter (org.eclipse.persistence.core.mappings.converters.CoreConverter)7 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)7 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)7