Search in sources :

Example 1 with SDOMarshalListener

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

the class SDOXMLHelperDelegate method getXmlMarshaller.

private XMLMarshaller getXmlMarshaller(Object options) {
    XMLMarshaller xmlMarshaller = getXmlMarshaller().clone();
    if (null == options) {
        return xmlMarshaller;
    }
    try {
        DataObject optionsDO = (DataObject) options;
        if (optionsDO.isSet(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)) {
            xmlMarshaller.setAttachmentMarshaller((XMLAttachmentMarshaller) optionsDO.get(SDOConstants.ATTACHMENT_MARSHALLER_OPTION));
        }
        xmlMarshaller.setMarshalListener(new SDOMarshalListener(xmlMarshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
        return xmlMarshaller;
    } catch (ClassCastException ccException) {
        throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
    }
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) DataObject(commonj.sdo.DataObject) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener)

Example 2 with SDOMarshalListener

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

the class SDOXMLHelperDelegate method save.

@Override
public void save(XMLDocument xmlDocument, Result result, Object options) throws IOException {
    if (xmlDocument == null) {
        throw new IllegalArgumentException(SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument"));
    }
    if (result instanceof StreamResult) {
        StreamResult streamResult = (StreamResult) result;
        Writer writer = streamResult.getWriter();
        if (null == writer) {
            save(xmlDocument, streamResult.getOutputStream(), options);
        } else {
            save(xmlDocument, writer, options);
        }
    } else {
        // get XMLMarshaller once - as we may create a new instance if this helper isDirty=true
        XMLMarshaller anXMLMarshaller = getXmlMarshaller(options);
        // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML
        anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration());
        anXMLMarshaller.setEncoding(xmlDocument.getEncoding());
        anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation());
        anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation());
        SDOMarshalListener listener = ((SDOMarshalListener) anXMLMarshaller.getMarshalListener());
        listener.setMarshalledObject(xmlDocument.getRootObject());
        listener.setMarshalledObjectRootQName(new QName(xmlDocument.getRootElementURI(), xmlDocument.getRootElementName()));
        if (result instanceof SAXResult) {
            ContentHandlerRecord marshalRecord = new ContentHandlerRecord();
            marshalRecord.setContentHandler(((SAXResult) result).getHandler());
            marshalRecord.setMarshaller(anXMLMarshaller);
            listener.setRootMarshalRecord(marshalRecord);
            anXMLMarshaller.marshal(xmlDocument, marshalRecord);
            marshalRecord.flush();
        } else if (result instanceof DOMResult) {
            NodeRecord marshalRecord = new NodeRecord();
            marshalRecord.setDOM(((DOMResult) result).getNode());
            marshalRecord.setMarshaller(anXMLMarshaller);
            listener.setRootMarshalRecord(marshalRecord);
            anXMLMarshaller.marshal(xmlDocument, marshalRecord);
            marshalRecord.flush();
        } else {
            StringWriter writer = new StringWriter();
            this.save(xmlDocument, writer, options);
            String xml = writer.toString();
            StreamSource source = new StreamSource(new java.io.StringReader(xml));
            anXMLMarshaller.getTransformer().transform(source, result);
        }
        listener.setMarshalledObject(null);
        listener.setMarshalledObjectRootQName(null);
        listener.setRootMarshalRecord(null);
    }
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) StreamResult(javax.xml.transform.stream.StreamResult) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) NodeRecord(org.eclipse.persistence.oxm.record.NodeRecord) SAXResult(javax.xml.transform.sax.SAXResult) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) ContentHandlerRecord(org.eclipse.persistence.oxm.record.ContentHandlerRecord)

Example 3 with SDOMarshalListener

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

the class SDODataObjectGetPathTest method testGetXPathFromAncestorDeletedFromChildToAncestorInsideListWrapperLoggingOn.

public void testGetXPathFromAncestorDeletedFromChildToAncestorInsideListWrapperLoggingOn() {
    SDODataObject anItem = (SDODataObject) aRoot5.get("billTo/phone[1]");
    // start logging
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    aCS.beginLogging();
    assertTrue(aCS.isLogging());
    // delete source object
    SDODataObject deletedObjectParent = ((SDODataObject) aRoot5.get("billTo"));
    // detach();
    deletedObjectParent.delete();
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(anItem, aRoot5, aRoot5.getChangeSummary());
    // SDODataObject anItemFromPath = (SDODataObject)aRoot5.get(aPath);
    // System.out.println("testGetPathFromAncestorDeletedFromChildToRootLoggingOn: " + aPath);
    assertNotNull(aPath);
    // TODO: no storage of deleted indexed postition - defaults to size() = start of list for now
    // see SDODataObject: index = ((SDODataObject)parent).getList(aChild).size();
    assertEquals("ns0:billTo/ns0:phone[1]", aPath);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 4 with SDOMarshalListener

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

the class SDODataObjectGetPathTest method testGetPathFromAncestorDetachedFromChildToAncestorInsideListWrapperLoggingOn.

// TODO: This case fails to find a path because the oldSettings map is not populated during detach()
public void testGetPathFromAncestorDetachedFromChildToAncestorInsideListWrapperLoggingOn() {
    SDODataObject anItem = (SDODataObject) aRoot5.get("items/item[2]");
    // start logging
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    aCS.beginLogging();
    assertTrue(aCS.isLogging());
    // delete source object
    // SDODataObject deletedObject = ((SDODataObject)aRoot5.get("items"));
    anItem.detach();
    // String aPath = anItem.getPathFromAncestor(aCS, aRoot5, useXPathFormat);
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(anItem, aRoot5, aRoot5.getChangeSummary());
    // SDODataObject anItemFromPath = (SDODataObject)aRoot5.get(aPath);
    assertNotNull(aPath);
    // TODO: no storage of deleted indexed postition - defaults to size() = start of list for now
    // see SDODataObject: index = ((SDODataObject)parent).getList(aChild).size();
    assertEquals("ns0:items/ns0:item[2]", aPath);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 5 with SDOMarshalListener

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

the class SDODataObjectGetPathTest method testGetXPathFromAncestorDeletedFromChildToRootInsideListWrapperLoggingOn.

public void testGetXPathFromAncestorDeletedFromChildToRootInsideListWrapperLoggingOn() {
    SDODataObject anItem = (SDODataObject) aRoot5.get("items/item[2]");
    // start logging
    SDOChangeSummary aCS = aRoot5.getChangeSummary();
    aCS.beginLogging();
    assertTrue(aCS.isLogging());
    // delete source object
    // SDODataObject deletedObject = ((SDODataObject)aRoot5.get("items"));
    // detach();
    anItem.delete();
    String aPath = ((SDOMarshalListener) ((SDOXMLHelper) xmlHelper).getXmlMarshaller().getMarshalListener()).getPathFromAncestor(anItem, aRoot5, aRoot5.getChangeSummary());
    // SDODataObject anItemFromPath = (SDODataObject)aRoot5.get(aPath);
    // System.out.println("testGetPathFromAncestorDeletedFromChildToRootLoggingOn: " + aPath);
    assertNotNull(aPath);
    // TODO: no storage of deleted indexed postition - defaults to size() = start of list for now
    // see SDODataObject: index = ((SDODataObject)parent).getList(aChild).size();
    assertEquals("ns0:items/ns0:item[2]", aPath);
}
Also used : SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Aggregations

SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)27 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)22 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)20 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)16 QName (javax.xml.namespace.QName)3 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)3 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)2 FormattedWriterRecord (org.eclipse.persistence.oxm.record.FormattedWriterRecord)2 WriterRecord (org.eclipse.persistence.oxm.record.WriterRecord)2 SDOType (org.eclipse.persistence.sdo.SDOType)2 SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)2 DataObject (commonj.sdo.DataObject)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 DOMResult (javax.xml.transform.dom.DOMResult)1 SAXResult (javax.xml.transform.sax.SAXResult)1 StreamResult (javax.xml.transform.stream.StreamResult)1