Search in sources :

Example 21 with XMLConversionManager

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

the class XMLChoiceCollectionMapping method initialize.

@Override
public void initialize(AbstractSession session) throws DescriptorException {
    super.initialize(session);
    if (this.converter != null) {
        this.converter.initialize(this, session);
    }
    ArrayList<XMLMapping> mappingsList = new ArrayList<>();
    mappingsList.addAll(getChoiceElementMappings().values());
    for (XMLMapping next : getChoiceElementMappingsByClass().values()) {
        if (!(mappingsList.contains(next))) {
            mappingsList.add(next);
        }
    }
    if (isAny) {
        // anyMapping = new XMLAnyCollectionMapping();
        mappingsList.add(anyMapping);
    }
    Iterator<XMLMapping> mappings = mappingsList.iterator();
    while (mappings.hasNext()) {
        DatabaseMapping nextMapping = (DatabaseMapping) mappings.next();
        Converter converter = null;
        if (fieldsToConverters != null) {
            converter = fieldsToConverters.get(nextMapping.getField());
        }
        if (nextMapping.isAbstractCompositeDirectCollectionMapping()) {
            XMLConversionManager xmlConversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager();
            QName schemaType = xmlConversionManager.schemaType(((AbstractCompositeDirectCollectionMapping) nextMapping).getAttributeElementClass());
            if (schemaType != null) {
                ((XMLField) nextMapping.getField()).setSchemaType(schemaType);
            }
            if (converter != null) {
                ((AbstractCompositeDirectCollectionMapping) nextMapping).setValueConverter(converter);
            }
            ((AbstractCompositeDirectCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
        } else if (nextMapping.isAbstractCompositeCollectionMapping()) {
            if (converter != null) {
                ((AbstractCompositeCollectionMapping) nextMapping).setConverter(converter);
            }
            ((AbstractCompositeCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
        } else if (nextMapping instanceof XMLBinaryDataCollectionMapping) {
            ((XMLBinaryDataCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
            if (converter != null) {
                ((XMLBinaryDataCollectionMapping) nextMapping).setValueConverter(converter);
            }
        } else if (nextMapping instanceof XMLAnyCollectionMapping) {
            ((XMLAnyCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
            if (converter != null && converter instanceof XMLConverter) {
                ((XMLAnyCollectionMapping) nextMapping).setConverter((XMLConverter) converter);
            }
        } else {
            ((XMLCollectionReferenceMapping) nextMapping).setContainerPolicy(getContainerPolicy());
            ((XMLCollectionReferenceMapping) nextMapping).setReuseContainer(true);
        }
        nextMapping.initialize(session);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) AbstractCompositeDirectCollectionMapping(org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping) Converter(org.eclipse.persistence.mappings.converters.Converter) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 22 with XMLConversionManager

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

the class XMLChoiceObjectMapping method initialize.

@Override
public void initialize(AbstractSession session) throws DescriptorException {
    super.initialize(session);
    if (this.converter != null) {
        this.converter.initialize(this, session);
    }
    ArrayList<XMLMapping> mappingsList = new ArrayList<>();
    mappingsList.addAll(getChoiceElementMappings().values());
    for (XMLMapping next : getChoiceElementMappingsByClass().values()) {
        if (!(mappingsList.contains(next))) {
            mappingsList.add(next);
        }
    }
    Iterator<XMLMapping> mappings = mappingsList.iterator();
    while (mappings.hasNext()) {
        DatabaseMapping nextMapping = (DatabaseMapping) mappings.next();
        Converter converter = null;
        if (fieldsToConverters != null) {
            converter = fieldsToConverters.get(nextMapping.getField());
        }
        if (nextMapping.isAbstractDirectMapping()) {
            ((XMLDirectMapping) nextMapping).setIsWriteOnly(this.isWriteOnly());
            if (converter != null) {
                ((AbstractDirectMapping) nextMapping).setConverter(converter);
            }
            XMLConversionManager xmlConversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager();
            QName schemaType = xmlConversionManager.schemaType(nextMapping.getAttributeClassification());
            if (schemaType != null && ((XMLField) nextMapping.getField()).getSchemaType() == null) {
                ((XMLField) nextMapping.getField()).setSchemaType(schemaType);
            }
        } else if (nextMapping instanceof XMLObjectReferenceMapping) {
            ((XMLObjectReferenceMapping) nextMapping).setIsWriteOnly(this.isWriteOnly);
        } else if (nextMapping instanceof XMLBinaryDataMapping) {
            ((XMLBinaryDataMapping) nextMapping).setIsCDATA(this.isWriteOnly);
            if (converter != null) {
                ((XMLBinaryDataMapping) nextMapping).setConverter(converter);
            }
        } else {
            ((XMLCompositeObjectMapping) nextMapping).setIsWriteOnly(this.isWriteOnly());
            if (converter != null) {
                ((AbstractCompositeObjectMapping) nextMapping).setConverter(converter);
            }
        }
        nextMapping.initialize(session);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) QName(javax.xml.namespace.QName) AbstractCompositeObjectMapping(org.eclipse.persistence.mappings.foundation.AbstractCompositeObjectMapping) ArrayList(java.util.ArrayList) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) AbstractDirectMapping(org.eclipse.persistence.mappings.foundation.AbstractDirectMapping) Converter(org.eclipse.persistence.mappings.converters.Converter) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) XMLRootConverter(org.eclipse.persistence.oxm.mappings.converters.XMLRootConverter) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 23 with XMLConversionManager

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

the class DateAndTimeTestCases method testSqlDateToString_dateTime_dstTimeZone.

public void testSqlDateToString_dateTime_dstTimeZone() {
    XMLConversionManager xmlConversionManager = (XMLConversionManager) XMLConversionManager.getDefaultXMLManager().clone();
    xmlConversionManager.setTimeZone(TimeZone.getTimeZone(CONTROL_DST_TIME_ZONE));
    xmlConversionManager.setTimeZoneQualified(true);
    java.sql.Date sqlDate = xmlConversionManager.convertObject(CONTROL_DST_INPUT_DATE_TIME, java.sql.Date.class, XMLConstants.DATE_TIME_QNAME);
    String testString = xmlConversionManager.convertObject(sqlDate, String.class, XMLConstants.DATE_TIME_QNAME);
    assertEquals("2003-08-29T03:00:00" + controlXmlConversionTimeSuffix + "-04:00", testString);
}
Also used : XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 24 with XMLConversionManager

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

the class DateAndTimeTestCases method testSqlTimestampToString_default_dstTimeZone.

public void testSqlTimestampToString_default_dstTimeZone() {
    XMLConversionManager xmlConversionManager = (XMLConversionManager) XMLConversionManager.getDefaultXMLManager().clone();
    xmlConversionManager.setTimeZone(TimeZone.getTimeZone(CONTROL_DST_TIME_ZONE));
    xmlConversionManager.setTimeZoneQualified(true);
    java.sql.Timestamp sqlTimestamp = xmlConversionManager.convertObject(CONTROL_DST_INPUT_DATE_TIME, Timestamp.class, XMLConstants.DATE_TIME_QNAME);
    String testString = xmlConversionManager.convertObject(sqlTimestamp, String.class);
    assertEquals("2003-08-29T03:00:00" + controlXmlConversionTimeSuffix + "-04:00", testString);
}
Also used : Timestamp(java.sql.Timestamp) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 25 with XMLConversionManager

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

the class DateAndTimeTestCases method testUtilDateToString_dateTime_dstTimeZone.

public void testUtilDateToString_dateTime_dstTimeZone() {
    XMLConversionManager xmlConversionManager = (XMLConversionManager) XMLConversionManager.getDefaultXMLManager().clone();
    xmlConversionManager.setTimeZone(TimeZone.getTimeZone(CONTROL_DST_TIME_ZONE));
    xmlConversionManager.setTimeZoneQualified(true);
    java.util.Date utilDate = xmlConversionManager.convertObject(CONTROL_DST_INPUT_DATE_TIME, java.util.Date.class);
    String testString = xmlConversionManager.convertObject(utilDate, String.class, XMLConstants.DATE_TIME_QNAME);
    assertEquals("2003-08-29T03:00:00" + controlXmlConversionTimeSuffix + "-04:00", testString);
}
Also used : XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Aggregations

XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)34 XMLField (org.eclipse.persistence.oxm.XMLField)12 QName (javax.xml.namespace.QName)10 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)8 ArrayList (java.util.ArrayList)6 Element (org.w3c.dom.Element)6 Time (java.sql.Time)4 Timestamp (java.sql.Timestamp)4 Vector (java.util.Vector)3 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)3 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)3 SDOType (org.eclipse.persistence.sdo.SDOType)3 DataObject (commonj.sdo.DataObject)2 Property (commonj.sdo.Property)2 Type (commonj.sdo.Type)2 DataHandler (jakarta.activation.DataHandler)2 List (java.util.List)2 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)2 XMLBinaryDataHelper (org.eclipse.persistence.internal.oxm.XMLBinaryDataHelper)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2