sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1548383 - in /sis/branches/JDK7/core: sis-referencing/src/test/java/org/apache/sis/referencing/datum/ sis-utility/src/main/java/org/apache/sis/internal/system/ sis-utility/src/main/java/org/apache/sis/xml/
Date Fri, 06 Dec 2013 05:47:29 GMT
Author: desruisseaux
Date: Fri Dec  6 05:47:29 2013
New Revision: 1548383

URL: http://svn.apache.org/r1548383
Log:
Enable unmarshalling objects from an older GML namespace.

Added:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLInputFactory.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java?rev=1548383&r1=1548382&r2=1548383&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] Fri Dec  6 05:47:29 2013
@@ -18,7 +18,9 @@ package org.apache.sis.referencing.datum
 
 import javax.measure.unit.NonSI;
 import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBException;
+import org.opengis.referencing.datum.PrimeMeridian;
 import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
@@ -41,28 +43,37 @@ import static org.apache.sis.test.mock.P
  */
 public final strictfp class DefaultPrimeMeridianTest extends DatumTestCase {
     /**
+     * Asserts the the given prime meridian is the Greenwich one.
+     */
+    private static void assertIsGreenwich(final PrimeMeridian meridian) {
+        assertEquals("name", "Greenwich", meridian.getName().getCode());
+        assertEquals("greenwichLongitude", 0, meridian.getGreenwichLongitude(), 0);
+        assertEquals("", NonSI.DEGREE_ANGLE, meridian.getAngularUnit());
+    }
+
+    /**
      * Tests {@link DefaultPrimeMeridian#toWKT()}.
      */
     @Test
     public void testToWKT() {
         final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
+        assertIsGreenwich(pm);
         assertWktEquals(pm, "PRIMEM[“Greenwich”, 0.0]");
     }
 
     /**
-     * Compares the given XML representation of Greenwich prime meridian against the expected
XML.
-     * The XML is expected to use the given GML namespace URI.
+     * Returns a XML representation of Greenwich prime meridian using the given GML namespace
URI.
      *
-     * @param namespace The expected GML namespace.
-     * @param actual XML representation of Greenwich prime meridian to test.
+     * @param  namespace The GML namespace.
+     * @return XML representation of Greenwich prime meridian.
      */
-    private static void assertGreenwichXmlEquals(final String namespace, final String actual)
{
-        assertXmlEquals(CharSequences.replace(
+    private static String getGreenwichXml(final String namespace) {
+        return CharSequences.replace(
                 "<gml:PrimeMeridian xmlns:gml=\"" + Namespaces.GML + "\">\n" +
                 "  <gml:name codeSpace=\"test\">Greenwich</gml:name>\n" +
                 "  <gml:greenwichLongitude uom=\"urn:ogc:def:uom:EPSG::9102\">0.0</gml:greenwichLongitude>\n"
+
                 "</gml:PrimeMeridian>\n",
-                Namespaces.GML, namespace).toString(), actual, "xmlns:*", "xsi:schemaLocation");
+                Namespaces.GML, namespace).toString();
     }
 
     /**
@@ -73,7 +84,7 @@ public final strictfp class DefaultPrime
     @Test
     public void testMarshall() throws JAXBException {
         final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
-        assertGreenwichXmlEquals(Namespaces.GML, marshal(pm));
+        assertXmlEquals(getGreenwichXml(Namespaces.GML), marshal(pm), "xmlns:*", "xsi:schemaLocation");
     }
 
     /**
@@ -90,7 +101,7 @@ public final strictfp class DefaultPrime
         marshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0);
         final String xml = marshal(marshaller, pm);
         pool.recycle(marshaller);
-        assertGreenwichXmlEquals(LegacyNamespaces.GML, xml);
+        assertXmlEquals(getGreenwichXml(LegacyNamespaces.GML), xml, "xmlns:*", "xsi:schemaLocation");
     }
 
     /**
@@ -103,7 +114,22 @@ public final strictfp class DefaultPrime
     @Test
     public void testUnmarshall() throws JAXBException {
         DefaultPrimeMeridian pm = unmarshall(DefaultPrimeMeridian.class, "Greenwich.xml");
-        assertEquals("greenwichLongitude", pm.getGreenwichLongitude(), 0, 0);
-        assertEquals("angularUnit", NonSI.DEGREE_ANGLE, pm.getAngularUnit());
+        assertIsGreenwich(pm);
+    }
+
+    /**
+     * Tests marshalling in the GML 3.1 namespace.
+     *
+     * @throws JAXBException If an error occurred during marshalling.
+     */
+    @Test
+    @DependsOnMethod("testUnmarshall")
+    public void testUnarshallGML31() throws JAXBException {
+        final MarshallerPool pool = getMarshallerPool();
+        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+        unmarshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0);
+        PrimeMeridian pm = (PrimeMeridian) unmarshal(unmarshaller, getGreenwichXml(LegacyNamespaces.GML));
+        pool.recycle(unmarshaller);
+        assertIsGreenwich(pm);
     }
 }

Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLInputFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLInputFactory.java?rev=1548383&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLInputFactory.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLInputFactory.java
[UTF-8] Fri Dec  6 05:47:29 2013
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.system;
+
+import java.io.Reader;
+import java.io.InputStream;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stax.StAXSource;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import org.apache.sis.util.Static;
+
+
+/**
+ * Provides access to {@link javax.xml.stream.XMLInputFactory} methods as static methods
working on
+ * a SIS-wide instance. This convenience is provided in a separated class in order to allow
the JVM
+ * to instantiate the factory only when first needed, when initializing this class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final class XMLInputFactory extends Static {
+    /**
+     * The SIS-wide factory.
+     */
+    private static final javax.xml.stream.XMLInputFactory FACTORY = javax.xml.stream.XMLInputFactory.newInstance();
+
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private XMLInputFactory() {
+    }
+
+    /*
+     * Do not provide convenience method for java.io.File, because the caller needs to close
the created
+     * input stream himself (this is not done by XMLInputFactory.close(), despite its method
name).
+     */
+
+    /**
+     * Creates a new reader for the given stream.
+     *
+     * @param  in Where to read from.
+     * @return The reader.
+     * @throws XMLStreamException If the reader can not be created.
+     */
+    public static XMLStreamReader createXMLStreamReader(final InputStream in) throws XMLStreamException
{
+        return FACTORY.createXMLStreamReader(in);
+    }
+
+    /**
+     * Creates a new reader for the given stream.
+     *
+     * @param  in Where to read from.
+     * @return The reader.
+     * @throws XMLStreamException If the reader can not be created.
+     */
+    public static XMLStreamReader createXMLStreamReader(final Reader in) throws XMLStreamException
{
+        return FACTORY.createXMLStreamReader(in);
+    }
+
+    /**
+     * Creates a new reader for the given source.
+     *
+     * @param  in Where to read from.
+     * @return The reader.
+     * @throws XMLStreamException If the reader can not be created.
+     */
+    public static XMLStreamReader createXMLStreamReader(final InputSource in) throws XMLStreamException
{
+        return FACTORY.createXMLStreamReader(new SAXSource(in));
+    }
+
+    /**
+     * Creates a new reader for the given source.
+     *
+     * @param  in Where to read from.
+     * @return The reader.
+     * @throws XMLStreamException If the reader can not be created.
+     */
+    public static XMLStreamReader createXMLStreamReader(final XMLEventReader in) throws XMLStreamException
{
+        return FACTORY.createXMLStreamReader(new StAXSource(in));
+    }
+
+    /**
+     * Creates a new reader for the given source.
+     *
+     * @param  in Where to read from.
+     * @return The reader.
+     * @throws XMLStreamException If the reader can not be created.
+     */
+    public static XMLStreamReader createXMLStreamReader(final Node in) throws XMLStreamException
{
+        return FACTORY.createXMLStreamReader(new DOMSource(in));
+    }
+
+    /**
+     * Creates a new reader for the given source.
+     *
+     * @param  in Where to read from.
+     * @return The reader.
+     * @throws XMLStreamException If the reader can not be created.
+     */
+    public static XMLStreamReader createXMLStreamReader(final Source in) throws XMLStreamException
{
+        return FACTORY.createXMLStreamReader(in);
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLInputFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLInputFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java?rev=1548383&r1=1548382&r2=1548383&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
[UTF-8] Fri Dec  6 05:47:29 2013
@@ -44,7 +44,7 @@ final class FilteredStreamReader extends
     /**
      * Creates a new filter for the given version of the standards.
      */
-    private FilteredStreamReader(final XMLStreamReader in, final FilterVersion version) {
+    FilteredStreamReader(final XMLStreamReader in, final FilterVersion version) {
         super(in);
         this.version = version;
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java?rev=1548383&r1=1548382&r2=1548383&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8]
Fri Dec  6 05:47:29 2013
@@ -229,18 +229,21 @@ abstract class Pooled {
     protected abstract void reset(final Object key, final Object value) throws JAXBException;
 
     /**
-     * Returns the GML version to be marshalled or unmarshalled, or {@code null} if unspecified.
-     * If null, then the latest version is assumed.
-     */
-    final Version getGMLVersion() {
-        return gmlVersion;
-    }
-
-    /**
-     * Returns {@code true} if the given {@link Context} bit is set.
+     * Returns the {@code FilterVersion} enumeration value to use for the current GML version,
or
+     * {@code null} if the SIS native version is suitable. If this method returns a non-null
value,
+     * then the output generated by JAXB will need to go through a {@link FilteredStreamWriter}
+     * in order to replace the namespace of the GML version implemented by SIS by the namespace
of
+     * the GML version asked by the user.
+     *
+     * @see FilteredNamespaces
      */
-    final boolean isFlagSet(final int mask) {
-        return (bitMasks & mask) != 0;
+    final FilterVersion getFilterVersion() {
+        if (gmlVersion != null && (bitMasks & Context.DISABLE_NAMESPACE_REPLACEMENTS)
== 0) {
+            if (gmlVersion.compareTo(LegacyNamespaces.VERSION_3_2, 2) < 0) {
+                return FilterVersion.GML31;
+            }
+        }
+        return null;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java?rev=1548383&r1=1548382&r2=1548383&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
[UTF-8] Fri Dec  6 05:47:29 2013
@@ -35,10 +35,8 @@ import javax.xml.transform.Result;
 import javax.xml.validation.Schema;
 import org.xml.sax.ContentHandler;
 import org.w3c.dom.Node;
-import org.apache.sis.util.Version;
 import org.apache.sis.util.Decorator;
 import org.apache.sis.internal.jaxb.Context;
-import org.apache.sis.internal.jaxb.LegacyNamespaces;
 import org.apache.sis.internal.system.XMLOutputFactory;
 
 
@@ -119,34 +117,14 @@ final class PooledMarshaller extends Poo
     }
 
     /**
-     * Returns the {@code FilterVersion} enumeration value to use for the current GML version,
or
-     * {@code null} if the SIS native version is suitable. If this method returns a non-null
value,
-     * then the output generated by JAXB will need to go through a {@link FilteredStreamWriter}
-     * in order to replace the namespace of the GML version implemented by SIS by the namespace
of
-     * the GML version asked by the user.
-     *
-     * @see FilteredNamespaces
-     */
-    private FilterVersion getFilterVersion() {
-        final Version gmlVersion = getGMLVersion();
-        if (gmlVersion != null && !isFlagSet(Context.DISABLE_NAMESPACE_REPLACEMENTS))
{
-            if (gmlVersion.compareTo(LegacyNamespaces.VERSION_3_2, 2) < 0) {
-                return FilterVersion.GML31;
-            }
-        }
-        return null;
-    }
-
-    /**
      * Marshals to the given output with on-the-fly substitution of namespaces.
      * This method is invoked only when the user asked to marshal to a different GML version
      * than the one supported natively by SIS, i.e. when {@link #getFilterVersion()} returns
      * a non-null value.
      *
      * @param object  The object to marshall.
-     * @param output  The writer create by SIS (<b>not</b> the writer given by
the user).
+     * @param output  The writer created by SIS (<b>not</b> the writer given
by the user).
      * @param version Identify the namespace substitutions to perform.
-     * @param close   Whether to close the writer after marshalling.
      */
     private void marshal(final Object object, XMLStreamWriter output, final FilterVersion
version)
             throws XMLStreamException, JAXBException

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java?rev=1548383&r1=1548382&r2=1548383&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java
[UTF-8] Fri Dec  6 05:47:29 2013
@@ -20,6 +20,9 @@ import java.net.URL;
 import java.io.File;
 import java.io.Reader;
 import java.io.InputStream;
+import java.io.FileInputStream;
+import java.io.BufferedInputStream;
+import java.io.IOException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
@@ -30,12 +33,14 @@ import javax.xml.bind.annotation.adapter
 import javax.xml.bind.attachment.AttachmentUnmarshaller;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.transform.Source;
 import javax.xml.validation.Schema;
 import org.w3c.dom.Node;
 import org.xml.sax.InputSource;
 import org.apache.sis.util.Decorator;
 import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.system.XMLInputFactory;
 
 
 /**
@@ -106,29 +111,89 @@ final class PooledUnmarshaller extends P
     }
 
     /**
-     * Delegates the unmarshalling to the wrapped unmarshaller.
+     * Unmarshals to the given input with on-the-fly substitution of namespaces.
+     * This method is invoked only when the user asked to marshal from a different GML version
+     * than the one supported natively by SIS, i.e. when {@link #getFilterVersion()} 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.
      */
-    @Override
-    public Object unmarshal(final InputStream input) throws JAXBException {
+    private Object unmarshal(XMLStreamReader input, final FilterVersion version)
+            throws XMLStreamException, JAXBException
+    {
+        input = new FilteredStreamReader(input, version);
         final Context context = begin();
+        final Object object;
         try {
-            return unmarshaller.unmarshal(input);
+            object = unmarshaller.unmarshal(input);
         } finally {
             context.finish();
         }
+        input.close(); // Despite its name, this method does not close the underlying input
stream.
+        return object;
     }
 
     /**
-     * Delegates the unmarshalling to the wrapped unmarshaller.
+     * Same as {@link #unmarshal(XMLStreamReader, FilterVersion)}, but delegating to the
unmarshaller
+     * methods returning a JAXB element instead than the one returning the object.
      */
-    @Override
-    public Object unmarshal(final URL input) throws JAXBException {
+    private <T> JAXBElement<T> unmarshal(XMLStreamReader input, final FilterVersion
version, final Class<T> declaredType)
+            throws XMLStreamException, JAXBException
+    {
+        input = new FilteredStreamReader(input, version);
         final Context context = begin();
+        final JAXBElement<T> object;
         try {
-            return unmarshaller.unmarshal(input);
+            object = unmarshaller.unmarshal(input, declaredType);
         } finally {
             context.finish();
         }
+        input.close(); // Despite its name, this method does not close the underlying input
stream.
+        return object;
+    }
+
+    /**
+     * Delegates the unmarshalling to the wrapped unmarshaller.
+     */
+    @Override
+    public Object unmarshal(final InputStream input) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
+        }
+    }
+
+    /**
+     * Delegates the unmarshalling to the wrapped unmarshaller.
+     */
+    @Override
+    public Object unmarshal(final URL input) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            try (final InputStream s = input.openStream()) {
+                return unmarshal(XMLInputFactory.createXMLStreamReader(s), version);
+            }
+        } catch (IOException | XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
+        }
     }
 
     /**
@@ -136,11 +201,20 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final File input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            try (final InputStream s = new BufferedInputStream(new FileInputStream(input)))
{
+                return unmarshal(XMLInputFactory.createXMLStreamReader(s), version);
+            }
+        } catch (IOException | XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -149,11 +223,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final Reader input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -162,11 +243,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final InputSource input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -175,11 +263,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final Node input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -188,11 +283,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public <T> JAXBElement<T> unmarshal(final Node input, final Class<T>
declaredType) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input, declaredType);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version, declaredType);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input, declaredType);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -201,11 +303,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final Source input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -214,11 +323,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public <T> JAXBElement<T> unmarshal(final Source input, final Class<T>
declaredType) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input, declaredType);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version, declaredType);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input, declaredType);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -226,7 +342,11 @@ final class PooledUnmarshaller extends P
      * Delegates the unmarshalling to the wrapped unmarshaller.
      */
     @Override
-    public Object unmarshal(final XMLStreamReader input) throws JAXBException {
+    public Object unmarshal(XMLStreamReader input) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) {
+            input = new FilteredStreamReader(input, version);
+        }
         final Context context = begin();
         try {
             return unmarshaller.unmarshal(input);
@@ -239,7 +359,11 @@ final class PooledUnmarshaller extends P
      * Delegates the unmarshalling to the wrapped unmarshaller.
      */
     @Override
-    public <T> JAXBElement<T> unmarshal(final XMLStreamReader input, final Class<T>
declaredType) throws JAXBException {
+    public <T> JAXBElement<T> unmarshal(XMLStreamReader input, final Class<T>
declaredType) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) {
+            input = new FilteredStreamReader(input, version);
+        }
         final Context context = begin();
         try {
             return unmarshaller.unmarshal(input, declaredType);
@@ -253,11 +377,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public Object unmarshal(final XMLEventReader input) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -266,11 +397,18 @@ final class PooledUnmarshaller extends P
      */
     @Override
     public <T> JAXBElement<T> unmarshal(final XMLEventReader input, final Class<T>
declaredType) throws JAXBException {
-        final Context context = begin();
-        try {
-            return unmarshaller.unmarshal(input, declaredType);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            return unmarshal(XMLInputFactory.createXMLStreamReader(input), version, declaredType);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            final Context context = begin();
+            try {
+                return unmarshaller.unmarshal(input, declaredType);
+            } finally {
+                context.finish();
+            }
         }
     }
 



Mime
View raw message