use of commonj.sdo.helper.XMLDocument in project metro-jax-ws by eclipse-ee4j.
the class SDOUtils method sdoToXML.
/**
* Serialize a DataObject to the specified xml element in text xml
*/
public static Source sdoToXML(HelperContext hc, DataObject obj, String targetNamespace, String localName) throws ParserConfigurationException, IOException {
SDOXMLHelper sdoXMLHelper = (SDOXMLHelper) hc.getXMLHelper();
sdoXMLHelper.setTimeZone(TimeZone.getTimeZone("GMT"));
sdoXMLHelper.setTimeZoneQualified(true);
XMLDocument xmlDoc = sdoXMLHelper.createDocument(obj, targetNamespace, localName);
if (xmlDoc == null) {
return null;
}
ByteArrayOutputStream bout = new ByteArrayOutputStream();
StreamResult result = new StreamResult(bout);
sdoXMLHelper.save(xmlDoc, result, null);
byte[] bytes = bout.toByteArray();
System.out.println("data obj converted to xml: " + new String(bytes));
return new StreamSource(new ByteArrayInputStream(bytes));
}
use of commonj.sdo.helper.XMLDocument in project metro-jax-ws by eclipse-ee4j.
the class SDOBond method deserialize.
private T deserialize(Source src, jakarta.xml.bind.attachment.AttachmentUnmarshaller au) {
try {
if (!commonj.sdo.DataObject.class.isAssignableFrom(javaType) && !javaType.isInterface()) {
return (T) deserializePrimitives(src);
}
HelperContext context = parent.getHelperContext();
SDOAttachmentUnmarshaller unmarshaller = null;
if (au != null) {
unmarshaller = new SDOAttachmentUnmarshaller(au);
}
DataFactory dataFactory = context.getDataFactory();
DataObject loadOptions = dataFactory.create(SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
// bug 8680450
loadOptions.set(SDOConstants.TYPE_LOAD_OPTION, theType);
if (unmarshaller != null) {
loadOptions.set(SDOConstants.ATTACHMENT_UNMARSHALLER_OPTION, unmarshaller);
}
XMLDocument xdoc = context.getXMLHelper().load(src, null, loadOptions);
DataObject obj = xdoc.getRootObject();
Object o = SDOUtils.unwrapPrimitives(obj);
// ClassCast possible without check
return (T) o;
} catch (Exception e) {
throw new SDODatabindingException(e);
}
}
use of commonj.sdo.helper.XMLDocument 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 commonj.sdo.helper.XMLDocument 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);
}
}
Aggregations