sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1547992 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/ sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-refere...
Date Thu, 05 Dec 2013 02:00:00 GMT
Author: desruisseaux
Date: Thu Dec  5 01:59:59 2013
New Revision: 1547992

URL: http://svn.apache.org/r1547992
Log:
First draft of namespace URI replacements done at marshalling time.

Added:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java   (with props)
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java   (with props)
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java   (with props)
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java   (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/GM_Object.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/ObjectFactory.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant31.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod31.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
    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/internal/jaxb/LegacyNamespaces.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Version.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

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/GM_Object.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/GM_Object.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/GM_Object.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/GM_Object.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -49,7 +49,8 @@ public class GM_Object extends XmlAdapte
      * Same as {@link #geometry}, but using GML 3.1 namespace.
      * This is hopefully a temporary patch.
      */
-    @XmlElementRef(name = "AbstractGeometry", namespace = LegacyNamespaces.GML, type = JAXBElement.class)
+    @Deprecated
+    @XmlElementRef(name = "AbstractGeometry", namespace = LegacyNamespaces.GML_IN_JAXB, type = JAXBElement.class)
     protected JAXBElement<? extends Geometry> geometry31;
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/ObjectFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/ObjectFactory.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/ObjectFactory.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/geometry/ObjectFactory.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -41,19 +41,19 @@ public class ObjectFactory {
      * The qualified name of {@code <AbstractGeometry>}.
      */
     protected static final QName AbstractGeometry_QNAME   = new QName(Namespaces.GML, "AbstractGeometry"),
-                                 AbstractGeometry31_QNAME = new QName(LegacyNamespaces.GML, "AbstractGeometry");
+                                 AbstractGeometry31_QNAME = new QName(LegacyNamespaces.GML_IN_JAXB, "AbstractGeometry");
 
     /**
      * The qualified name of {@code <AbstractGML>}.
      */
     protected static final QName AbstractGML_QNAME   = new QName(Namespaces.GML, "AbstractGML"),
-                                 AbstractGML31_QNAME = new QName(LegacyNamespaces.GML, "AbstractGML");
+                                 AbstractGML31_QNAME = new QName(LegacyNamespaces.GML_IN_JAXB, "AbstractGML");
 
     /**
      * The qualified name of {@code <AbstractObject>}.
      */
     protected static final QName AbstractObject_QNAME   = new QName(Namespaces.GML, "AbstractObject"),
-                                 AbstractObject31_QNAME = new QName(LegacyNamespaces.GML, "AbstractObject");
+                                 AbstractObject31_QNAME = new QName(LegacyNamespaces.GML_IN_JAXB, "AbstractObject");
 
     /**
      * Creates an instance of {@code JAXBElement<Object>}}.
@@ -72,7 +72,8 @@ public class ObjectFactory {
      * @param  value The {@code Object} value to wrap.
      * @return The wrapped value in the legacy namespace.
      */
-    @XmlElementDecl(name = "AbstractObject", namespace = LegacyNamespaces.GML)
+    @Deprecated
+    @XmlElementDecl(name = "AbstractObject", namespace = LegacyNamespaces.GML_IN_JAXB)
     public JAXBElement<Object> createObject31(final Object value) {
         return new JAXBElement<>(AbstractObject31_QNAME, Object.class, null, value);
     }
@@ -101,11 +102,12 @@ public class ObjectFactory {
      * @param  value The GML {@code AbstractGMLType} value to wrap.
      * @return The wrapped value in the legacy namespace.
      */
+    @Deprecated
     @Workaround(library = "JAXB", version = "2.1")
     @XmlElementDecl(name = "AbstractGML",
-            namespace = LegacyNamespaces.GML,
+            namespace = LegacyNamespaces.GML_IN_JAXB,
             substitutionHeadName = "AbstractObject",
-            substitutionHeadNamespace = LegacyNamespaces.GML) // Not necessary according javadoc, but appears to be in practice (JAXB 2.1 bug?)
+            substitutionHeadNamespace = LegacyNamespaces.GML_IN_JAXB) // Not necessary according javadoc, but appears to be in practice (JAXB 2.1 bug?)
     public JAXBElement<Object> createAbstractGML31(final Object value) {
         return new JAXBElement<>(AbstractGML31_QNAME, Object.class, null, value);
     }
@@ -134,11 +136,12 @@ public class ObjectFactory {
      * @param  value The {@code AbstractGeometryType} value to wrap.
      * @return The wrapped value in the legacy namespace.
      */
+    @Deprecated
     @Workaround(library = "JAXB", version = "2.1")
     @XmlElementDecl(name = "AbstractGeometry",
-            namespace = LegacyNamespaces.GML,
+            namespace = LegacyNamespaces.GML_IN_JAXB,
             substitutionHeadName = "AbstractGML",
-            substitutionHeadNamespace = LegacyNamespaces.GML) // Not necessary according javadoc, but appears to be in practice (JAXB 2.1 bug?)
+            substitutionHeadNamespace = LegacyNamespaces.GML_IN_JAXB) // Not necessary according javadoc, but appears to be in practice (JAXB 2.1 bug?)
     public JAXBElement<Object> createAbstractGeometry31(final Object value) {
         return new JAXBElement<>(AbstractGeometry31_QNAME, Object.class, null, value);
     }

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/GMLAdapter.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -19,7 +19,6 @@ package org.apache.sis.internal.jaxb.gml
 import javax.xml.bind.annotation.XmlID;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlTransient;
-import org.apache.sis.util.Version;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.IdentifierMap;
 import org.apache.sis.xml.IdentifierSpace;
@@ -43,12 +42,6 @@ import org.apache.sis.xml.IdentifiedObje
 @XmlTransient
 public abstract class GMLAdapter {
     /**
-     * A GML version suitable for calls to {@link org.apache.sis.internal.jaxb.Context#isGMLVersion}.
-     */
-    public static final Version GML_3_0 = new Version("3.0"),
-                                GML_3_2 = new Version("3.2");
-
-    /**
      * The period identifier, or {@code null} if undefined.
      * This element is part of GML 3.1.1 specification.
      *

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TM_Primitive.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -84,7 +84,7 @@ public final class TM_Primitive extends 
      * of GML schemas.</p>
      */
     private static boolean isGML32() {
-        return Context.isGMLVersion(Context.current(), GMLAdapter.GML_3_2);
+        return Context.isGMLVersion(Context.current(), LegacyNamespaces.VERSION_3_2);
     }
 
     /**
@@ -109,7 +109,8 @@ public final class TM_Primitive extends 
      *
      * @return The time period, or {@code null}.
      */
-    @XmlElement(name = "TimePeriod", namespace = LegacyNamespaces.GML)
+    @Deprecated
+    @XmlElement(name = "TimePeriod", namespace = LegacyNamespaces.GML_IN_JAXB)
     public TimePeriod31 getTimePeriod31() {
         if (!skip() && !isGML32()) {
             final TemporalPrimitive metadata = this.metadata;
@@ -142,7 +143,8 @@ public final class TM_Primitive extends 
      *
      * @return The time instant, or {@code null}.
      */
-    @XmlElement(name = "TimeInstant", namespace = LegacyNamespaces.GML)
+    @Deprecated
+    @XmlElement(name = "TimeInstant", namespace = LegacyNamespaces.GML_IN_JAXB)
     public TimeInstant31 getTimeInstant31() {
         if (!skip() && !isGML32()) {
             final TemporalPrimitive metadata = this.metadata;

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant31.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant31.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant31.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant31.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -33,12 +33,13 @@ import org.apache.sis.internal.jaxb.Lega
  * @version 0.4
  * @module
  */
-@XmlRootElement(name="TimeInstant", namespace = LegacyNamespaces.GML)
+@Deprecated
+@XmlRootElement(name="TimeInstant", namespace = LegacyNamespaces.GML_IN_JAXB)
 public final class TimeInstant31 extends GMLAdapter {
     /**
      * Same as {@link TimeInstant#timePosition}, but using GML 3.1 namespace.
      */
-    @XmlElement(namespace = LegacyNamespaces.GML)
+    @XmlElement(namespace = LegacyNamespaces.GML_IN_JAXB)
     public XMLGregorianCalendar timePosition;
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -23,6 +23,8 @@ import javax.xml.bind.annotation.XmlRoot
 import org.opengis.temporal.Period;
 import org.apache.sis.internal.jaxb.Context;
 
+import static org.apache.sis.internal.jaxb.LegacyNamespaces.VERSION_3_0;
+
 
 /**
  * The adapter for {@code "TimePeriod"}. This is an attribute of {@link TM_Primitive}.
@@ -76,7 +78,7 @@ public final class TimePeriod extends GM
     public TimePeriod(final Period period) {
         super(period);
         if (period != null) {
-            if (Context.isGMLVersion(Context.current(), GML_3_0)) {
+            if (Context.isGMLVersion(Context.current(), VERSION_3_0)) {
                 begin = new TimePeriodBound.GML3(period.getBeginning(), "before");
                 end   = new TimePeriodBound.GML3(period.getEnding(), "after");
             } else {

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod31.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod31.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod31.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/TimePeriod31.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -26,7 +26,7 @@ import org.opengis.temporal.Period;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.LegacyNamespaces;
 
-import static org.apache.sis.internal.jaxb.gml.GMLAdapter.GML_3_0;
+import static org.apache.sis.internal.jaxb.LegacyNamespaces.VERSION_3_0;
 
 
 /**
@@ -39,7 +39,8 @@ import static org.apache.sis.internal.ja
  * @version 0.4
  * @module
  */
-@XmlRootElement(name="TimePeriod", namespace = LegacyNamespaces.GML)
+@Deprecated
+@XmlRootElement(name="TimePeriod", namespace = LegacyNamespaces.GML_IN_JAXB)
 @XmlType(propOrder = {
     "begin",
     "end"
@@ -49,8 +50,8 @@ public final class TimePeriod31 extends 
      * Same as {@link TimePeriod#begin}, but using GML 3.1 namespace.
      */
     @XmlElements({
-        @XmlElement(type=TimePeriodBound.GML3.class, name="beginPosition", namespace = LegacyNamespaces.GML),
-        @XmlElement(type=Bound.class, name="begin", namespace = LegacyNamespaces.GML)
+        @XmlElement(type=TimePeriodBound.GML3.class, name="beginPosition", namespace = LegacyNamespaces.GML_IN_JAXB),
+        @XmlElement(type=Bound.class, name="begin", namespace = LegacyNamespaces.GML_IN_JAXB)
     })
     TimePeriodBound begin;
 
@@ -58,8 +59,8 @@ public final class TimePeriod31 extends 
      * Same as {@link TimePeriod#end}, but using GML 3.1 namespace.
      */
     @XmlElements({
-        @XmlElement(type=TimePeriodBound.GML3.class, name="endPosition", namespace = LegacyNamespaces.GML),
-        @XmlElement(type=Bound.class, name="end", namespace = LegacyNamespaces.GML)
+        @XmlElement(type=TimePeriodBound.GML3.class, name="endPosition", namespace = LegacyNamespaces.GML_IN_JAXB),
+        @XmlElement(type=Bound.class, name="end", namespace = LegacyNamespaces.GML_IN_JAXB)
     })
     TimePeriodBound end;
 
@@ -77,7 +78,7 @@ public final class TimePeriod31 extends 
     public TimePeriod31(final Period period) {
         super(period);
         if (period != null) {
-            if (Context.isGMLVersion(Context.current(), GML_3_0)) {
+            if (Context.isGMLVersion(Context.current(), VERSION_3_0)) {
                 begin = new TimePeriodBound.GML3(period.getBeginning(), "before");
                 end   = new TimePeriodBound.GML3(period.getEnding(), "after");
             } else {
@@ -97,11 +98,12 @@ public final class TimePeriod31 extends 
      * @version 0.4
      * @module
      */
+    @Deprecated
     private static final class Bound extends TimePeriodBound {
         /**
          * Same as {@link TimePeriodBound.GML2#timeInstant}, but using GML 3.1 namespace.
          */
-        @XmlElement(name = "TimeInstant", namespace = LegacyNamespaces.GML)
+        @XmlElement(name = "TimeInstant", namespace = LegacyNamespaces.GML_IN_JAXB)
         public TimeInstant timeInstant;
 
         /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultVerticalDatum.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -29,7 +29,7 @@ import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.util.Immutable;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.internal.jaxb.Context;
-import org.apache.sis.internal.jaxb.gml.GMLAdapter;
+import org.apache.sis.internal.jaxb.LegacyNamespaces;
 import org.apache.sis.internal.referencing.VerticalDatumTypes;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -234,14 +234,14 @@ public class DefaultVerticalDatum extend
      * This element was present in GML 3.0 and 3.1, but has been removed from GML 3.2.
      */
     @XmlElement(name = "verticalDatumType")
-    private VerticalDatumType getMarshalled() {
-        return (Context.isGMLVersion(Context.current(), GMLAdapter.GML_3_2)) ? null : getVerticalDatumType();
+    private VerticalDatumType getTypeElement() {
+        return Context.isGMLVersion(Context.current(), LegacyNamespaces.VERSION_3_2) ? null : getVerticalDatumType();
     }
 
     /**
      * Invoked by JAXB only. The vertical datum type is set only if it has not already been specified.
      */
-    private void setMarshalled(final VerticalDatumType t) {
+    private void setTypeElement(final VerticalDatumType t) {
         if (type != null) {
             throw new IllegalStateException();
         }

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=1547992&r1=1547991&r2=1547992&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] Thu Dec  5 01:59:59 2013
@@ -19,9 +19,11 @@ package org.apache.sis.referencing.datum
 import javax.measure.unit.NonSI;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.JAXBException;
+import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
 import org.apache.sis.util.CharSequences;
+import org.apache.sis.internal.jaxb.LegacyNamespaces;
 import org.junit.Test;
 
 import static org.apache.sis.referencing.Assert.*;
@@ -79,14 +81,14 @@ public final strictfp class DefaultPrime
      * @throws JAXBException If an error occurred during marshalling.
      */
     @Test
-    @org.junit.Ignore
     public void testMarshallGML31() throws JAXBException {
         final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
         final MarshallerPool pool = getMarshallerPool();
         final Marshaller marshaller = pool.acquireMarshaller();
+        marshaller.setProperty(XML.GML_VERSION, LegacyNamespaces.VERSION_3_0);
         final String xml = marshal(marshaller, pm);
         pool.recycle(marshaller);
-        assertGreenwichXmlEquals("http://www.opengis.net/gml", marshal(pm));
+        assertGreenwichXmlEquals(LegacyNamespaces.GML, xml);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/LegacyNamespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/LegacyNamespaces.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/LegacyNamespaces.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/LegacyNamespaces.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -16,25 +16,41 @@
  */
 package org.apache.sis.internal.jaxb;
 
+import org.apache.sis.util.Version;
+
 
 /**
- * Legacy XML namespaces.
- * This class is hopefully temporary, if we can find a way to share the same Java classes between different versions.
- * If such better way is found, then every classes, methods and fields having a JAXB annotation using this namespace
- * should be deleted.
+ * Legacy XML namespaces, and {@link Version} constants for identifying when those namespaces were used.
  *
  * @author  Guilhem Legal (Geomatys)
  * @since   0.4
  * @version 0.4
  * @module
+ *
+ * @see org.apache.sis.xml.Namespaces
  */
 public final class LegacyNamespaces {
     /**
+     * Miscellaneous version constants.
+     */
+    public static final Version VERSION_3_0 = new Version("3.0"),
+                                VERSION_3_2 = new Version("3.2");
+
+    /**
      * The {@value} URL, which was used for all GML versions before 3.2.
      */
     public static final String GML = "http://www.opengis.net/gml";
 
     /**
+     * A copy of {@link #GML} used only in JAXB annotations.
+     * We use a separated constants in order to make easier to remove every uses of this namespace in
+     * all JAXB annotations if we can find a way to share the same Java classes between different versions.
+     * If such better way is found, then every classes, methods and fields using this constant should be deleted.
+     */
+    @Deprecated
+    public static final String GML_IN_JAXB = GML;
+
+    /**
      * Do not allow instantiation of this class.
      */
     private LegacyNamespaces() {

Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java?rev=1547992&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -0,0 +1,143 @@
+/*
+ * 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.File;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.io.Writer;
+import java.io.OutputStream;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.Result;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.sax.SAXResult;
+import javax.xml.transform.stax.StAXResult;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+import org.apache.sis.util.Static;
+import org.apache.sis.util.resources.Errors;
+
+
+/**
+ * Provides access to {@link javax.xml.stream.XMLOutputFactory} 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 XMLOutputFactory extends Static {
+    /**
+     * The SIS-wide factory.
+     */
+    private static final javax.xml.stream.XMLOutputFactory FACTORY = javax.xml.stream.XMLOutputFactory.newInstance();
+
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private XMLOutputFactory() {
+    }
+
+    /**
+     * Creates a new writer for the given file.
+     *
+     * @param  out Where to write to.
+     * @return The writer.
+     * @throws XMLStreamException If the writer can not be created.
+     */
+    public static XMLStreamWriter createXMLStreamWriter(final File out) throws XMLStreamException {
+        try {
+            return FACTORY.createXMLStreamWriter(new FileOutputStream(out));
+        } catch (FileNotFoundException e) {
+            throw new XMLStreamException(Errors.format(Errors.Keys.CanNotOpen_1, out), e);
+        }
+    }
+
+    /**
+     * Creates a new writer for the given stream.
+     *
+     * @param  out Where to write to.
+     * @return The writer.
+     * @throws XMLStreamException If the writer can not be created.
+     */
+    public static XMLStreamWriter createXMLStreamWriter(final OutputStream out) throws XMLStreamException {
+        return FACTORY.createXMLStreamWriter(out);
+    }
+
+    /**
+     * Creates a new writer for the given stream.
+     *
+     * @param  out Where to write to.
+     * @return The writer.
+     * @throws XMLStreamException If the writer can not be created.
+     */
+    public static XMLStreamWriter createXMLStreamWriter(final Writer out) throws XMLStreamException {
+        return FACTORY.createXMLStreamWriter(out);
+    }
+
+    /**
+     * Creates a new writer for the JAXP result.
+     * Note that this method is identified as <em>optional</em> in JSE javadoc.
+     *
+     * @param  out Where to write to.
+     * @return The writer.
+     * @throws XMLStreamException If the writer can not be created.
+     */
+    public static XMLStreamWriter createXMLStreamWriter(final ContentHandler out) throws XMLStreamException {
+        return FACTORY.createXMLStreamWriter(new SAXResult(out));
+    }
+
+    /**
+     * Creates a new writer for the JAXP result.
+     * Note that this method is identified as <em>optional</em> in JSE javadoc.
+     *
+     * @param  out Where to write to.
+     * @return The writer.
+     * @throws XMLStreamException If the writer can not be created.
+     */
+    public static XMLStreamWriter createXMLStreamWriter(final Node out) throws XMLStreamException {
+        return FACTORY.createXMLStreamWriter(new DOMResult(out));
+    }
+
+    /**
+     * Creates a new writer for the JAXP result.
+     * Note that this method is identified as <em>optional</em> in JSE javadoc.
+     *
+     * @param  out Where to write to.
+     * @return The writer.
+     * @throws XMLStreamException If the writer can not be created.
+     */
+    public static XMLStreamWriter createXMLStreamWriter(final XMLEventWriter out) throws XMLStreamException {
+        return FACTORY.createXMLStreamWriter(new StAXResult(out));
+    }
+
+    /**
+     * Creates a new writer for the JAXP result.
+     * Note that this method is identified as <em>optional</em> in JSE javadoc.
+     *
+     * @param  out Where to write to.
+     * @return The writer.
+     * @throws XMLStreamException If the writer can not be created.
+     */
+    public static XMLStreamWriter createXMLStreamWriter(final Result out) throws XMLStreamException {
+        return FACTORY.createXMLStreamWriter(out);
+    }
+}

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

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

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/measure/UnitsMap.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -53,8 +53,9 @@ final class UnitsMap extends Static {
      */
     static final Map<Unit<?>,Integer> EPSG_CODES = new HashMap<>(20);
     static {
-        final int[] codes = {9001, 9002, 9030, 9036, 9101, 9102, 9103, 9104, 9105, 9108, 9109, 9111, 9110, 9201, 9202};
-        for (final int code : codes) {
+        final byte[] codes = {1, 2, 30, 36, 101, 102, 103, 104, 105, 108, 109, 111, 110, (byte) 201, (byte) 202};
+        for (final byte c : codes) {
+            final int code = 9000 + (c & 0xFF);
             EPSG_CODES.put(Units.valueOfEPSG(code), code);
         }
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Version.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Version.java?rev=1547992&r1=1547991&r2=1547992&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Version.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/Version.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -244,6 +244,7 @@ public class Version implements CharSequ
      *         value if it is higher, or 0 if they are equal.
      */
     public int compareTo(final Version other, final int limit) {
+        ArgumentChecks.ensureNonNull ("other", other);
         ArgumentChecks.ensurePositive("limit", limit);
         for (int i=0; i<limit; i++) {
             final Comparable<?> v1 =  this.getComponent(i);

Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java?rev=1547992&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -0,0 +1,58 @@
+/*
+ * 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.xml;
+
+import java.util.Map;
+import org.apache.sis.internal.jaxb.LegacyNamespaces;
+
+import static java.util.Collections.singletonMap;
+
+
+/**
+ * The target version of standards for {@link FilteredNamespaces}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+enum FilterVersion {
+    /**
+     * GML using the legacy {@code "http://www.opengis.net/gml"} namespace.
+     */
+    GML31(Namespaces.GML, LegacyNamespaces.GML);
+
+    /**
+     * The URIs to replace. Keys are the old URIs, and values are the new URIs to use instead of the old one.
+     * This map must be immutable.
+     */
+    final Map<String,String> replacements;
+
+    /**
+     * The converse of {@link #replacements}. Keys are the new URIs, and values are the old URIs which are
+     * replaced by the new ones. This map is inferred from {@link #replacements} and must be immutable.
+     */
+    final Map<String,String> toDelegate;
+
+    /**
+     * Creates a new enum for replacing only one namespace.
+     */
+    private FilterVersion(final String from, final String to) {
+        this.replacements = singletonMap(from, to);
+        this.toDelegate   = singletonMap(to, from);
+    }
+}

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

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

Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java?rev=1547992&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -0,0 +1,126 @@
+/*
+ * 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.xml;
+
+import java.util.Map;
+import java.util.Iterator;
+import javax.xml.namespace.NamespaceContext;
+
+
+/**
+ * Substitutes at (un)marshalling time the XML namespaces used by SIS by the namespaces used in the XML document.
+ * This class is used internally by {@link FilteredStreamReader} and {@link FilteredStreamWriter} only.
+ *
+ * {@section The problem}
+ * When the XML schemas of an international standard is updated, the URL of the namespace is often modified.
+ * For example when GML has been updated from version 3.1 to 3.2, the URL mandated by the international standard
+ * changed from {@code "http://www.opengis.net/gml"} to {@code "http://www.opengis.net/gml/3.2"}
+ * (XML namespaces usually have a version number or publication year - GML before 3.2 were an exception).
+ *
+ * The problem is that namespaces in JAXB annotations are static. The straightforward solution is
+ * to generate complete new set of classes for every GML version using the {@code xjc} compiler.
+ * But this approach has many inconvenient:
+ *
+ * <ul>
+ *   <li>Massive code duplication (hundreds of classes, many of them strictly identical except for the namespace).</li>
+ *   <li>Handling of above-cited classes duplication requires either a bunch of {@code if (x instanceof Y)} in every
+ *       SIS corners (unconceivable), or to modify the {@code xjc} output in order to give to generated classes a
+ *       common parent class or interface. In the later case, the auto-generated classes require significant work
+ *       anyways.</li>
+ *   <li>The namespaces of all versions appear in the {@code xmlns} attributes of the root element (we can not always
+ *       create separated JAXB contexts), which is confusing and prevent usage of usual prefixes for all versions
+ *       except one.</li>
+ * </ul>
+ *
+ * An alternative is to support only one version of each standard, and transform XML documents before unmarshalling
+ * or after marshalling if they use different versions of standards. We could use XSLT for that, but this is heavy.
+ * A lighter approach is to use {@link javax.xml.stream.XMLStreamReader} and {@link javax.xml.stream.XMLStreamWriter}
+ * as "micro-transformers".
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+final class FilteredNamespaces implements NamespaceContext {
+    /**
+     * The context to wrap, given by {@link FilteredStreamReader} or {@link FilteredStreamWriter}.
+     *
+     * @see javax.xml.stream.XMLStreamReader#getNamespaceContext()
+     * @see javax.xml.stream.XMLStreamWriter#getNamespaceContext()
+     */
+    final NamespaceContext delegate;
+
+    /**
+     * The URIs to replace, as a copy of the {@link FilterVersion#replacements} reference.
+     */
+    private final Map<String,String> replacements;
+
+    /**
+     * The converse of {@link #replacements}, as a copy of the {@link FilterVersion#toDelegate} reference.
+     */
+    private final Map<String,String> toDelegate;
+
+    /**
+     * Creates a new namespaces filter for the given target version.
+     */
+    FilteredNamespaces(final NamespaceContext delegate, final FilterVersion version) {
+        this.delegate     = delegate;
+        this.replacements = version.replacements;
+        this.toDelegate   = version.toDelegate;
+    }
+
+    /**
+     * Returns the URI to make visible to the user of this filter.
+     */
+    private String replacement(final String uri) {
+        final String replacement = replacements.get(uri);
+        return (replacement != null) ? replacement : uri;
+    }
+
+    /**
+     * Returns the URI used by the {@linkplain #delegate}.
+     */
+    private String toDelegate(final String uri) {
+        final String replacement = toDelegate.get(uri);
+        return (replacement != null) ? replacement : uri;
+    }
+
+    /**
+     * Returns the namespace for the given prefix.
+     */
+    @Override
+    public String getNamespaceURI(final String prefix) {
+        return toDelegate(delegate.getNamespaceURI(prefix));
+    }
+
+    /**
+     * Returns the prefix for the given namespace.
+     */
+    @Override
+    public String getPrefix(final String namespaceURI) {
+        return delegate.getPrefix(replacement(namespaceURI));
+    }
+
+    /**
+     * Returns all prefixes for the given namespace.
+     */
+    @Override
+    public Iterator<String> getPrefixes(final String namespaceURI) {
+        return delegate.getPrefixes(replacement(namespaceURI));
+    }
+}

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

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

Added: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java?rev=1547992&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java (added)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java [UTF-8] Thu Dec  5 01:59:59 2013
@@ -0,0 +1,257 @@
+/*
+ * 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.xml;
+
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.namespace.NamespaceContext;
+
+
+/**
+ * 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.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+final class FilteredStreamWriter implements XMLStreamWriter {
+    /**
+     * Where to write the XML.
+     */
+    private final XMLStreamWriter out;
+
+    /**
+     * The other version to marshall to.
+     */
+    private final FilterVersion version;
+
+    /**
+     * Creates a new filter for the given version of the standards.
+     */
+    FilteredStreamWriter(final XMLStreamWriter out, final FilterVersion version) {
+        this.out     = out;
+        this.version = version;
+    }
+
+    /**
+     * Returns the URI to write in the XML document.
+     */
+    private String replacement(final String uri) {
+        final String replacement = version.replacements.get(uri);
+        return (replacement != null) ? replacement : uri;
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeStartElement(String localName) throws XMLStreamException {
+        out.writeStartElement(localName);
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
+        out.writeStartElement(replacement(namespaceURI), localName);
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+        out.writeStartElement(prefix, localName, replacement(namespaceURI));
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
+        out.writeEmptyElement(replacement(namespaceURI), localName);
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+        out.writeEmptyElement(prefix, localName, replacement(namespaceURI));
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeEmptyElement(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(String localName, String value) throws XMLStreamException {
+        out.writeAttribute(localName, value);
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
+        out.writeAttribute(prefix, replacement(namespaceURI), localName, value);
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
+        out.writeAttribute(replacement(namespaceURI), localName, value);
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
+        out.writeNamespace(prefix, replacement(namespaceURI));
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
+        out.writeDefaultNamespace(replacement(namespaceURI));
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeComment(String data) throws XMLStreamException {
+        out.writeComment(data);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeProcessingInstruction(String target) throws XMLStreamException {
+        out.writeProcessingInstruction(target);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
+        out.writeProcessingInstruction(target, data);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeCData(String data) throws XMLStreamException {
+        out.writeCData(data);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeDTD(String dtd) throws XMLStreamException {
+        out.writeDTD(dtd);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeEntityRef(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(String version) throws XMLStreamException {
+        out.writeStartDocument(version);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeStartDocument(String encoding, String version) throws XMLStreamException {
+        out.writeStartDocument(encoding, version);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public void writeCharacters(String text) throws XMLStreamException {
+        out.writeCharacters(text);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    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. */
+    @Override
+    public String getPrefix(String uri) throws XMLStreamException {
+        return out.getPrefix(replacement(uri));
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void setPrefix(String prefix, String uri) throws XMLStreamException {
+        out.setPrefix(prefix, replacement(uri));
+    }
+
+    /** Replaces the given URI if needed, then forwards the call. */
+    @Override
+    public void setDefaultNamespace(String uri) throws XMLStreamException {
+        out.setDefaultNamespace(replacement(uri));
+    }
+
+    /** Unwraps the original context and forwards the call. */
+    @Override
+    public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
+        if (context instanceof FilteredNamespaces) {
+            context = ((FilteredNamespaces) context).delegate;
+        } else {
+            context = new FilteredNamespaces(context, version);
+        }
+        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);
+    }
+
+    /** Forwards the call verbatim. */
+    @Override
+    public Object getProperty(String name) throws IllegalArgumentException {
+        return out.getProperty(name);
+    }
+}

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

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

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=1547992&r1=1547991&r2=1547992&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] Thu Dec  5 01:59:59 2013
@@ -120,6 +120,8 @@ abstract class Pooled {
     /**
      * The GML version to be marshalled or unmarshalled, or {@code null} if unspecified.
      * If null, then the latest version is assumed.
+     *
+     * @see #getGMLVersion()
      */
     private Version gmlVersion;
 
@@ -231,6 +233,14 @@ 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 initial property is already saved for the given key.
      * Note that a property set to {@code null} is still considered as defined.
      */

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=1547992&r1=1547991&r2=1547992&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] Thu Dec  5 01:59:59 2013
@@ -27,12 +27,16 @@ import javax.xml.bind.annotation.adapter
 import javax.xml.bind.attachment.AttachmentMarshaller;
 import javax.xml.stream.XMLEventWriter;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
 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;
 
 
 /**
@@ -48,7 +52,7 @@ import org.apache.sis.internal.jaxb.Cont
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @Decorator(Marshaller.class)
@@ -103,16 +107,61 @@ final class PooledMarshaller extends Poo
     }
 
     /**
-     * Delegates the marshalling to the wrapped marshaller.
+     * Returns the {@code FilterVersion} enumeration value to use for the current GML version,
+     * or {@code null} if the SIS default version is suitable.
      */
-    @Override
-    public void marshal(final Object object, final Result output) throws JAXBException {
+    private FilterVersion getFilterVersion() {
+        final Version gmlVersion = getGMLVersion();
+        if (gmlVersion != null && 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 in an GML version
+     * older than the one supported natively by SIS.
+     *
+     * @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,
+            final boolean close) throws XMLStreamException, JAXBException
+    {
+        output = new FilteredStreamWriter(output, version);
         final Context context = begin();
         try {
             marshaller.marshal(object, output);
         } finally {
             context.finish();
         }
+        if (close) {
+            output.close();
+        } else {
+            output.flush();
+        }
+    }
+
+    /**
+     * Delegates the marshalling to the wrapped marshaller.
+     */
+    @Override
+    public void marshal(final Object object, final Result output) throws JAXBException {
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, false);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
+        }
     }
 
     /**
@@ -120,11 +169,19 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public void marshal(final Object object, final OutputStream output) throws JAXBException {
-        final Context context = begin();
-        try {
-            marshaller.marshal(object, output);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, false);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -133,11 +190,19 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public void marshal(final Object object, final File output) throws JAXBException {
-        final Context context = begin();
-        try {
-            marshaller.marshal(object, output);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, true);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -146,11 +211,19 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public void marshal(final Object object, final Writer output) throws JAXBException {
-        final Context context = begin();
-        try {
-            marshaller.marshal(object, output);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, false);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -159,11 +232,19 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public void marshal(final Object object, final ContentHandler output) throws JAXBException {
-        final Context context = begin();
-        try {
-            marshaller.marshal(object, output);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, false);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -172,11 +253,19 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public void marshal(final Object object, final Node output) throws JAXBException {
-        final Context context = begin();
-        try {
-            marshaller.marshal(object, output);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, false);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -185,11 +274,19 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public void marshal(final Object object, final XMLStreamWriter output) throws JAXBException {
-        final Context context = begin();
-        try {
-            marshaller.marshal(object, output);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, output, version, false);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
         }
     }
 
@@ -198,11 +295,19 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public void marshal(final Object object, final XMLEventWriter output) throws JAXBException {
-        final Context context = begin();
-        try {
-            marshaller.marshal(object, output);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) try {
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, false);
+        } catch (XMLStreamException e) {
+            throw new JAXBException(e);
+        } else {
+            // Marshalling to the default GML version.
+            final Context context = begin();
+            try {
+                marshaller.marshal(object, output);
+            } finally {
+                context.finish();
+            }
         }
     }
 



Mime
View raw message