Search in sources :

Example 1 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class PooledMarshaller method marshal.

/**
 * Delegates the marshalling to the wrapped marshaller.
 */
@Override
public void marshal(Object object, final Node output) throws JAXBException {
    // Must be call before getTransformVersion()
    object = toImplementation(object);
    final TransformVersion version = getTransformVersion();
    if (version != null)
        try {
            marshal(object, OutputFactory.createXMLEventWriter(output), version);
        } catch (XMLStreamException e) {
            throw new JAXBException(e);
        }
    else {
        // Marshalling to the default GML version.
        final Context context = begin();
        try {
            marshaller.marshal(object, output);
        } finally {
            context.finish();
        }
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException)

Example 2 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class PooledMarshaller method marshal.

/**
 * Delegates the marshalling to the wrapped marshaller.
 */
@Override
public void marshal(Object object, final File output) throws JAXBException {
    // Must be call before getTransformVersion()
    object = toImplementation(object);
    final TransformVersion version = getTransformVersion();
    if (version != null)
        try {
            try (OutputStream s = new BufferedOutputStream(new FileOutputStream(output))) {
                marshal(object, OutputFactory.createXMLEventWriter(s, getEncoding()), version);
            }
        } catch (IOException | XMLStreamException e) {
            throw new JAXBException(e);
        }
    else {
        // Marshalling to the default GML version.
        final Context context = begin();
        try {
            marshaller.marshal(object, output);
        } finally {
            context.finish();
        }
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) JAXBException(javax.xml.bind.JAXBException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class PooledMarshaller method getNode.

/**
 * Delegates the marshalling to the wrapped marshaller.
 */
@Override
public Node getNode(Object object) throws JAXBException {
    // Must be call before getTransformVersion()
    object = toImplementation(object);
    final TransformVersion version = getTransformVersion();
    if (version != null) {
        // This exception is thrown by javax.xml.bind.helpers.AbstractMarshallerImpl anyway.
        throw new UnsupportedOperationException();
    } else {
        final Context context = begin();
        try {
            return marshaller.getNode(object);
        } finally {
            context.finish();
        }
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 4 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class PooledMarshaller method marshal.

/**
 * Delegates the marshalling to the wrapped marshaller.
 */
@Override
public void marshal(Object object, XMLEventWriter output) throws JAXBException {
    // Must be call before getTransformVersion()
    object = toImplementation(object);
    final TransformVersion version = getTransformVersion();
    if (version != null) {
        output = new TransformingWriter(output, version);
    }
    final Context context = begin();
    try {
        marshaller.marshal(object, output);
    } finally {
        context.finish();
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 5 with Context

use of org.apache.sis.internal.jaxb.Context in project sis by apache.

the class PooledMarshaller method marshal.

/**
 * Delegates the marshalling to the wrapped marshaller.
 */
@Override
public void marshal(Object object, final ContentHandler output) throws JAXBException {
    // Must be call before getTransformVersion()
    object = toImplementation(object);
    final TransformVersion version = getTransformVersion();
    if (version != null)
        try {
            marshal(object, OutputFactory.createXMLEventWriter(output), version);
        } catch (XMLStreamException e) {
            throw new JAXBException(e);
        }
    else {
        // Marshalling to the default GML version.
        final Context context = begin();
        try {
            marshaller.marshal(object, output);
        } finally {
            context.finish();
        }
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

Context (org.apache.sis.internal.jaxb.Context)32 JAXBException (javax.xml.bind.JAXBException)7 XMLStreamException (javax.xml.stream.XMLStreamException)6 Locale (java.util.Locale)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 DefaultInternationalString (org.apache.sis.util.iso.DefaultInternationalString)2 Test (org.junit.Test)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 XmlAdapter (javax.xml.bind.annotation.adapters.XmlAdapter)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 CodeListUID (org.apache.sis.internal.jaxb.cat.CodeListUID)1 GO_CharacterString (org.apache.sis.internal.jaxb.gco.GO_CharacterString)1 Anchor (org.apache.sis.internal.jaxb.gcx.Anchor)1