Search in sources :

Example 21 with SDOXMLHelper

use of org.eclipse.persistence.sdo.helper.SDOXMLHelper in project metro-jax-ws by eclipse-ee4j.

the class SDOUtils method sdoToDom.

/**
 * Serialize a DataObject to the specified element
 * Per bug  6120620,, we use only GMT timezone
 */
public static Element sdoToDom(HelperContext hc, DataObject obj, String targetNamespace, String localName) throws ParserConfigurationException, IOException {
    SDOXMLHelper sdoXMLHelper = (SDOXMLHelper) hc.getXMLHelper();
    // Removed this from JRF for ADF use case.
    // sdoXMLHelper.setTimeZone(TimeZone.getTimeZone("GMT"));
    sdoXMLHelper.setTimeZoneQualified(true);
    XMLDocument xmlDoc = sdoXMLHelper.createDocument(obj, targetNamespace, localName);
    if (xmlDoc == null) {
        return null;
    }
    Document doc = newDocumentBuilder().newDocument();
    DOMResult result = new DOMResult(doc);
    sdoXMLHelper.save(xmlDoc, result, null);
    return ((Document) result.getNode()).getDocumentElement();
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) Document(org.w3c.dom.Document) XMLDocument(commonj.sdo.helper.XMLDocument) XMLDocument(commonj.sdo.helper.XMLDocument)

Example 22 with SDOXMLHelper

use of org.eclipse.persistence.sdo.helper.SDOXMLHelper in project metro-jax-ws by eclipse-ee4j.

the class SDOBond method serializeDataObject.

private void serializeDataObject(DataObject java, Result result, jakarta.xml.bind.attachment.AttachmentMarshaller am) {
    logger.entering(CLASSNAME, "serializeDataObject");
    try {
        HelperContext context = parent.getHelperContext();
        SDOAttachmentMarshaller marshaller = null;
        if (am != null) {
            marshaller = new SDOAttachmentMarshaller(am);
        }
        // check Primitives for T
        SDOXMLHelper sdoXMLHelper = (SDOXMLHelper) context.getXMLHelper();
        // Bug 8909750 - Toplink already sets this to "GMT".  ADF
        // resets it before we get here, so don't change it again.
        // sdoXMLHelper.setTimeZone(TimeZone.getTimeZone("GMT"));
        sdoXMLHelper.setTimeZoneQualified(true);
        XMLDocument xmlDoc = sdoXMLHelper.createDocument(java, xmlTag.getNamespaceURI(), xmlTag.getLocalPart());
        if (xmlDoc == null) {
            return;
        }
        xmlDoc.setXMLDeclaration(false);
        DataObject saveOptions = null;
        if (marshaller != null) {
            DataFactory dataFactory = parent.getHelperContext().getDataFactory();
            saveOptions = dataFactory.create(SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
            saveOptions.set(SDOConstants.ATTACHMENT_MARSHALLER_OPTION, marshaller);
        }
        sdoXMLHelper.save(xmlDoc, result, saveOptions);
    } catch (Exception e) {
        throw new SDODatabindingException(e);
    }
}
Also used : HelperContext(commonj.sdo.helper.HelperContext) DataObject(commonj.sdo.DataObject) DataFactory(commonj.sdo.helper.DataFactory) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) XMLDocument(commonj.sdo.helper.XMLDocument) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(jakarta.xml.bind.JAXBException)

Example 23 with SDOXMLHelper

use of org.eclipse.persistence.sdo.helper.SDOXMLHelper in project eclipselink by eclipse-ee4j.

the class SDOResolvable method writeExternal.

/**
 * Purpose: Serialize an SDODataObject to an ObjectOutputStream This
 * function is mandated by the Externalizable interface. It writes binary
 * data in the same order as was will be read back in readExternal().
 *
 * Prerequisites: An object has already been constructed and associated with
 * the theSDODataObject member
 */
@Override
public void writeExternal(ObjectOutput objectOutput) throws IOException {
    GZIPOutputStream aGZIPOutputStream = null;
    ByteArrayOutputStream aByteOutputStream = null;
    // check whether we are a root DataObject, write gzip of the root
    if ((theSDODataObject.getContainer() == null)) {
        try {
            // is a root object
            String identifier = null;
            if (this.aHelperContext.getClass() == SDOHelperContext.class) {
                identifier = ((SDOHelperContext) this.aHelperContext).getIdentifier();
            }
            if (identifier != null && !(identifier.equals(""))) {
                objectOutput.writeByte(SDO_HELPER_CONTEXT_ID_IDENTIFIER);
                objectOutput.writeUTF(identifier);
            } else {
                objectOutput.writeByte(SDO_ROOT_OBJECT_IDENTIFIER);
            }
            // write root xml
            aByteOutputStream = new ByteArrayOutputStream();
            // chain a GZIP stream to the byte stream
            aGZIPOutputStream = new GZIPOutputStream(aByteOutputStream);
            // write XML Serialization of the root DataObject to the GZIP output stream
            XMLDocument aDocument = // 
            aHelperContext.getXMLHelper().createDocument(// 
            theSDODataObject, // root element URI
            SDOConstants.SDO_URL, SDOConstants.SDO_PREFIX + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + DEFAULT_ROOT_ELEMENT_NAME);
            ((SDOXMLHelper) aHelperContext.getXMLHelper()).serialize(aDocument, aGZIPOutputStream, null);
            // finished the stream to move compressed data from the Deflater
            aGZIPOutputStream.finish();
            // flush the streams
            aGZIPOutputStream.flush();
            aByteOutputStream.flush();
            // get bytes from ByteOutputStream
            byte[] buf = aByteOutputStream.toByteArray();
            // write gzip buffer length
            // compressed xml file length
            objectOutput.writeInt(buf.length);
            // write gzip buffer to ostream
            objectOutput.write(buf);
        } finally {
            // close streams on all Exceptions
            if (aGZIPOutputStream != null) {
                // Clover: false case testing requires IO/comm failure
                aGZIPOutputStream.close();
            }
            if (aByteOutputStream != null) {
                // Clover: false case testing requires IO/comm failure
                aByteOutputStream.close();
            }
        }
    } else {
        // Internal non-root object, write the path to the from this object to the root
        // call this function recursively again for the root object serialization
        objectOutput.writeByte(SDO_INTERNAL_OBJECT_IDENTIFIER);
        // write path to the root
        String aPath = theSDODataObject._getPath();
        objectOutput.writeUTF(aPath);
        // write root (via indirect recursion to SDOResolvable)
        objectOutput.writeObject(theSDODataObject.getRootObject());
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) XMLDocument(commonj.sdo.helper.XMLDocument)

Example 24 with SDOXMLHelper

use of org.eclipse.persistence.sdo.helper.SDOXMLHelper in project eclipselink by eclipse-ee4j.

the class SDODataObjectGetPathTest method testGetXPathFromAncestorDeletedFromRootToCurrentObjectLoggingOn.

public void testGetXPathFromAncestorDeletedFromRootToCurrentObjectLoggingOn() {
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(aRoot5, aRoot5, aRoot5.getChangeSummary());
    // start logging
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    aCS.beginLogging();
    assertTrue(aCS.isLogging());
    // delete source object
    aRoot5.delete();
    assertNotNull(aPath);
    assertEquals(SDOConstants.EMPTY_STRING, aPath);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper)

Example 25 with SDOXMLHelper

use of org.eclipse.persistence.sdo.helper.SDOXMLHelper in project eclipselink by eclipse-ee4j.

the class SDODataObjectGetPathTest method testGetPathFromAncestorFromChildToRoot.

public void testGetPathFromAncestorFromChildToRoot() {
    SDODataObject anItem = (SDODataObject) aRoot5.get("items/item[2]");
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(anItem, aRoot5, anItem.getChangeSummary());
    assertNotNull(aPath);
    assertEquals("ns0:items/ns0:item[2]", aPath);
}
Also used : SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Aggregations

SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)40 SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)22 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)21 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)16 XMLDocument (commonj.sdo.helper.XMLDocument)6 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)6 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)5 XMLAttachmentMarshaller (org.eclipse.persistence.oxm.attachment.XMLAttachmentMarshaller)5 XMLAttachmentUnmarshaller (org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 SDOType (org.eclipse.persistence.sdo.SDOType)3 SDOClassLoader (org.eclipse.persistence.sdo.helper.SDOClassLoader)3 SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)3 DataObject (commonj.sdo.DataObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)2 Type (commonj.sdo.Type)1