sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1776095 - in /sis/branches/JDK8: core/sis-utility/src/main/java/org/apache/sis/internal/util/ core/sis-utility/src/main/java/org/apache/sis/xml/ core/sis-utility/src/test/java/org/apache/sis/xml/ storage/sis-xmlstore/src/main/java/org/apac...
Date Tue, 27 Dec 2016 09:05:34 GMT
Author: desruisseaux
Date: Tue Dec 27 09:05:34 2016
New Revision: 1776095

URL: http://svn.apache.org/viewvc?rev=1776095&view=rev
Log:
Add a StreamWriterDelegate class as a complement of JDK's StreamReaderDelegate.
Refactor FilteredStreamWriter to inherit StreamWriterDelegate, and add another subclass for STAX-based data store.
Modify the way we marshal fragment in STAX: we need to set the Marshaller.JAXB_FRAGMENT property to Boolean.TRUE.
Provide a way to omit the namespace declaration inserted by JAXB when this namespace is the default one.

Added:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StreamWriterDelegate.java
      - copied, changed from r1776051, sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/DefaultNamespaceStreamWriter.java
      - copied, changed from r1776051, sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java
Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper_Endorsed.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/PooledTemplate.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/xml/OGCNamespacePrefixMapperTest.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXStore.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXWriter.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/StoreProvider.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStoreProvider.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java
    sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java
    sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java

Copied: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StreamWriterDelegate.java (from r1776051, sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StreamWriterDelegate.java?p2=sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StreamWriterDelegate.java&p1=sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java&r1=1776051&r2=1776095&rev=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/StreamWriterDelegate.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -14,89 +14,77 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.xml;
+package org.apache.sis.internal.util;
 
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.namespace.NamespaceContext;
+import org.apache.sis.util.Workaround;
 
 
 /**
- * A filter replacing the namespaces used by JAXB by other namespaces to be used in the XML document
- * at marshalling time. This class forwards every method calls to the wrapped {@link XMLStreamWriter},
- * with all {@code namespaceURI} arguments filtered before to be delegated.
+ * Base class for deriving an {@code XMLStreamWriter} filters.
+ * By default each method does nothing but call the corresponding method on the wrapped instance.
  *
- * See {@link FilteredNamespaces} for more information.
+ * <p>This class is the complement of {@link javax.xml.stream.util.StreamReaderDelegate} provided
+ * in standard JDK. For an unknown reason, JDK 8 does not provide a {@code StreamWriterDelegate}.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @since   0.4
- * @version 0.4
+ * @since   0.8
+ * @version 0.8
  * @module
+ *
+ * @see javax.xml.stream.util.StreamReaderDelegate
  */
-final class FilteredStreamWriter implements XMLStreamWriter {
+@Workaround(library = "JDK", version = "1.8")
+public class StreamWriterDelegate implements XMLStreamWriter {
     /**
      * Where to write the XML.
      */
-    private final XMLStreamWriter out;
-
-    /**
-     * The other version to marshall to.
-     */
-    private final FilterVersion version;
+    protected final XMLStreamWriter out;
 
     /**
-     * Creates a new filter for the given version of the standards.
+     * Creates a new filter.
+     *
+     * @param out  where to write the XML.
      */
-    FilteredStreamWriter(final XMLStreamWriter out, final FilterVersion version) {
-        this.out     = out;
-        this.version = version;
-    }
-
-    /**
-     * Returns the URI to write in the XML document.
-     */
-    private String toView(final String uri) {
-        final String replacement = version.toView.get(uri);
-        return (replacement != null) ? replacement : uri;
+    protected StreamWriterDelegate(XMLStreamWriter out) {
+        this.out = out;
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeStartElement(final String localName) throws XMLStreamException {
+    public void writeStartElement(String localName) throws XMLStreamException {
         out.writeStartElement(localName);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeStartElement(final String namespaceURI, final String localName) throws XMLStreamException {
-        out.writeStartElement(toView(namespaceURI), localName);
+    public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
+        out.writeStartElement(namespaceURI, localName);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeStartElement(final String prefix, final String localName, final String namespaceURI)
-            throws XMLStreamException
-    {
-        out.writeStartElement(prefix, localName, toView(namespaceURI));
+    public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+        out.writeStartElement(prefix, localName, namespaceURI);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeEmptyElement(final String namespaceURI, final String localName) throws XMLStreamException {
-        out.writeEmptyElement(toView(namespaceURI), localName);
+    public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
+        out.writeEmptyElement(namespaceURI, localName);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeEmptyElement(final String prefix, final String localName, final String namespaceURI)
-            throws XMLStreamException
-    {
-        out.writeEmptyElement(prefix, localName, toView(namespaceURI));
+    public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+        out.writeEmptyElement(prefix, localName, namespaceURI);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeEmptyElement(final String localName) throws XMLStreamException {
+    public void writeEmptyElement(String localName) throws XMLStreamException {
         out.writeEmptyElement(localName);
     }
 
@@ -126,71 +114,67 @@ final class FilteredStreamWriter impleme
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeAttribute(final String localName, final String value) throws XMLStreamException {
+    public void writeAttribute(String localName, String value) throws XMLStreamException {
         out.writeAttribute(localName, value);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeAttribute(final String prefix, final String namespaceURI,final  String localName,
-            final String value) throws XMLStreamException
-    {
-        out.writeAttribute(prefix, toView(namespaceURI), localName, value);
+    public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
+        out.writeAttribute(prefix, namespaceURI, localName, value);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeAttribute(final String namespaceURI, final String localName, final String value)
-            throws XMLStreamException
-    {
-        out.writeAttribute(toView(namespaceURI), localName, value);
+    public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
+        out.writeAttribute(namespaceURI, localName, value);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeNamespace(final String prefix, final String namespaceURI) throws XMLStreamException {
-        out.writeNamespace(prefix, toView(namespaceURI));
+    public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
+        out.writeNamespace(prefix, namespaceURI);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void writeDefaultNamespace(final String namespaceURI) throws XMLStreamException {
-        out.writeDefaultNamespace(toView(namespaceURI));
+    public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
+        out.writeDefaultNamespace(namespaceURI);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeComment(final String data) throws XMLStreamException {
+    public void writeComment(String data) throws XMLStreamException {
         out.writeComment(data);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeProcessingInstruction(final String target) throws XMLStreamException {
+    public void writeProcessingInstruction(String target) throws XMLStreamException {
         out.writeProcessingInstruction(target);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeProcessingInstruction(final String target, final String data) throws XMLStreamException {
+    public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
         out.writeProcessingInstruction(target, data);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeCData(final String data) throws XMLStreamException {
+    public void writeCData(String data) throws XMLStreamException {
         out.writeCData(data);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeDTD(final String dtd) throws XMLStreamException {
+    public void writeDTD(String dtd) throws XMLStreamException {
         out.writeDTD(dtd);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeEntityRef(final String name) throws XMLStreamException {
+    public void writeEntityRef(String name) throws XMLStreamException {
         out.writeEntityRef(name);
     }
 
@@ -202,66 +186,61 @@ final class FilteredStreamWriter impleme
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeStartDocument(final String version) throws XMLStreamException {
+    public void writeStartDocument(String version) throws XMLStreamException {
         out.writeStartDocument(version);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeStartDocument(final String encoding, final String version) throws XMLStreamException {
+    public void writeStartDocument(String encoding, String version) throws XMLStreamException {
         out.writeStartDocument(encoding, version);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeCharacters(final String text) throws XMLStreamException {
+    public void writeCharacters(String text) throws XMLStreamException {
         out.writeCharacters(text);
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public void writeCharacters(final char[] text, final int start, final int len) throws XMLStreamException {
+    public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
         out.writeCharacters(text, start, len);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public String getPrefix(final String uri) throws XMLStreamException {
-        return out.getPrefix(toView(uri));
+    public String getPrefix(String uri) throws XMLStreamException {
+        return out.getPrefix(uri);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void setPrefix(final String prefix, final String uri) throws XMLStreamException {
-        out.setPrefix(prefix, toView(uri));
+    public void setPrefix(String prefix, String uri) throws XMLStreamException {
+        out.setPrefix(prefix, uri);
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
-    public void setDefaultNamespace(final String uri) throws XMLStreamException {
-        out.setDefaultNamespace(toView(uri));
+    public void setDefaultNamespace(String uri) throws XMLStreamException {
+        out.setDefaultNamespace(uri);
     }
 
-    /** Unwraps the original context and forwards the call. */
+    /** Forwards the call verbatim. */
     @Override
     public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
-        if (context instanceof FilteredNamespaces) {
-            context = ((FilteredNamespaces) context).inverse(version);
-        } else {
-            context = new FilteredNamespaces(context, version, true);
-        }
         out.setNamespaceContext(context);
     }
 
-    /** Returns the context of the underlying writer wrapped in a filter that convert the namespaces on the fly. */
+    /** Forwards the call verbatim. */
     @Override
     public NamespaceContext getNamespaceContext() {
-        return new FilteredNamespaces(out.getNamespaceContext(), version, false);
+        return out.getNamespaceContext();
     }
 
     /** Forwards the call verbatim. */
     @Override
-    public Object getProperty(final String name) throws IllegalArgumentException {
+    public Object getProperty(String name) throws IllegalArgumentException {
         return out.getProperty(name);
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -19,6 +19,7 @@ package org.apache.sis.xml;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.namespace.NamespaceContext;
+import org.apache.sis.internal.util.StreamWriterDelegate;
 
 
 /**
@@ -30,17 +31,12 @@ import javax.xml.namespace.NamespaceCont
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.8
  * @module
  */
-final class FilteredStreamWriter implements XMLStreamWriter {
+final class FilteredStreamWriter extends StreamWriterDelegate {
     /**
-     * Where to write the XML.
-     */
-    private final XMLStreamWriter out;
-
-    /**
-     * The other version to marshall to.
+     * The other version to marshal to.
      */
     private final FilterVersion version;
 
@@ -48,7 +44,7 @@ final class FilteredStreamWriter impleme
      * Creates a new filter for the given version of the standards.
      */
     FilteredStreamWriter(final XMLStreamWriter out, final FilterVersion version) {
-        this.out     = out;
+        super(out);
         this.version = version;
     }
 
@@ -60,12 +56,6 @@ final class FilteredStreamWriter impleme
         return (replacement != null) ? replacement : uri;
     }
 
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartElement(final String localName) throws XMLStreamException {
-        out.writeStartElement(localName);
-    }
-
     /** Replaces the given URI if needed, then forwards the call. */
     @Override
     public void writeStartElement(final String namespaceURI, final String localName) throws XMLStreamException {
@@ -94,45 +84,9 @@ final class FilteredStreamWriter impleme
         out.writeEmptyElement(prefix, localName, toView(namespaceURI));
     }
 
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEmptyElement(final String localName) throws XMLStreamException {
-        out.writeEmptyElement(localName);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEndElement() throws XMLStreamException {
-        out.writeEndElement();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEndDocument() throws XMLStreamException {
-        out.writeEndDocument();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void close() throws XMLStreamException {
-        out.close();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void flush() throws XMLStreamException {
-        out.flush();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeAttribute(final String localName, final String value) throws XMLStreamException {
-        out.writeAttribute(localName, value);
-    }
-
     /** Replaces the given URI if needed, then forwards the call. */
     @Override
-    public void writeAttribute(final String prefix, final String namespaceURI,final  String localName,
+    public void writeAttribute(final String prefix, final String namespaceURI, final String localName,
             final String value) throws XMLStreamException
     {
         out.writeAttribute(prefix, toView(namespaceURI), localName, value);
@@ -158,72 +112,6 @@ final class FilteredStreamWriter impleme
         out.writeDefaultNamespace(toView(namespaceURI));
     }
 
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeComment(final String data) throws XMLStreamException {
-        out.writeComment(data);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeProcessingInstruction(final String target) throws XMLStreamException {
-        out.writeProcessingInstruction(target);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeProcessingInstruction(final String target, final String data) throws XMLStreamException {
-        out.writeProcessingInstruction(target, data);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeCData(final String data) throws XMLStreamException {
-        out.writeCData(data);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeDTD(final String dtd) throws XMLStreamException {
-        out.writeDTD(dtd);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEntityRef(final String name) throws XMLStreamException {
-        out.writeEntityRef(name);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartDocument() throws XMLStreamException {
-        out.writeStartDocument();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartDocument(final String version) throws XMLStreamException {
-        out.writeStartDocument(version);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartDocument(final String encoding, final String version) throws XMLStreamException {
-        out.writeStartDocument(encoding, version);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeCharacters(final String text) throws XMLStreamException {
-        out.writeCharacters(text);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeCharacters(final char[] text, final int start, final int len) throws XMLStreamException {
-        out.writeCharacters(text, start, len);
-    }
-
     /** Replaces the given URI if needed, then forwards the call. */
     @Override
     public String getPrefix(final String uri) throws XMLStreamException {
@@ -258,10 +146,4 @@ final class FilteredStreamWriter impleme
     public NamespaceContext getNamespaceContext() {
         return new FilteredNamespaces(out.getNamespaceContext(), version, false);
     }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public Object getProperty(final String name) throws IllegalArgumentException {
-        return out.getProperty(name);
-    }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -75,7 +75,7 @@ public class MarshallerPool {
      * This is a very approximative value: actual timeout will not be shorter,
      * but may be twice longer.
      */
-    private static final long TIMEOUT = 15000000000L; // 15 seconds.
+    private static final long TIMEOUT = 15000000000L;           // 15 seconds.
 
     /**
      * Kind of JAXB implementations.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -44,7 +44,7 @@ import org.apache.sis.util.ArgumentCheck
  *   <tr><td>srv</td>    <td>{@value #SRV}</td>   <td></td></tr>
  *   <tr><td>gts</td>    <td>{@value #GTS}</td>   <td></td></tr>
  *   <tr><td>gmx</td>    <td>{@value #GMX}</td>   <td></td></tr>
- *   <tr><td>gml</td>    <td>{@value #GML}</td>   <td>0.4</td></tr>
+ *   <tr><td>gml</td>    <td>{@value #GML}</td>   <td>SIS 0.4</td></tr>
  *   <tr><td>csw</td>    <td>{@value #CSW}</td>   <td></td></tr>
  *   <tr><td>xsi</td>    <td>{@value #XSI}</td>   <td></td></tr>
  *   <tr><td>xlink</td>  <td>{@value #XLINK}</td> <td></td></tr>

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -49,7 +49,7 @@ final class OGCNamespacePrefixMapper ext
      * Creates a new prefix mapper.
      * This constructor is invoked by reflection and needs to be public for that reason.
      *
-     * @param defaultNamespace The namespace which doesn't need prefix, or {@code null} if none.
+     * @param defaultNamespace the namespace which doesn't need prefix, or {@code null} if none.
      */
     public OGCNamespacePrefixMapper(final String defaultNamespace) {
         this.defaultNamespace = defaultNamespace;
@@ -58,11 +58,12 @@ final class OGCNamespacePrefixMapper ext
     /**
      * Returns a preferred prefix for the given namespace URI.
      *
-     * @param  namespace  The namespace URI for which the prefix needs to be found.
-     * @param  suggestion The suggested prefix, returned if the given namespace is not recognized.
-     * @param  required   {@code true} if this method is not allowed to return the empty string.
-     * @return The prefix inferred from the namespace URI.
+     * @param  namespace   the namespace URI for which the prefix needs to be found.
+     * @param  suggestion  the suggested prefix, returned if the given namespace is not recognized.
+     * @param  required    {@code true} if this method is not allowed to return the empty string.
+     * @return the prefix inferred from the namespace URI.
      */
+    @Override
     public String getPreferredPrefix(final String namespace, final String suggestion, final boolean required) {
         /*
          * If the given namespace is the one defined as default namespace, this implementation

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper_Endorsed.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper_Endorsed.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper_Endorsed.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/OGCNamespacePrefixMapper_Endorsed.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -44,7 +44,7 @@ final class OGCNamespacePrefixMapper_End
      * Creates a new prefix mapper.
      * This constructor is invoked by reflection and needs to be public for that reason.
      *
-     * @param defaultNamespace The namespace which doesn't need prefix, or {@code null} if none.
+     * @param defaultNamespace the namespace which doesn't need prefix, or {@code null} if none.
      */
     public OGCNamespacePrefixMapper_Endorsed(final String defaultNamespace) {
         this.defaultNamespace = defaultNamespace;
@@ -53,11 +53,12 @@ final class OGCNamespacePrefixMapper_End
     /**
      * Returns a preferred prefix for the given namespace URI.
      *
-     * @param  namespace  The namespace URI for which the prefix needs to be found.
-     * @param  suggestion The suggested prefix, returned if the given namespace is not recognized.
-     * @param  required   {@code true} if this method is not allowed to return the empty string.
-     * @return The prefix inferred from the namespace URI.
+     * @param  namespace   the namespace URI for which the prefix needs to be found.
+     * @param  suggestion  the suggested prefix, returned if the given namespace is not recognized.
+     * @param  required    {@code true} if this method is not allowed to return the empty string.
+     * @return the prefix inferred from the namespace URI.
      */
+    @Override
     public String getPreferredPrefix(final String namespace, final String suggestion, final boolean required) {
         /*
          * If the given namespace is the one defined as default namespace, this implementation

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/PooledTemplate.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/PooledTemplate.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/PooledTemplate.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/PooledTemplate.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -39,7 +39,7 @@ final class PooledTemplate extends Poole
     /**
      * Creates a new template.
      *
-     * @param properties The properties to be given to JAXB (un)marshallers, or {@code null} if none.
+     * @param properties  the properties to be given to JAXB (un)marshallers, or {@code null} if none.
      * @param internal {@code true} if the JAXB implementation is the one bundled in JDK 6,
      *        or {@code false} if this is the external implementation provided as a JAR file
      *        in the endorsed directory.
@@ -83,10 +83,10 @@ final class PooledTemplate extends Poole
      * <p>Current implementation expects values of type {@code String}, but this may be generalized
      * in a future SIS version if there is a need for that.</p>
      *
-     * @param  name The name of the property to remove.
-     * @param  defaultValue The default value to return if the given property is not defined in the map.
-     * @return The old value of that property, or {@code defaultValue} if the given property was not defined.
-     * @throws PropertyException If the given property is not of the expected type.
+     * @param  name  the name of the property to remove.
+     * @param  defaultValue  the default value to return if the given property is not defined in the map.
+     * @return the old value of that property, or {@code defaultValue} if the given property was not defined.
+     * @throws PropertyException if the given property is not of the expected type.
      */
     String remove(final String name, final String defaultValue) throws PropertyException {
         final Object value = initialProperties.remove(name);

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -155,7 +155,6 @@ public final class XML extends Static {
      * <div class="section">Current limitation</div>
      * In current SIS implementation, this property is honored only by the {@link MarshallerPool} constructors.
      * Specifying this property to {@link javax.xml.bind.Marshaller#setProperty(String, Object)} is too late.
-     * This limitation may be fixed in a future SIS version.
      */
     public static final String DEFAULT_NAMESPACE = "org.apache.sis.xml.defaultNamespace";
 

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/xml/OGCNamespacePrefixMapperTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/xml/OGCNamespacePrefixMapperTest.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/xml/OGCNamespacePrefixMapperTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/xml/OGCNamespacePrefixMapperTest.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -48,7 +48,7 @@ public final strictfp class OGCNamespace
      * defined in the JDK class. This test is ignored if the Java framework running this test
      * is not the Oracle one (i.e. if it does not bundle the Sun internal JAXB implementation).
      *
-     * @throws ReflectiveOperationException If an error occurred while invoking a method by
+     * @throws ReflectiveOperationException if an error occurred while invoking a method by
      *         the reflection API.
      */
     @Test
@@ -65,7 +65,7 @@ public final strictfp class OGCNamespace
      * methods defined in the JAXB class. This test is ignored if the Java framework running
      * this test does not contains JAXB in its endorsed directory.
      *
-     * @throws ReflectiveOperationException If an error occurred while invoking a method by
+     * @throws ReflectiveOperationException if an error occurred while invoking a method by
      *         the reflection API.
      */
     @Test
@@ -84,9 +84,9 @@ public final strictfp class OGCNamespace
      * method. Additionally, this test checks the result of some method calls in order to
      * ensure that the invoked method was the one defined in {@link OGCNamespacePrefixMapper}.
      *
-     * @param  The {@code OGCNamespacePrefixMapper} or {@code OGCNamespacePrefixMapper_Endorsed}
+     * @param  mapper the {@code OGCNamespacePrefixMapper} or {@code OGCNamespacePrefixMapper_Endorsed}
      *         instance to check.
-     * @throws ReflectiveOperationException If an error occurred while invoking a method by
+     * @throws ReflectiveOperationException if an error occurred while invoking a method by
      *         the reflection API.
      */
     private void ensureOverrideMethods(final Object mapper) throws ReflectiveOperationException {

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXReader.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -427,7 +427,7 @@ parse:  while (reader.hasNext()) {
         }
         final Feature feature = types.wayPoint.newInstance();
         feature.setPropertyValue("@identifier", index);
-        feature.setPropertyValue("@geometry", new Point(Double.parseDouble(lon), Double.parseDouble(lat)));
+        feature.setPropertyValue("@geometry", new Point(parseDouble(lon), parseDouble(lat)));
         List<Link> links = null;
         while (true) {
             /*

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXStore.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXStore.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXStore.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -59,7 +59,7 @@ public class GPXStore extends StaxDataSt
     /**
      * Version of the GPX file, or {@code null} if unknown.
      */
-    private Version version;
+    Version version;
 
     /**
      * {@code true} if the {@linkplain #metadata} field has been initialized.
@@ -183,7 +183,9 @@ public class GPXStore extends StaxDataSt
         // TODO: convert the metadata if needed.
         try (final GPXWriter writer = new GPXWriter(this, (org.apache.sis.internal.gpx.Metadata) metadata)) {
             writer.writeStartDocument();
-            features.forEachOrdered(writer);
+            if (features != null) {
+                features.forEachOrdered(writer);
+            }
             writer.writeEndDocument();
         } catch (BackingStoreException e) {
             final Throwable cause = e.getCause();

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXWriter.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXWriter.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/GPXWriter.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -54,6 +54,11 @@ public class GPXWriter extends StaxStrea
     private final int version;
 
     /**
+     * The namespace, which is either {@link Tags#NAMESPACE_V10} or {@link Tags#NAMESPACE_V11}.
+     */
+    private final String namespace;
+
+    /**
      * The metadata to write, or {@code null} if none.
      */
     private final Metadata metadata;
@@ -73,8 +78,7 @@ public class GPXWriter extends StaxStrea
         super(owner);
         types = Types.DEFAULT;
         this.metadata = metadata;
-        final String namespace;
-        final Version ver = owner.getVersion();
+        final Version ver = owner.version;
         if (ver != null && ver.compareTo(GPXStore.V1_0, 2) <= 0) {
             version   = 0;
             namespace = Tags.NAMESPACE_V10;
@@ -114,7 +118,7 @@ public class GPXWriter extends StaxStrea
                      * In GPX 1.1 format, the metadata are stored under a <metadata> node.
                      * This can conveniently be written by JAXB.
                      */
-                    marshal(metadata);
+                    marshal(namespace, Tags.METADATA, Metadata.class, metadata);
                     break;
                 }
                 case 0: {
@@ -132,7 +136,7 @@ public class GPXWriter extends StaxStrea
                     writeLinks(metadata.links);
                     writeSingle(Tags.TIME, metadata.time);
                     writeList(Tags.KEYWORDS, metadata.keywords);
-                    marshal(metadata.bounds);
+                    marshal(namespace, Tags.BOUNDS, Bounds.class, metadata.bounds);
                 }
             }
         }
@@ -246,7 +250,7 @@ public class GPXWriter extends StaxStrea
                     switch (version) {
                         default:
                         case 1: {
-                            marshal(link);
+                            marshal(namespace, Tags.LINK, Link.class, (Link) link);
                             break;
                         }
                         case 0: {

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/StoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/StoreProvider.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/StoreProvider.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/gpx/StoreProvider.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -42,6 +42,9 @@ public class StoreProvider extends StaxD
     public StoreProvider() {
     }
 
+    /**
+     * TODO
+     */
     @Override
     public ProbeResult probeContent(StorageConnector connector) throws DataStoreException {
         throw new UnsupportedOperationException("Not supported yet.");
@@ -60,6 +63,16 @@ public class StoreProvider extends StaxD
     }
 
     /**
+     * Returns the namespace URI of GPX 1.1 file format.
+     *
+     * @return GPX 1.1 namespace.
+     */
+    @Override
+    protected String getDefaultNamespace() {
+        return Tags.NAMESPACE_V11;
+    }
+
+    /**
      * Returns the JAXB context for the data store. This method is invoked at most once.
      *
      * @return the JAXB context.

Copied: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/DefaultNamespaceStreamWriter.java (from r1776051, sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/DefaultNamespaceStreamWriter.java?p2=sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/DefaultNamespaceStreamWriter.java&p1=sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java&r1=1776051&r2=1776095&rev=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/DefaultNamespaceStreamWriter.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -14,62 +14,52 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.xml;
+package org.apache.sis.internal.xml;
 
+import javax.xml.XMLConstants;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.namespace.NamespaceContext;
+import org.apache.sis.internal.util.StreamWriterDelegate;
 
 
 /**
- * A filter replacing the namespaces used by JAXB by other namespaces to be used in the XML document
- * at marshalling time. This class forwards every method calls to the wrapped {@link XMLStreamWriter},
- * with all {@code namespaceURI} arguments filtered before to be delegated.
- *
- * See {@link FilteredNamespaces} for more information.
+ * A filter replacing the given namespace by the default namespace.
+ * This is used for removing unnecessary namespace declarations introduced by JAXB marshaller.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @since   0.4
- * @version 0.4
+ * @since   0.8
+ * @version 0.8
  * @module
  */
-final class FilteredStreamWriter implements XMLStreamWriter {
-    /**
-     * Where to write the XML.
-     */
-    private final XMLStreamWriter out;
-
+final class DefaultNamespaceStreamWriter extends StreamWriterDelegate {
     /**
-     * The other version to marshall to.
+     * The default namespace.
      */
-    private final FilterVersion version;
+    private final String defaultNamespace;
 
     /**
-     * Creates a new filter for the given version of the standards.
+     * Creates a new filter for the given default namespace.
      */
-    FilteredStreamWriter(final XMLStreamWriter out, final FilterVersion version) {
-        this.out     = out;
-        this.version = version;
+    DefaultNamespaceStreamWriter(final XMLStreamWriter out, final String namespaceURI) {
+        super(out);
+        defaultNamespace = namespaceURI;
     }
 
     /**
-     * Returns the URI to write in the XML document.
+     * Returns {@code true} if the given namespace is the default one.
      */
-    private String toView(final String uri) {
-        final String replacement = version.toView.get(uri);
-        return (replacement != null) ? replacement : uri;
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartElement(final String localName) throws XMLStreamException {
-        out.writeStartElement(localName);
+    private boolean isDefault(final String ns) {
+        return defaultNamespace.equals(ns);
     }
 
     /** Replaces the given URI if needed, then forwards the call. */
     @Override
     public void writeStartElement(final String namespaceURI, final String localName) throws XMLStreamException {
-        out.writeStartElement(toView(namespaceURI), localName);
+        if (isDefault(namespaceURI)) {
+            out.writeStartElement(localName);
+        } else {
+            out.writeStartElement(namespaceURI, localName);
+        }
     }
 
     /** Replaces the given URI if needed, then forwards the call. */
@@ -77,13 +67,21 @@ final class FilteredStreamWriter impleme
     public void writeStartElement(final String prefix, final String localName, final String namespaceURI)
             throws XMLStreamException
     {
-        out.writeStartElement(prefix, localName, toView(namespaceURI));
+        if (isDefault(namespaceURI)) {
+            out.writeStartElement(localName);
+        } else {
+            out.writeStartElement(prefix, localName, namespaceURI);
+        }
     }
 
     /** Replaces the given URI if needed, then forwards the call. */
     @Override
     public void writeEmptyElement(final String namespaceURI, final String localName) throws XMLStreamException {
-        out.writeEmptyElement(toView(namespaceURI), localName);
+        if (isDefault(namespaceURI)) {
+            out.writeEmptyElement(localName);
+        } else {
+            out.writeEmptyElement(namespaceURI, localName);
+        }
     }
 
     /** Replaces the given URI if needed, then forwards the call. */
@@ -91,51 +89,23 @@ final class FilteredStreamWriter impleme
     public void writeEmptyElement(final String prefix, final String localName, final String namespaceURI)
             throws XMLStreamException
     {
-        out.writeEmptyElement(prefix, localName, toView(namespaceURI));
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEmptyElement(final String localName) throws XMLStreamException {
-        out.writeEmptyElement(localName);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEndElement() throws XMLStreamException {
-        out.writeEndElement();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEndDocument() throws XMLStreamException {
-        out.writeEndDocument();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void close() throws XMLStreamException {
-        out.close();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void flush() throws XMLStreamException {
-        out.flush();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeAttribute(final String localName, final String value) throws XMLStreamException {
-        out.writeAttribute(localName, value);
+        if (isDefault(namespaceURI)) {
+            out.writeEmptyElement(localName);
+        } else {
+            out.writeEmptyElement(prefix, localName, namespaceURI);
+        }
     }
 
     /** Replaces the given URI if needed, then forwards the call. */
     @Override
-    public void writeAttribute(final String prefix, final String namespaceURI,final  String localName,
+    public void writeAttribute(final String prefix, final String namespaceURI, final String localName,
             final String value) throws XMLStreamException
     {
-        out.writeAttribute(prefix, toView(namespaceURI), localName, value);
+        if (isDefault(namespaceURI)) {
+            out.writeAttribute(localName, value);
+        } else {
+            out.writeAttribute(prefix, namespaceURI, localName, value);
+        }
     }
 
     /** Replaces the given URI if needed, then forwards the call. */
@@ -143,125 +113,37 @@ final class FilteredStreamWriter impleme
     public void writeAttribute(final String namespaceURI, final String localName, final String value)
             throws XMLStreamException
     {
-        out.writeAttribute(toView(namespaceURI), localName, value);
+        if (isDefault(namespaceURI)) {
+            out.writeAttribute(localName, value);
+        } else {
+            out.writeAttribute(namespaceURI, localName, value);
+        }
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Do nothing if the given namespace is the default one. */
     @Override
     public void writeNamespace(final String prefix, final String namespaceURI) throws XMLStreamException {
-        out.writeNamespace(prefix, toView(namespaceURI));
+        if (!isDefault(namespaceURI)) {
+            if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
+                throw new XMLStreamException(namespaceURI);         // Do not allow change of default namespace.
+            }
+            out.writeNamespace(prefix, namespaceURI);
+        }
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Do nothing if the given namespace is the default one. */
     @Override
     public void writeDefaultNamespace(final String namespaceURI) throws XMLStreamException {
-        out.writeDefaultNamespace(toView(namespaceURI));
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeComment(final String data) throws XMLStreamException {
-        out.writeComment(data);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeProcessingInstruction(final String target) throws XMLStreamException {
-        out.writeProcessingInstruction(target);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeProcessingInstruction(final String target, final String data) throws XMLStreamException {
-        out.writeProcessingInstruction(target, data);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeCData(final String data) throws XMLStreamException {
-        out.writeCData(data);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeDTD(final String dtd) throws XMLStreamException {
-        out.writeDTD(dtd);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeEntityRef(final String name) throws XMLStreamException {
-        out.writeEntityRef(name);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartDocument() throws XMLStreamException {
-        out.writeStartDocument();
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartDocument(final String version) throws XMLStreamException {
-        out.writeStartDocument(version);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeStartDocument(final String encoding, final String version) throws XMLStreamException {
-        out.writeStartDocument(encoding, version);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeCharacters(final String text) throws XMLStreamException {
-        out.writeCharacters(text);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public void writeCharacters(final char[] text, final int start, final int len) throws XMLStreamException {
-        out.writeCharacters(text, start, len);
-    }
-
-    /** Replaces the given URI if needed, then forwards the call. */
-    @Override
-    public String getPrefix(final String uri) throws XMLStreamException {
-        return out.getPrefix(toView(uri));
+        if (!isDefault(namespaceURI)) {
+            throw new XMLStreamException(namespaceURI);             // Do not allow change of default namespace.
+        }
     }
 
-    /** Replaces the given URI if needed, then forwards the call. */
-    @Override
-    public void setPrefix(final String prefix, final String uri) throws XMLStreamException {
-        out.setPrefix(prefix, toView(uri));
-    }
-
-    /** Replaces the given URI if needed, then forwards the call. */
+    /** Do nothing if the given namespace is the default one. */
     @Override
     public void setDefaultNamespace(final String uri) throws XMLStreamException {
-        out.setDefaultNamespace(toView(uri));
-    }
-
-    /** Unwraps the original context and forwards the call. */
-    @Override
-    public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
-        if (context instanceof FilteredNamespaces) {
-            context = ((FilteredNamespaces) context).inverse(version);
-        } else {
-            context = new FilteredNamespaces(context, version, true);
+        if (!isDefault(uri)) {
+            throw new XMLStreamException(uri);                      // Do not allow change of default namespace.
         }
-        out.setNamespaceContext(context);
-    }
-
-    /** Returns the context of the underlying writer wrapped in a filter that convert the namespaces on the fly. */
-    @Override
-    public NamespaceContext getNamespaceContext() {
-        return new FilteredNamespaces(out.getNamespaceContext(), version, false);
-    }
-
-    /** Forwards the call verbatim. */
-    @Override
-    public Object getProperty(final String name) throws IllegalArgumentException {
-        return out.getProperty(name);
     }
 }

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStore.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -178,7 +178,8 @@ public abstract class StaxDataStore exte
              * if needed (and if the underlying channel is writable).
              */
             stream = connector.getStorageAs(InputStream.class);
-        } else if (storage instanceof AutoCloseable) {
+        }
+        if (stream == null && storage instanceof AutoCloseable) {
             stream = (AutoCloseable) storage;
         }
         connector.closeAllExcept(stream);

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStoreProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStoreProvider.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStoreProvider.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxDataStoreProvider.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -16,10 +16,13 @@
  */
 package org.apache.sis.internal.xml;
 
+import java.util.Map;
+import java.util.Collections;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import org.apache.sis.storage.DataStoreProvider;
 import org.apache.sis.xml.MarshallerPool;
+import org.apache.sis.xml.XML;
 
 
 /**
@@ -46,6 +49,13 @@ public abstract class StaxDataStoreProvi
     }
 
     /**
+     * Returns the default namespace URI for the XML documents created by this format.
+     *
+     * @return the default namespace URI.
+     */
+    protected abstract String getDefaultNamespace();
+
+    /**
      * Returns the JAXB context for the data store, or {@code null} if the data stores
      * {@linkplain #open created} by this provided do not use JAXB.
      *
@@ -70,7 +80,8 @@ public abstract class StaxDataStoreProvi
                 if (pool == null) {
                     final JAXBContext context = getJAXBContext();
                     if (context != null) {
-                        jaxb = pool = new MarshallerPool(context, null);
+                        Map<String,?> properties = Collections.singletonMap(XML.DEFAULT_NAMESPACE, getDefaultNamespace());
+                        jaxb = pool = new MarshallerPool(context, properties);
                     }
                 }
             }

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamReader.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -335,10 +335,12 @@ public abstract class StaxStreamReader e
      * @return the current text element as a floating point number, or {@code null} if empty.
      * @throws XMLStreamException if a text element can not be returned.
      * @throws NumberFormatException if the text can not be parsed as a floating point number.
+     *
+     * @see #parseDouble(String)
      */
     protected final Double getElementAsDouble() throws XMLStreamException {
         final String text = getElementText();
-        return (text != null) ? Numerics.valueOf(Double.parseDouble(text)) : null;
+        return (text != null) ? Numerics.valueOf(parseDouble(text)) : null;
     }
 
     /**
@@ -379,12 +381,59 @@ public abstract class StaxStreamReader e
     }
 
     /**
+     * Parses the given text as a XML floating point number. This method performs the same parsing than
+     * {@link Double#valueOf(String)} with the addition of {@code INF} and {@code -INF} values.
+     * The following summarizes the special values (note that parsing is case-sensitive):
+     *
+     * <ul>
+     *   <li>{@code NaN}  — a XML value which is also understood natively by {@link Double#valueOf(String)}.</li>
+     *   <li>{@code INF}  — a XML value which is processed by this method.</li>
+     *   <li>{@code -INF} — a XML value which is processed by this method.</li>
+     *   <li>{@code +INF} — illegal XML value, nevertheless processed by this method.</li>
+     *   <li>{@code Infinity} — a {@link Double#valueOf(String)} specific value.</li>
+     * </ul>
+     *
+     * <div class="note"><b>Note:</b>
+     * this method duplicates {@link javax.xml.bind.DatatypeConverter#parseDouble(String)} work,
+     * but avoid synchronization or volatile field cost of {@code DatatypeConverter}.</div>
+     *
+     * @param  value  the text to parse.
+     * @return the floating point value for the given text.
+     * @throws NumberFormatException if parsing failed.
+     *
+     * @see #getElementAsDouble()
+     * @see javax.xml.bind.DatatypeConverter#parseDouble(String)
+     */
+    @SuppressWarnings("fallthrough")
+    protected static double parseDouble(final String value) throws NumberFormatException {
+        if (!value.endsWith("INF")) {
+            return Double.parseDouble(value);
+        }
+parse:  switch (value.length()) {
+            case 4: switch (value.charAt(0)) {
+                default:  break parse;
+                case '-': return Double.NEGATIVE_INFINITY;
+                case '+': // Fall through
+            }
+            case 3: return Double.POSITIVE_INFINITY;
+        }
+        throw new NumberFormatException(value);
+    }
+
+    /**
      * Parses the given string as a boolean value. This method performs the same parsing than
      * {@link Boolean#parseBoolean(String)} with one extension: the "0" value is considered
      * as {@code false} and the "1" value as {@code true}.
      *
-     * @param value The string value to parse as a boolean.
+     * <div class="note"><b>Note:</b>
+     * this method duplicates {@link javax.xml.bind.DatatypeConverter#parseBoolean(String)} work
+     * (except for its behavior in case of invalid value), but avoid synchronization or volatile
+     * field cost of {@code DatatypeConverter}.</div>
+     *
+     * @param value  the string value to parse as a boolean.
      * @return true if the boolean is equal to "true" or "1".
+     *
+     * @see javax.xml.bind.DatatypeConverter#parseBoolean(String)
      */
     protected static boolean parseBoolean(final String value) {
         if (value.length() == 1) {

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/main/java/org/apache/sis/internal/xml/StaxStreamWriter.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -20,7 +20,9 @@ import java.util.Map;
 import java.util.Date;
 import java.io.IOException;
 import java.nio.charset.Charset;
+import javax.xml.namespace.QName;
 import javax.xml.bind.Marshaller;
+import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
@@ -128,11 +130,12 @@ public abstract class StaxStreamWriter e
      *         {@link DataStoreException}, {@link ClassCastException}, <i>etc.</i>
      */
     public void writeStartDocument() throws Exception {
-        Charset encoding = owner.encoding;
-        if (encoding == null) {
-            encoding = Charset.defaultCharset();
+        final Charset encoding = owner.encoding;
+        if (encoding != null) {
+            writer.writeStartDocument(encoding.name());
+        } else {
+            writer.writeStartDocument();
         }
-        writer.writeStartDocument(encoding.name());
     }
 
     /**
@@ -243,22 +246,39 @@ public abstract class StaxStreamWriter e
     /**
      * Delegates to JAXB the marshalling of a part of XML document.
      *
-     * @param  object  the object to marshall, or {@code null} if none.
+     * @param  <T>     compile-time value of the {@code type} argument.
+     * @param  name    the XML tag to write.
+     * @param  type    the Java class that define the XML schema of the object to marshal.
+     * @param  object  the object to marshal, or {@code null} if none.
+     * @param  defaultNamespace  the namespace to omit (i.e. the namespace of elements to move in the default namespace),
+     *                 or {@code null} if none. This is used for removing the redundant {@code xmlns} attributes inserted
+     *                 by JAXB.
      * @throws XMLStreamException if the XML stream is closed.
      * @throws JAXBException if an error occurred during marshalling.
      *
      * @see javax.xml.bind.Marshaller#marshal(Object, XMLStreamWriter)
      */
-    protected final void marshal(final Object object) throws XMLStreamException, JAXBException {
+    protected final <T> void marshal(final String defaultNamespace, final String name, final Class<T> type, final T object)
+            throws XMLStreamException, JAXBException
+    {
         Marshaller m = marshaller;
         if (m == null) {
             m = getMarshallerPool().acquireMarshaller();
+            m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
             for (final Map.Entry<String,?> entry : ((Map<String,?>) owner.configuration).entrySet()) {
                 m.setProperty(entry.getKey(), entry.getValue());
             }
         }
+        final QName qn;
+        XMLStreamWriter out = writer;
+        if (defaultNamespace != null) {
+            out = new DefaultNamespaceStreamWriter(writer, defaultNamespace);
+            qn = new QName(defaultNamespace, name);
+        } else {
+            qn = new QName(name);
+        }
         marshaller = null;
-        m.marshal(object, writer);
+        m.marshal(new JAXBElement<>(qn, type, object), out);
         marshaller = m;                 // Allow reuse or recycling only on success.
     }
 

Modified: sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java?rev=1776095&r1=1776094&r2=1776095&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-xmlstore/src/test/java/org/apache/sis/internal/gpx/GPXWriterTest.java [UTF-8] Tue Dec 27 09:05:34 2016
@@ -18,14 +18,17 @@ package org.apache.sis.internal.gpx;
 
 import java.net.URI;
 import java.io.ByteArrayOutputStream;
+import java.io.UnsupportedEncodingException;
 import java.util.Date;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import com.esri.core.geometry.Point;
+import org.apache.sis.storage.gps.Fix;
 import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.util.Debug;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.BeforeClass;
@@ -37,7 +40,6 @@ import static org.junit.Assert.*;
 // Branch-dependent imports
 import java.time.LocalDate;
 import java.util.stream.Stream;
-import org.apache.sis.storage.gps.Fix;
 import org.opengis.feature.Feature;
 
 
@@ -88,6 +90,22 @@ public final strictfp class GPXWriterTes
     }
 
     /**
+     * Returns a string representation of the XML data written by the test case.
+     * This is a helper method for debugging purpose only.
+     *
+     * @return the XML document written by the test case.
+     */
+    @Debug
+    @Override
+    public String toString() {
+        try {
+            return output.toString("UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new AssertionError(e);
+        }
+    }
+
+    /**
      * Test writing GPX metadata.
      *
      * @throws Exception if an error occurred while writing the XML data.



Mime
View raw message