Search in sources :

Example 1 with DataObject

use of commonj.sdo.DataObject 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);
    }
}
Also used : HelperContext(commonj.sdo.helper.HelperContext) DataObject(commonj.sdo.DataObject) DataObject(commonj.sdo.DataObject) DataFactory(commonj.sdo.helper.DataFactory) XMLDocument(commonj.sdo.helper.XMLDocument) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(jakarta.xml.bind.JAXBException)

Example 2 with DataObject

use of commonj.sdo.DataObject in project metro-jax-ws by eclipse-ee4j.

the class SDOBond method marshal.

@Override
public void marshal(T object, XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
    /*  Didn't work due to bug 8539542
        StAXResult result = new StAXResult(writer);
        sdoXMLHelper.save(xmlDoc, result, null);
        */
    try {
        output.flush();
    } catch (Exception e) {
        e.printStackTrace();
    }
    SAX2StaxContentHandler handler = new SAX2StaxContentHandler(output);
    if (object instanceof DataObject) {
        serializeDataObject((DataObject) object, new SAXResult(handler), am);
        return;
    }
    try {
        String value = serializePrimitive(object, javaType);
        String prefix = output.getPrefix(xmlTag.getNamespaceURI());
        // TODO, this is a hack, seems to be wrong. why should namespace returned  is ""?
        if (xmlTag.getNamespaceURI().equals("")) {
            output.writeStartElement("", xmlTag.getLocalPart(), xmlTag.getNamespaceURI());
        // } else if (prefix == null) {
        // output.writeStartElement(xmlTag.getNamespaceURI(), xmlTag.getLocalPart());
        } else {
            output.writeStartElement(prefix, xmlTag.getLocalPart(), xmlTag.getNamespaceURI());
            output.writeNamespace(prefix, xmlTag.getNamespaceURI());
        }
        output.writeCharacters(value);
        output.writeEndElement();
    } catch (XMLStreamException e) {
        throw new SDODatabindingException(e);
    }
}
Also used : DataObject(commonj.sdo.DataObject) SAXResult(javax.xml.transform.sax.SAXResult) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(jakarta.xml.bind.JAXBException)

Example 3 with DataObject

use of commonj.sdo.DataObject in project metro-jax-ws by eclipse-ee4j.

the class SDOBond method marshal.

@Override
public void marshal(T object, OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
    if (object instanceof DataObject) {
        serializeDataObject((DataObject) object, new StreamResult(output), am);
        return;
    }
    try {
        String value = serializePrimitive(object, javaType);
        String prefix = nsContext.getPrefix(xmlTag.getNamespaceURI());
        StringBuilder sb = new StringBuilder();
        if ("".equals(prefix)) {
            sb.append("<").append(xmlTag.getLocalPart()).append(">");
            sb.append(value);
            sb.append("</").append(xmlTag.getLocalPart()).append(">");
        } else if (prefix != null) {
            sb.append("<").append(prefix).append(":").append(xmlTag.getLocalPart()).append(">");
            sb.append(value);
            sb.append("</").append(prefix).append(":").append(xmlTag.getLocalPart()).append(">");
        } else {
            // Unbound namespace!
            sb.append("<ns1:").append(xmlTag.getLocalPart()).append(" xmlns:ns1=\"").append(xmlTag.getNamespaceURI()).append("\"").append(">");
            sb.append(value);
            sb.append("</ns1:").append(xmlTag.getLocalPart()).append(">");
        }
    } catch (Exception e) {
        throw new SDODatabindingException(e);
    }
}
Also used : DataObject(commonj.sdo.DataObject) StreamResult(javax.xml.transform.stream.StreamResult) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(jakarta.xml.bind.JAXBException)

Example 4 with DataObject

use of commonj.sdo.DataObject in project metro-jax-ws by eclipse-ee4j.

the class SDOBond method marshal.

@Override
public void marshal(T object, ContentHandler contentHandler, AttachmentMarshaller am) throws JAXBException {
    Result res = new SAXResult(contentHandler);
    if (object instanceof DataObject) {
        serializeDataObject((DataObject) object, res, null);
        return;
    }
    String value = serializePrimitive(object, javaType);
    serializeToResult(value, res);
}
Also used : DataObject(commonj.sdo.DataObject) SAXResult(javax.xml.transform.sax.SAXResult) StreamResult(javax.xml.transform.stream.StreamResult) SAXResult(javax.xml.transform.sax.SAXResult) DOMResult(javax.xml.transform.dom.DOMResult)

Example 5 with DataObject

use of commonj.sdo.DataObject in project metro-jax-ws by eclipse-ee4j.

the class SDOBond method marshal.

@Override
public void marshal(T object, Node output) throws JAXBException {
    Result res = new DOMResult(output);
    if (object instanceof DataObject) {
        serializeDataObject((DataObject) object, res, null);
        return;
    }
    String value = serializePrimitive(object, javaType);
    serializeToResult(value, res);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) DataObject(commonj.sdo.DataObject) StreamResult(javax.xml.transform.stream.StreamResult) SAXResult(javax.xml.transform.sax.SAXResult) DOMResult(javax.xml.transform.dom.DOMResult)

Aggregations

DataObject (commonj.sdo.DataObject)6 JAXBException (jakarta.xml.bind.JAXBException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 SAXResult (javax.xml.transform.sax.SAXResult)3 StreamResult (javax.xml.transform.stream.StreamResult)3 DataFactory (commonj.sdo.helper.DataFactory)2 HelperContext (commonj.sdo.helper.HelperContext)2 XMLDocument (commonj.sdo.helper.XMLDocument)2 DOMResult (javax.xml.transform.dom.DOMResult)2 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)1