sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1548015 - in /sis/branches/JDK7/core: sis-referencing/src/test/java/org/apache/sis/referencing/datum/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/main/java/org/apache/sis/xml/
Date Thu, 05 Dec 2013 05:03:39 GMT
Author: desruisseaux
Date: Thu Dec  5 05:03:39 2013
New Revision: 1548015

URL: http://svn.apache.org/r1548015
Log:
Allow disabling of namespace replacements.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.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/xml/FilterVersion.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.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-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=1548015&r1=1548014&r2=1548015&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 05:03:39 2013
@@ -24,6 +24,7 @@ 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.apache.sis.test.DependsOnMethod;
 import org.junit.Test;
 
 import static org.apache.sis.referencing.Assert.*;
@@ -81,6 +82,7 @@ public final strictfp class DefaultPrime
      * @throws JAXBException If an error occurred during marshalling.
      */
     @Test
+    @DependsOnMethod("testMarshall")
     public void testMarshallGML31() throws JAXBException {
         final DefaultPrimeMeridian pm = new DefaultPrimeMeridian(GREENWICH);
         final MarshallerPool pool = getMarshallerPool();

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java?rev=1548015&r1=1548014&r2=1548015&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] Thu Dec  5 05:03:39 2013
@@ -85,6 +85,13 @@ public final class Context extends Marsh
     public static final int SUBSTITUTE_MIMETYPE = 16;
 
     /**
+     * The bit flag for disabling usage of {@link org.apache.sis.xml.FilteredNamespaces}.
+     *
+     * @see org.apache.sis.internal.jaxb.LegacyNamespaces#DISABLE_NAMESPACE_REPLACEMENTS
+     */
+    public static final int DISABLE_NAMESPACE_REPLACEMENTS = 32;
+
+    /**
      * The thread-local context. Elements are created in the constructor, and removed in
a
      * {@code finally} block by the {@link #finish()} method. This {@code ThreadLocal} shall
      * not contain any value when no (un)marshalling is in progress.

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=1548015&r1=1548014&r2=1548015&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 05:03:39 2013
@@ -38,12 +38,14 @@ public final class LegacyNamespaces {
 
     /**
      * The {@value} URL, which was used for all GML versions before 3.2.
+     * This URL should not be used in JAXB annotations, even if the annotated element is
really for that
+     * legacy GML version. Instead, namespace replacements are applied on-the-fly at marshalling
time.
      */
     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
+     * We use a separated constant 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.
      */
@@ -51,6 +53,11 @@ public final class LegacyNamespaces {
     public static final String GML_IN_JAXB = GML;
 
     /**
+     * A non-public (un)marshaller property for disabling usage of {@link org.apache.sis.xml.FilteredNamespaces}.
+     */
+    public static final String DISABLE_NAMESPACE_REPLACEMENTS = "org.apache.sis.xml.disableNamespaceReplacements";
+
+    /**
      * Do not allow instantiation of this class.
      */
     private LegacyNamespaces() {

Modified: 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=1548015&r1=1548014&r2=1548015&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java
[UTF-8] Thu Dec  5 05:03:39 2013
@@ -25,6 +25,8 @@ import static java.util.Collections.sing
 /**
  * The target version of standards for {@link FilteredNamespaces}.
  *
+ * See {@link FilteredNamespaces} for more information.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4

Modified: 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=1548015&r1=1548014&r2=1548015&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamWriter.java
[UTF-8] Thu Dec  5 05:03:39 2013
@@ -26,6 +26,8 @@ import javax.xml.namespace.NamespaceCont
  * 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.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
  * @version 0.4

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=1548015&r1=1548014&r2=1548015&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 05:03:39 2013
@@ -36,6 +36,7 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.util.logging.WarningListener;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.jaxb.LegacyNamespaces;
 
 
 /**
@@ -188,14 +189,6 @@ abstract class Pooled {
     }
 
     /**
-     * Returns the initial value of {@link Context#bitMasks}. Shall be 0 if this object is
-     * an unmarshaller, or {@link Context#MARSHALLING} if it is an {@link Unmarshaller}.
-     */
-    private int initialBitMasks() {
-        return (this instanceof Marshaller) ? Context.MARSHALLING : 0;
-    }
-
-    /**
      * Releases resources and resets the (un)marshaller to its initial state.
      * This method is invoked by {@link MarshallerPool} just before to push a
      * (un)marshaller in the pool after its usage.
@@ -208,7 +201,7 @@ abstract class Pooled {
             reset(entry.getKey(), entry.getValue());
         }
         initialProperties.clear();
-        bitMasks        = initialBitMasks();
+        bitMasks        = template.bitMasks;
         locale          = template.locale;
         timezone        = template.timezone;
         schemas         = template.schemas;
@@ -217,6 +210,9 @@ abstract class Pooled {
         converter       = template.converter;
         warningListener = template.warningListener;
         resetTime       = System.nanoTime();
+        if (this instanceof Marshaller) {
+            bitMasks |= Context.MARSHALLING;
+        }
     }
 
     /**
@@ -241,6 +237,13 @@ abstract class Pooled {
     }
 
     /**
+     * Returns {@code true} if the given {@link Context} bit is set.
+     */
+    final boolean isFlagSet(final int mask) {
+        return (bitMasks & mask) != 0;
+    }
+
+    /**
      * 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.
      */
@@ -329,27 +332,36 @@ abstract class Pooled {
                     return;
                 }
                 case XML.STRING_SUBSTITUTES: {
-                    int mask = initialBitMasks();
+                    bitMasks &= ~(Context.SUBSTITUTE_LANGUAGE |
+                                  Context.SUBSTITUTE_COUNTRY  |
+                                  Context.SUBSTITUTE_FILENAME |
+                                  Context.SUBSTITUTE_MIMETYPE);
                     if (value != null) {
                         for (final CharSequence substitute : (CharSequence[]) value) {
                             if (CharSequences.equalsIgnoreCase(substitute, "language")) {
-                                mask |= Context.SUBSTITUTE_LANGUAGE;
+                                bitMasks |= Context.SUBSTITUTE_LANGUAGE;
                             } else if (CharSequences.equalsIgnoreCase(substitute, "country"))
{
-                                mask |= Context.SUBSTITUTE_COUNTRY;
+                                bitMasks |= Context.SUBSTITUTE_COUNTRY;
                             } else if (CharSequences.equalsIgnoreCase(substitute, "filename"))
{
-                                mask |= Context.SUBSTITUTE_FILENAME;
+                                bitMasks |= Context.SUBSTITUTE_FILENAME;
                             } else if (CharSequences.equalsIgnoreCase(substitute, "mimetype"))
{
-                                mask |= Context.SUBSTITUTE_MIMETYPE;
+                                bitMasks |= Context.SUBSTITUTE_MIMETYPE;
                             }
                         }
                     }
-                    bitMasks = mask;
                     return;
                 }
                 case XML.WARNING_LISTENER: {
                     warningListener = (WarningListener<?>) value;
                     return;
                 }
+                case LegacyNamespaces.DISABLE_NAMESPACE_REPLACEMENTS: {
+                    bitMasks &= ~Context.DISABLE_NAMESPACE_REPLACEMENTS;
+                    if ((Boolean) value) {
+                        bitMasks |= Context.DISABLE_NAMESPACE_REPLACEMENTS;
+                    }
+                    return;
+                }
             }
         } catch (ClassCastException | IllegalArgumentException e) {
             throw new PropertyException(Errors.format(
@@ -390,6 +402,9 @@ abstract class Pooled {
                 if ((bitMasks & Context.SUBSTITUTE_MIMETYPE) != 0) substitutes[n++] =
"mimetype";
                 return (n != 0) ? ArraysExt.resize(substitutes, n) : null;
             }
+            case LegacyNamespaces.DISABLE_NAMESPACE_REPLACEMENTS: {
+                return (bitMasks & Context.DISABLE_NAMESPACE_REPLACEMENTS) != 0;
+            }
             default: {
                 return getStandardProperty(convertPropertyKey(name));
             }

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=1548015&r1=1548014&r2=1548015&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 05:03:39 2013
@@ -112,8 +112,10 @@ final class PooledMarshaller extends Poo
      */
     private FilterVersion getFilterVersion() {
         final Version gmlVersion = getGMLVersion();
-        if (gmlVersion != null && gmlVersion.compareTo(LegacyNamespaces.VERSION_3_2,
2) < 0) {
-            return FilterVersion.GML31;
+        if (gmlVersion != null && !isFlagSet(Context.DISABLE_NAMESPACE_REPLACEMENTS))
{
+            if (gmlVersion.compareTo(LegacyNamespaces.VERSION_3_2, 2) < 0) {
+                return FilterVersion.GML31;
+            }
         }
         return null;
     }



Mime
View raw message