Examples of XoXMLStreamWriter


Examples of com.envoisolutions.sxc.util.XoXMLStreamWriter

                throw new MarshalException("Object must be annotated with @XmlRootElement or be a JAXBElement!");
            }
           
            Boolean frag = (Boolean) getProperty(Marshaller.JAXB_FRAGMENT);
           
            XoXMLStreamWriter w = new XoXMLStreamWriterImpl(xsw);
            if (frag == null || !frag) {
                w.writeStartDocument();
            }
           
            JAXBElement jaxbElement = null;
            if (o instanceof JAXBElement) {
                jaxbElement = (JAXBElement) o;
            }
           
            if (jaxbElement != null) {
                QName n = jaxbElement.getName();
                w.writeStartElement("",  n.getLocalPart(), n.getNamespaceURI());
                // TODO: we should check to see if a NS is already written here
                w.writeDefaultNamespace(n.getNamespaceURI());
               
                o = jaxbElement.getValue();
            }
           
            if (o == null) {
                w.writeXsiNil();
            } else {
                Class c = o.getClass();
                if (c == String.class) {
                    w.writeCharacters((String) o);
                } else if (c == Boolean.class) {
                    w.writeBoolean((Boolean) o);
                } else if (c == Byte.class) {
                    w.writeByte((Byte) o);
                } else if (c == Double.class) {
                    w.writeDouble((Double) o);
                } else if (c == Float.class) {
                    w.writeFloat((Float) o);
                } else if (c == Long.class) {
                    w.writeLong((Long) o);
                } else if (c == Integer.class) {
                    w.writeInt((Integer) o);
                } else if (c == Short.class) {
                    w.writeShort((Short) o);
                } else if (c == Duration.class) {
                    w.writeCharacters(((Duration) o).toString());
                } else if (c == XMLGregorianCalendar.class) {
                    w.writeCharacters(((XMLGregorianCalendar) o).toXMLFormat());
                } else if (c == byte[].class) {
                    BinaryUtils.encodeBytes(w, (byte[]) o);
                } else {
                    context.createWriter().write(w, o);
                }
            }
           
            if (jaxbElement != null) {
                w.writeEndElement();
            }
           
            if (frag == null || !frag) {
                w.writeEndDocument();
            }
        } catch (Exception e) {
            if (e instanceof JAXBException) {
                throw (JAXBException) e;
            } else if (e instanceof RuntimeException) {
View Full Code Here

Examples of com.envoisolutions.sxc.util.XoXMLStreamWriter

        try {
            if (!introspector.isElement(o)) {
                throw new MarshalException("Object must be annotated with @XmlRootElement or be a JAXBElement!");
            }
           
            XoXMLStreamWriter w = new XoXMLStreamWriterImpl(xsw);
            if (writeStartAndEnd) {
                w.writeStartDocument();
            }
           
            JAXBElement jaxbElement = null;
            if (o instanceof JAXBElement) {
                jaxbElement = (JAXBElement) o;
            }
           
            if (jaxbElement != null) {
                QName n = jaxbElement.getName();
                w.writeStartElement("",  n.getLocalPart(), n.getNamespaceURI());
                // TODO: we should check to see if a NS is already written here
                w.writeDefaultNamespace(n.getNamespaceURI());
               
                o = jaxbElement.getValue();
            }
           
            if (o == null) {
                w.writeXsiNil();
            } else {
                Class c = o.getClass();
                if (c == String.class) {
                    w.writeCharacters((String) o);
                } else if (c == Boolean.class) {
                    w.writeBoolean((Boolean) o);
                } else if (c == Byte.class) {
                    w.writeByte((Byte) o);
                } else if (c == Double.class) {
                    w.writeDouble((Double) o);
                } else if (c == Float.class) {
                    w.writeFloat((Float) o);
                } else if (c == Long.class) {
                    w.writeLong((Long) o);
                } else if (c == Integer.class) {
                    w.writeInt((Integer) o);
                } else if (c == Short.class) {
                    w.writeShort((Short) o);
                } else if (c == Duration.class) {
                    w.writeCharacters(((Duration) o).toString());
                } else if (c == XMLGregorianCalendar.class) {
                    w.writeCharacters(((XMLGregorianCalendar) o).toXMLFormat());
                } else if (c == byte[].class) {
                    BinaryUtils.encodeBytes(w, (byte[]) o);
                } else {
                    context.createWriter().write(w, o);
                }
            }
           
            if (jaxbElement != null) {
                w.writeEndElement();
            }
           
            if (writeStartAndEnd) {
                w.writeEndDocument();
            }
        } catch (Exception e) {
            if (e instanceof JAXBException) {
                throw (JAXBException) e;
            } else if (e instanceof RuntimeException) {
View Full Code Here

Examples of com.envoisolutions.sxc.util.XoXMLStreamWriter

        if (isFormattedOutput()) {
            writer = new PrettyPrintXMLStreamWriter(writer);
        }

        // writer with out custom extension
        XoXMLStreamWriter w = new XoXMLStreamWriterImpl(writer);

        try {
            // if the is not a fragment, write the document header
            if (!isFragment()) {
                w.writeStartDocument(getEncoding(), null);
            }

            // write xsi:type if there is no default root element for this type
            boolean writeXsiType = true;
            if (jaxbElement instanceof JAXBElement) {
                writeXsiType = ((JAXBElement)jaxbElement).isTypeSubstituted();
            } else {
                JAXBObject jaxbObject = introspector.getJaxbMarshaller(jaxbElement.getClass());
                if (jaxbObject != null) {
                    writeXsiType = jaxbObject.getXmlRootElement() == null && jaxbObject.getXmlType() != null;
                }
            }

            write(jaxbElement, w, new RuntimeContext(this), true, writeXsiType);

            if (!isFragment()) {
                w.writeEndDocument();
            }
        } catch (XMLStreamException e) {
            throw new MarshalException(e);
        }
    }
View Full Code Here

Examples of org.metatype.sxc.util.XoXMLStreamWriter

        XMLStreamWriter writer = null;
        try {
            final XMLOutputFactory xof = getXmOutputFactory();
            writer = xof.createXMLStreamWriter(streamResult.getOutputStream(), "UTF-8");
            writer = new PrettyPrintXMLStreamWriter(writer);
            final XoXMLStreamWriter w = new XoXMLStreamWriterImpl(writer);

            try {
                w.writeStartDocument("UTF-8", null);

                // write xsi:type if there is no default root element for this type

                final RuntimeContext context = new RuntimeContext((ExtendedMarshaller) null);

                try {

                    final QName name = objectType.getXmlRootElement();

                    // open element
                    w.writeStartElementWithAutoPrefix(name.getNamespaceURI(), name.getLocalPart());

                    objectType.write(w, object, context);

                    w.writeEndElement();
                } catch (Exception e) {
                    if (e instanceof JAXBException) {
                        // assume event handler has already been notified
                        throw (JAXBException) e;
                    }
                    if (e instanceof RuntimeXMLStreamException) {
                        // simply unwrap and handle below
                        e = ((RuntimeXMLStreamException) e).getCause();
                    }

                    if (e instanceof XMLStreamException) {
                        final Throwable cause = e.getCause();
                        if (cause instanceof JAXBException) {
                            throw (JAXBException) e;
                        }
                        throw new MarshalException(cause == null ? e : cause);
                    }
                    throw new MarshalException(e);

                }

                w.writeEndDocument();
            } catch (final Exception e) {
                throw new MarshalException(e);
            }

View Full Code Here

Examples of org.metatype.sxc.util.XoXMLStreamWriter

        XMLStreamWriter writer = null;
        try {
            final XMLOutputFactory xof = getXmOutputFactory();
            writer = xof.createXMLStreamWriter(streamResult.getOutputStream(), "UTF-8");
            writer = new PrettyPrintXMLStreamWriter(writer);
            final XoXMLStreamWriter w = new XoXMLStreamWriterImpl(writer);

            try {
                w.writeStartDocument("UTF-8", null);

                // write xsi:type if there is no default root element for this type

                final RuntimeContext context = new RuntimeContext((ExtendedMarshaller) null);

                try {

                    final QName name = objectType.getXmlRootElement();

                    // open element
                    w.writeStartElementWithAutoPrefix(name.getNamespaceURI(), name.getLocalPart());

                    objectType.write(w, object, context);

                    w.writeEndElement();
                } catch (Exception e) {
                    if (e instanceof JAXBException) {
                        // assume event handler has already been notified
                        throw (JAXBException) e;
                    }
                    if (e instanceof RuntimeXMLStreamException) {
                        // simply unwrap and handle below
                        e = ((RuntimeXMLStreamException) e).getCause();
                    }

                    if (e instanceof XMLStreamException) {
                        final Throwable cause = e.getCause();
                        if (cause instanceof JAXBException) {
                            throw (JAXBException) e;
                        }
                        throw new MarshalException(cause == null ? e : cause);
                    }
                    throw new MarshalException(e);

                }

                w.writeEndDocument();
            } catch (final Exception e) {
                throw new MarshalException(e);
            }

View Full Code Here

Examples of org.metatype.sxc.util.XoXMLStreamWriter

        XMLStreamWriter writer = null;
        try {
            final XMLOutputFactory xof = getXmOutputFactory();
            writer = xof.createXMLStreamWriter(streamResult.getOutputStream(), "UTF-8");
            writer = new PrettyPrintXMLStreamWriter(writer);
            XoXMLStreamWriter w = new XoXMLStreamWriterImpl(writer);

            try {
                w.writeStartDocument("UTF-8", null);

                // write xsi:type if there is no default root element for this type

                final RuntimeContext context = new RuntimeContext((ExtendedMarshaller) null);

                try {

                    QName name = objectType.getXmlRootElement();

                    // open element
                    w.writeStartElementWithAutoPrefix(name.getNamespaceURI(), name.getLocalPart());

                    objectType.write(w, object, context);

                    w.writeEndElement();
                } catch (Exception e) {
                    if (e instanceof JAXBException) {
                        // assume event handler has already been notified
                        throw (JAXBException) e;
                    }
                    if (e instanceof RuntimeXMLStreamException) {
                        // simply unwrap and handle below
                        e = ((RuntimeXMLStreamException) e).getCause();
                    }

                    if (e instanceof XMLStreamException) {
                        Throwable cause = e.getCause();
                        if (cause instanceof JAXBException) {
                            throw (JAXBException) e;
                        }
                        throw new MarshalException(cause == null ? e : cause);
                    }
                    throw new MarshalException(e);

                }

                w.writeEndDocument();
            } catch (Exception e) {
                throw new MarshalException(e);
            }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.