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();
}
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);
}
}
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());
}
}
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);
}
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);
}
Aggregations