Search in sources :

Example 26 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 Writer 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 27 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 XMLStreamWriter 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 28 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 Result 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 29 with Context

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

the class PooledUnmarshaller method unmarshal.

/**
 * Unmarshals to the given input with on-the-fly substitution of namespaces.
 * This method is invoked when we may marshal a different GML or metadata version than the one
 * supported natively by SIS, i.e. when {@link #getTransformVersion()} returns a non-null value.
 *
 * @param  input    the reader created by SIS (<b>not</b> the reader given by the user).
 * @param  version  identify the namespace substitutions to perform.
 * @return the unmarshalled object.
 */
private Object unmarshal(XMLEventReader input, final TransformVersion version) throws XMLStreamException, JAXBException {
    input = new TransformingReader(input, version);
    final Context context = begin();
    final Object object;
    try {
        object = unmarshaller.unmarshal(input);
    } finally {
        context.finish();
    }
    // Despite its name, this method does not close the underlying input stream.
    input.close();
    return object;
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

Example 30 with Context

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

the class PooledUnmarshaller method unmarshal.

/**
 * Delegates the unmarshalling to the wrapped unmarshaller.
 */
@Override
public <T> JAXBElement<T> unmarshal(XMLEventReader input, final Class<T> declaredType) throws JAXBException {
    final TransformVersion version = getTransformVersion();
    if (version != null) {
        input = new TransformingReader(input, version);
    }
    final Context context = begin();
    try {
        return unmarshaller.unmarshal(input, declaredType);
    } finally {
        context.finish();
    }
}
Also used : Context(org.apache.sis.internal.jaxb.Context)

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