You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/12/06 20:38:50 UTC
svn commit: r1548693 - in
/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis:
internal/jaxb/Context.java internal/jaxb/LegacyNamespaces.java
xml/FilterVersion.java xml/Pooled.java
Author: desruisseaux
Date: Fri Dec 6 19:38:49 2013
New Revision: 1548693
URL: http://svn.apache.org/r1548693
Log:
Modified the semantic of APPLY_NAMESPACES_REPLACEMENTS property:
if the boolean value is present, force or disable replacements.
Modified:
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/Pooled.java
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=1548693&r1=1548692&r2=1548693&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] Fri Dec 6 19:38:49 2013
@@ -85,13 +85,6 @@ 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=1548693&r1=1548692&r2=1548693&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] Fri Dec 6 19:38:49 2013
@@ -53,9 +53,24 @@ 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}.
+ * A non-public (un)marshaller property for controlling usage of {@link org.apache.sis.xml.FilteredNamespaces}.
+ * Values can be:
+ *
+ * <ul>
+ * <li>{@link Boolean#FALSE} for disabling namespace replacements. XML (un)marshalling will use the namespaces URI
+ * supported natively by SIS as declared in JAXB annotations. This is sometime useful for debugging purpose.</li>
+ * <li>{@link Boolean#TRUE} for forcing namespace replacements at unmarshalling time. This is useful for reading a
+ * XML document of unknown GML version.</li>
+ * <li>{@code null} or missing for the default behavior, which is apply namespace replacements only if the
+ * {@link org.apache.sis.xml.XML#GML_VERSION} property is set to an older value than the one supported
+ * natively by SIS.</li>
+ * </ul>
+ *
+ * This property can be given to {@link org.apache.sis.xml.MarshallerPool} constructor, or set directly on a
+ * {@code Marshaller} or {@link code Unmarshaller} instance created by {@code MarshallerPool} by invoking its
+ * {@code setProperty(String, Object)} method.
*/
- public static final String DISABLE_NAMESPACE_REPLACEMENTS = "org.apache.sis.xml.disableNamespaceReplacements";
+ public static final String APPLY_NAMESPACE_REPLACEMENTS = "org.apache.sis.xml.applyNamespaceReplacements";
/**
* Do not allow instantiation of this class.
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=1548693&r1=1548692&r2=1548693&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] Fri Dec 6 19:38:49 2013
@@ -39,6 +39,12 @@ enum FilterVersion {
GML31(Namespaces.GML, LegacyNamespaces.GML);
/**
+ * Apply all known namespace replacements. This can be used only at unmarshalling time,
+ * for replacing all namespaces by the namespaces declared in Apache SIS JAXB annotations.
+ */
+ static FilterVersion ALL = GML31;
+
+ /**
* The URI replacements to apply when going from the "real" data producer (JAXB marshaller)
* to the filtered reader/writer. Keys are the actual URIs as declared in SIS implementation,
* and values are the URIs read or to write instead of the actual ones.
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=1548693&r1=1548692&r2=1548693&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/Pooled.java [UTF-8] Fri Dec 6 19:38:49 2013
@@ -119,6 +119,22 @@ abstract class Pooled {
private Map<String,String> schemas;
/**
+ * Whether {@link FilteredNamespaces} shall be used of not. Values can be:
+ *
+ * <ul>
+ * <li>0 for the default behavior, which is apply namespace replacements only if the {@link XML#GML_VERSION}
+ * property is set to an older value than the one supported natively by SIS.</li>
+ * <li>1 for forcing namespace replacements at unmarshalling time. This is useful for reading a XML document
+ * of unknown GML version.</li>
+ * <li>2 for disabling namespace replacements. XML (un)marshalling will use the namespaces URI supported
+ * natively by SIS as declared in JAXB annotations. This is sometime useful for debugging purpose.</li>
+ * </ul>
+ *
+ * @see LegacyNamespaces#APPLY_NAMESPACE_REPLACEMENTS
+ */
+ private byte applyNamespaceReplacements;
+
+ /**
* The GML version to be marshalled or unmarshalled, or {@code null} if unspecified.
* If null, then the latest version is assumed.
*
@@ -238,10 +254,24 @@ abstract class Pooled {
* @see FilteredNamespaces
*/
final FilterVersion getFilterVersion() {
- if (gmlVersion != null && (bitMasks & Context.DISABLE_NAMESPACE_REPLACEMENTS) == 0) {
- if (gmlVersion.compareTo(LegacyNamespaces.VERSION_3_2, 2) < 0) {
- return FilterVersion.GML31;
+ switch (applyNamespaceReplacements) {
+ case 0: {
+ // Apply namespace replacements only for older versions than the one supported natively by SIS.
+ if (gmlVersion != null) {
+ if (gmlVersion.compareTo(LegacyNamespaces.VERSION_3_2, 2) < 0) {
+ return FilterVersion.GML31;
+ }
+ }
+ break;
+ }
+ case 1: {
+ // Force namespace replacements at unmarshalling time (illegal for marshalling).
+ if ((bitMasks & Context.MARSHALLING) == 0) {
+ return FilterVersion.ALL;
+ }
+ break;
}
+ // case 2: disable namespace replacements.
}
return null;
}
@@ -358,10 +388,10 @@ abstract class Pooled {
warningListener = (WarningListener<?>) value;
return;
}
- case LegacyNamespaces.DISABLE_NAMESPACE_REPLACEMENTS: {
- bitMasks &= ~Context.DISABLE_NAMESPACE_REPLACEMENTS;
- if ((Boolean) value) {
- bitMasks |= Context.DISABLE_NAMESPACE_REPLACEMENTS;
+ case LegacyNamespaces.APPLY_NAMESPACE_REPLACEMENTS: {
+ applyNamespaceReplacements = 0;
+ if (value != null) {
+ applyNamespaceReplacements = ((Boolean) value) ? (byte) 1 : (byte) 2;
}
return;
}
@@ -405,8 +435,12 @@ 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;
+ case LegacyNamespaces.APPLY_NAMESPACE_REPLACEMENTS: {
+ switch (applyNamespaceReplacements) {
+ case 1: return Boolean.TRUE;
+ case 2: return Boolean.FALSE;
+ default: return null;
+ }
}
default: {
return getStandardProperty(convertPropertyKey(name));