Author: desruisseaux
Date: Mon Feb 12 22:40:13 2018
New Revision: 1824083
URL: http://svn.apache.org/viewvc?rev=1824083&view=rev
Log:
Prepare for handling of QName localPart renaming during (un)marshalling.
As part of this work, FilteredStreamReader and FilteredStreamResolver
have been merged in a single class, FilteredReader.
Added:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java
- copied, changed from r1824082, sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java
Removed:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java
Modified:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NamespaceContent.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredEvent.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredWriter.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java
sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/MetadataMock.java
sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/FilteredNamespacesTest.java
sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java
Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NamespaceContent.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NamespaceContent.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NamespaceContent.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/xml/NamespaceContent.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -136,7 +136,7 @@ public final class NamespaceContent {
*/
final String topLevelTypeName = root.name();
String classNS = namespace(classe, root.namespace());
- add(classNS, topLevelTypeName, FilteredStreamResolver.TYPE_KEY);
+ add(classNS, topLevelTypeName, FilteredReader.TYPE_KEY);
for (;; classNS = namespace(classe, root.namespace())) {
for (final Method method : classe.getDeclaredMethods()) {
if (!method.isBridge()) {
@@ -170,7 +170,7 @@ public final class NamespaceContent {
}
}
if (singleton != null) {
- add(namespace(classe, singleton.namespace()), singleton.name(), FilteredStreamResolver.TYPE_KEY);
+ add(namespace(classe, singleton.namespace()), singleton.name(), FilteredReader.TYPE_KEY);
}
}
}
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilterVersion.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -19,11 +19,9 @@ package org.apache.sis.xml;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
-import org.apache.sis.util.collection.Containers;
+import javax.xml.namespace.QName;
import org.apache.sis.internal.jaxb.LegacyNamespaces;
-import static java.util.Collections.singletonMap;
-
/**
* The target version of standards for {@link FilteredNamespaces}.
@@ -36,135 +34,252 @@ import static java.util.Collections.sing
* @since 0.4
* @module
*/
-enum FilterVersion {
+final class FilterVersion {
/**
* Metadata using the legacy ISO 19139:2007 schema (replaced by ISO 19115-3).
*/
- ISO19139(new String[] {
- Namespaces.CAT,
- Namespaces.CIT,
- Namespaces.DQC,
- Namespaces.FCC,
- Namespaces.GEX,
- Namespaces.GMW,
- Namespaces.LAN,
- Namespaces.MAC,
- Namespaces.MAS,
- Namespaces.MCC,
- Namespaces.MCO,
- Namespaces.MD1,
- Namespaces.MD2,
- Namespaces.MDA,
- Namespaces.MDB,
- Namespaces.MDQ,
- Namespaces.MDS,
- Namespaces.MDT,
- Namespaces.MEX,
- Namespaces.MMI,
- Namespaces.MPC,
- Namespaces.MRC,
- Namespaces.MRD,
- Namespaces.MRI,
- Namespaces.MRL,
- Namespaces.MRS,
- Namespaces.MSR,
- Namespaces.RCE
- }, LegacyNamespaces.GMD,
- new String[] {
- Namespaces.GCX, LegacyNamespaces.GMX,
- Namespaces.GCO, LegacyNamespaces.GCO,
- Namespaces.SRV, LegacyNamespaces.SRV},
- Collections.singletonMap(LegacyNamespaces.GCO, Namespaces.GCO)),
+ static final FilterVersion ISO19139 = new FilterVersion(42, 2);
+ static {
+ ISO19139.addSurjectives(new String[] {
+ Namespaces.CAT,
+ Namespaces.CIT,
+ Namespaces.DQC,
+ Namespaces.FCC,
+ Namespaces.GEX,
+ Namespaces.GMW,
+ Namespaces.LAN,
+ Namespaces.MAC,
+ Namespaces.MAS,
+ Namespaces.MCC,
+ Namespaces.MCO,
+ Namespaces.MD1,
+ Namespaces.MD2,
+ Namespaces.MDA,
+ Namespaces.MDB,
+ Namespaces.MDQ,
+ Namespaces.MDS,
+ Namespaces.MDT,
+ Namespaces.MEX,
+ Namespaces.MMI,
+ Namespaces.MPC,
+ Namespaces.MRC,
+ Namespaces.MRD,
+ Namespaces.MRI,
+ Namespaces.MRL,
+ Namespaces.MRS,
+ Namespaces.MSR,
+ Namespaces.RCE
+ }, LegacyNamespaces.GMD);
+ /*
+ * SV_OperationMetadata has two properties that are identical except for the name
+ * between ISO 19115-3:2016 and legacy ISO 19139:2007. Instead than complicating
+ * the class with JAXB annotations, we perform the renaming in this package.
+ */
+ Replacement r = new Replacement(LegacyNamespaces.SRV, 4);
+ r.addProperty("distributedComputingPlatform", "DCP");
+ r.addProperty("parameter", "parameters");
+ ISO19139.exports.put(Namespaces.SRV, r);
/*
* For the way back from legacy ISO 19139:2007 to new ISO 19115-3:2016, we must rely on
- * FilteredStreamResolver (do NOT declare entries in 'imports', because some namespaces
- * must be left unchanged). An exception to this rule is the "gco" namespace because
- * FilteredStreamResolver renames only element namespaces while we need to rename also
- * attributes in "gco" namespace (e.g. "gco:nilReason").
+ * FilteredReader (do NOT declare entries in 'imports', because some namespaces must be
+ * left unchanged). An exception to this rule is the "gco" namespace because our reader
+ * renames only element namespaces while we need to rename also attributes in "gco"
+ * namespace (e.g. "gco:nilReason").
*/
+ ISO19139.addSurjective(Namespaces.GCX, LegacyNamespaces.GMX);
+ ISO19139.addBijective (Namespaces.GCO, LegacyNamespaces.GCO);
+ }
/**
* GML using the legacy {@code "http://www.opengis.net/gml"} namespace.
* Note that the use of GML 3.2 may imply the use of ISO 19139:2007,
* which requires the use of {@link #ALL}.
*/
- GML31(Namespaces.GML, LegacyNamespaces.GML),
+ static final FilterVersion GML31 = new FilterVersion(ISO19139);
+ static {
+ GML31.addBijective(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.
*/
- ALL(ISO19139, GML31);
+ static final FilterVersion ALL = GML31;
+
+ /**
+ * The exported namespace used in the XML file instead then the namespaces used by JAXB annotations.
+ * Contains also the properties renamed in that exported namespaces if any.
+ */
+ static final class Replacement {
+ /**
+ * The exported namespace (used in XML document).
+ */
+ final String namespace;
+
+ /**
+ * The properties having a different name in the exported namespace. Keys are property names
+ * as declared in JAXB annotations, and values are property names used in the XML document.
+ */
+ private final Map<String,String> exports;
+
+ /**
+ * Constructs a replacement for a namespace only (no renamed property).
+ */
+ Replacement(final String namespace) {
+ this.namespace = namespace;
+ this.exports = Collections.emptyMap();
+ }
+
+ /**
+ * Constructs a replacement for a namespace, together with the map of properties
+ * that need to be renamed for that exported namespace.
+ */
+ Replacement(final String namespace, final int capacity) {
+ this.namespace = namespace;
+ this.exports = new HashMap<>(capacity);
+ }
+
+ /**
+ * Adds a two-directional association between a property used in JAXB annotation and a property
+ * used in XML document. A bijective association means that the renaming is reversible.
+ */
+ final void addProperty(final String jaxb, final String xml) {
+ exports.put(jaxb, xml);
+ }
+
+ /**
+ * Converts a property name used in JAXB annotations to a property name used in XML document.
+ */
+ final String exportProperty(final String localPart) {
+ return exports.getOrDefault(localPart, localPart);
+ }
+ }
/**
* The URI replacements to apply when going from the model implemented by Apache SIS
* to the filtered reader/writer. Keys are the URIs as declared in JAXB annotations,
* and values are the URIs to write instead of the actual ones.
*
- * @see FilteredNamespaces#exports
+ * <p>This map shall not be modified after construction.
+ * We do not wrap in {@link Collections#unmodifiableMap(Map)} for efficiency.</p>
+ *
+ * @see #exports()
*/
- final Map<String,String> exports;
+ private final Map<String, Replacement> exports;
/**
* The URI replacements to apply when going from the filtered reader/writer to the
* model implemented by Apache SIS. This map is the converse of {@link #exports}.
*
- * @see FilteredNamespaces#imports
+ * <p>This map shall not be modified after construction.
+ * We do not wrap in {@link Collections#unmodifiableMap(Map)} for efficiency.</p>
+ *
+ * @see #imports()
*/
- final Map<String,String> imports;
+ private final Map<String, String> imports;
/**
- * {@code true} if applying {@link #exports} replacements results in many namespaces collapsed into
- * a single namespace. In those case, {@link #imports} is not sufficient for performing the reverse
- * operation; we need {@link FilteredStreamResolver}.
+ * Creates a new enumeration initialized to the given capacity.
+ *
+ * @param ec exports capacity.
+ * @param ic imports capacity.
*/
- final boolean manyToOne;
+ private FilterVersion(final int ec, final int ic) {
+ exports = new HashMap<>(ec);
+ imports = new HashMap<>(ic);
+ }
/**
- * Creates a new enum for replacing only one namespace.
- *
- * @param impl the namespace used in JAXB annotations (should be latest schema).
- * @param view the namespace used in the XML file to (un)marshall (older schema).
+ * Creates an enumeration initialized to a copy of the given enumeration.
+ * This construction should be followed by calls to {@code add(…)} methods.
+ */
+ private FilterVersion(final FilterVersion first) {
+ exports = new HashMap<>(first.exports);
+ imports = new HashMap<>(first.imports);
+ }
+
+ /**
+ * Adds a two-directional association between a namespace used in JAXB annotation and a namespace
+ * used in XML document. A bijective association means that the renaming is reversible.
*/
- private FilterVersion(final String impl, final String view) {
- this.exports = singletonMap(impl, view);
- this.imports = singletonMap(view, impl);
- manyToOne = false;
+ private void addBijective(final String jaxb, final String xml) {
+ exports.put(jaxb, new Replacement(xml));
+ imports.put(xml, jaxb);
}
/**
- * Creates a new enum for replacing many namespaces by a single one.
- * This constructor is used when the legacy schema (the "view") was one large monolithic schema,
- * and the new schema (the "impl") has been separated in many smaller modules.
- *
- * @param impl the namespaces used in JAXB annotations (should be most recent schema).
- * @param view the single namespace used in the XML file to (un)marshall (older schema).
- * @param additional additional (<var>impl</var>, <var>view</var>) mapping for a few namespaces
- * having different {@code view} values.
+ * Adds a one-way association from JAXB namespace to XML namespace. Many JAXB namespaces may map
+ * to the same XML namespace. For example most ISO 19115-3:2016 namespaces map to the same legacy
+ * ISO 19139:2007 namespace. Consequently this association is not easily reversible.
*/
- private FilterVersion(final String[] impl, final String view, final String[] additional,
- final Map<String,String> imports)
- {
- exports = new HashMap<>(Containers.hashMapCapacity(impl.length));
- this.imports = imports;
- for (final String e : impl) {
- exports.put(e, view);
+ private void addSurjective(final String jaxb, final String xml) {
+ exports.put(jaxb, new Replacement(xml));
+ }
+
+ /**
+ * Adds one-way associations from JAXB namespaces to a single XML namespace.
+ * This method is used when the legacy schema (the {@code xml} one) was one large monolithic schema,
+ * and the new schema (represented by {@code jaxb}) has been separated in many smaller modules.
+ */
+ private void addSurjectives(final String[] jaxb, final String xml) {
+ final Replacement r = new Replacement(xml);
+ for (final String e : jaxb) {
+ exports.put(e, r);
}
- for (int i=0; i<additional.length;) {
- exports.put(additional[i++],
- additional[i++]);
+ }
+
+ /**
+ * Returns the name (prefix, namespace and local part) to write in the XML document.
+ * This method may replace the namespace, and in some case the name local part too.
+ * If there is no name change, then this method returns the given instance as-is.
+ */
+ final QName export(QName name) {
+ String uri = name.getNamespaceURI();
+ if (uri != null && !uri.isEmpty()) { // Optimization for a common case.
+ final Replacement r = exports.get(uri);
+ if (r != null) {
+ uri = r.namespace;
+ name = new QName(uri, r.exportProperty(name.getLocalPart()),
+ Namespaces.getPreferredPrefix(uri, name.getPrefix()));
+ }
}
- manyToOne = true;
+ return name;
}
/**
- * Creates the {@link #ALL} enumeration.
+ * Converts a namespace used in JAXB annotation to the namespace used in XML document.
*/
- private FilterVersion(final FilterVersion first, final FilterVersion more) {
- exports = new HashMap<>(first.exports);
- imports = new HashMap<>(first.imports);
- exports.putAll(more.exports);
- imports.putAll(more.imports);
- manyToOne = first.manyToOne | more.manyToOne;
+ final String exportNS(final String uri) {
+ final FilterVersion.Replacement r = exports.get(uri);
+ return (r != null) ? r.namespace : uri;
+ }
+
+ final Replacement export(final String uri) {
+ return exports.get(uri);
+ }
+
+ /**
+ * Converts a namespace used in XML document to the namespace used in JAXB annotation.
+ */
+ final String importNS(final String uri) {
+ return imports.getOrDefault(uri, uri);
+ }
+
+ /**
+ * Returns the URI replacements to apply when going from the model implemented by Apache SIS to the
+ * filtered reader/writer. Used only for more sophisticated work than what {@link #exportNS(String)}
+ * does. Wrapped in a {@link Collections#unmodifiableMap(Map)} for safety.
+ */
+ final Map<String, Replacement> exports() {
+ return Collections.unmodifiableMap(exports);
+ }
+
+ /**
+ * Returns the URI replacements to apply when going from the filtered reader/writer to the model implemented
+ * by Apache SIS. Used only for mor sophisticated work than what {@link #exportNS(String)} does. Wrapped in
+ * a {@link Collections#unmodifiableMap(Map)} for safety.
+ */
+ final Map<String, String> imports() {
+ return Collections.unmodifiableMap(imports);
}
}
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredEvent.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredEvent.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredEvent.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredEvent.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -248,7 +248,7 @@ abstract class FilteredEvent<E extends X
/** Gets a read-only namespace context. */
@Override public NamespaceContext getNamespaceContext() {
final NamespaceContext context = event.getNamespaceContext();
- return (context != null) ? new FilteredNamespaces(context, version, false) : null;
+ return (context != null) ? new FilteredNamespaces(context, version) : null;
}
/** Gets the value that the prefix is bound to in the context of this element. */
@@ -256,7 +256,7 @@ abstract class FilteredEvent<E extends X
final NamespaceContext context = event.getNamespaceContext();
if (context != null) {
final String uri = context.getNamespaceURI(prefix);
- return version.exports.getOrDefault(uri, uri);
+ return version.exportNS(uri);
}
return null;
}
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -20,12 +20,13 @@ import java.util.Map;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.xml.namespace.NamespaceContext;
+import javax.xml.XMLConstants;
/**
- * 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 FilteredWriter} only.
- * Current {@code FilteredNamespaces} implementation takes care of XML prefixes only;
+ * In the associations between prefixes and namespaces, substitutes the namespaces used in JAXB annotations by the
+ * namespaces used in the XML document at marshalling time. This class is used internally by {@link FilteredReader}
+ * and {@link FilteredWriter} only. Current {@code FilteredNamespaces} implementation takes care of XML prefixes only;
* the stream reader and writer do the rest of the work.
*
* <div class="section">The problem</div>
@@ -41,9 +42,8 @@ import javax.xml.namespace.NamespaceCont
* <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>
+ * SIS corners, 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>
@@ -55,60 +55,98 @@ import javax.xml.namespace.NamespaceCont
* as "micro-transformers".
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.4
+ * @version 1.0
*
* @see <a href="http://issues.apache.org/jira/browse/SIS-152">SIS-152</a>
*
* @since 0.4
* @module
*/
-final class FilteredNamespaces implements NamespaceContext {
+class FilteredNamespaces implements NamespaceContext {
/**
- * The context to wrap, given by {@link FilteredStreamReader} or {@link FilteredWriter}.
+ * The context to wrap, given by {@link FilteredReader} or {@link FilteredWriter}.
*
* @see javax.xml.stream.XMLStreamReader#getNamespaceContext()
* @see javax.xml.stream.XMLStreamWriter#getNamespaceContext()
*/
- private final NamespaceContext context;
+ final NamespaceContext context;
/**
- * The URI replacements to apply when going from the wrapped context to the filtered context.
- *
- * @see FilterVersion#exports
+ * The URI replacements to apply when exporting from the JAXB annotations to the XML documents.
*/
- private final Map<String,String> exports;
+ final FilterVersion version;
/**
- * The URI replacements to apply when going from the filtered context to the wrapped context.
- * This map is the converse of {@link #exports}.
- *
- * @see FilterVersion#imports
+ * Creates a new namespaces filter for the given target version.
*/
- private final Map<String,String> imports;
+ FilteredNamespaces(final NamespaceContext context, final FilterVersion version) {
+ this.context = context;
+ this.version = version;
+ }
/**
- * Creates a new namespaces filter for the given target version.
+ * Returns the inverse of {@code FilteredNamespaces}.
*/
- FilteredNamespaces(final NamespaceContext context, final FilterVersion version, final boolean inverse) {
- this.context = context;
- if (!inverse) {
- exports = version.exports;
- imports = version.imports;
- } else {
- exports = version.imports;
- imports = version.exports;
- }
+ NamespaceContext inverse(final FilterVersion target) {
+ return (version == target) ? context : new Import(context, target);
}
/**
- * Wraps this {@code FilteredNamespaces} in a new instance performing the inverse of the replacements
- * specified by the given version.
+ * Substitutes the XML namespaces used in XML documents by namespaces used in JAXB annotations.
+ * This is used at unmarshalling time for importing legacy documents.
*/
- NamespaceContext inverse(final FilterVersion version) {
- if (exports == version.exports && imports == version.imports) {
- return this;
+ static final class Import extends FilteredNamespaces {
+ /**
+ * Creates a new namespaces filter for the given source version.
+ */
+ Import(final NamespaceContext context, final FilterVersion version) {
+ super(context, version);
+ }
+
+ /**
+ * Returns the inverse of this namespace.
+ */
+ @Override NamespaceContext inverse(final FilterVersion target) {
+ return (version == target) ? context : new FilteredNamespaces(context, target);
+ }
+
+ /**
+ * Returns the namespace used in JAXB annotations for the given prefix in XML document.
+ * If no unique namespace can be mapped (for example if asking the namespace of legacy
+ * {@code "gmd"} prefix), returns {@link XMLConstants#NULL_NS_URI}.
+ *
+ * <p>Except for {@code NULL_NS_URI}, this is usually an <cite>injective</cite> function:
+ * each namespace can be created from at most one prefix.</p>
+ */
+ @Override public String getNamespaceURI(final String prefix) {
+ return version.importNS(context.getNamespaceURI(prefix));
+ }
+
+ /**
+ * Returns an arbitrary prefix for the given namespace. For example given the
+ * {@code "http://standards.iso.org/iso/19115/-3/mdb/1.0"} namespace from ISO 19115-3,
+ * this method returns {@code "gmd"} which was the prefix used in legacy ISO 19139:2007.
+ *
+ * <p>This is a <cite>surjective</cite> function:
+ * many prefixes can be created from the same namespace.</p>
+ */
+ @Override
+ public String getPrefix(final String namespaceURI) {
+ return context.getPrefix(version.exportNS(namespaceURI));
+ }
+
+ /**
+ * Returns all prefixes for the given namespace. There is usually only one, contrarily
+ * to {@link FilteredNamespaces#getPrefixes(String)} which have many.
+ *
+ * <p>This is a <cite>surjective</cite> function:
+ * many prefixes can be created from the same namespace.</p>
+ */
+ @Override
+ @SuppressWarnings("unchecked") // TODO: remove with JDK9
+ public Iterator<String> getPrefixes(final String namespaceURI) {
+ return context.getPrefixes(version.exportNS(namespaceURI));
}
- return new FilteredNamespaces(this, version, true);
}
/**
@@ -119,8 +157,7 @@ final class FilteredNamespaces implement
*/
@Override
public String getNamespaceURI(final String prefix) {
- final String uri = context.getNamespaceURI(prefix);
- return exports.getOrDefault(uri, uri);
+ return version.exportNS(context.getNamespaceURI(prefix));
}
/**
@@ -129,19 +166,16 @@ final class FilteredNamespaces implement
*/
@Override
public String getPrefix(final String namespaceURI) {
- final String ns = imports.get(namespaceURI);
- if (ns != null) {
- final String p = context.getPrefix(ns);
- if (p != null) return p;
- }
+ String p = context.getPrefix(version.importNS(namespaceURI));
+ if (p != null) return p;
/*
* We can not use the 'imports' map when the same namespace (e.g. "http://www.isotc211.org/2005/gmd" from
* legacy ISO 19139:2007) is mapped to multiple namespaces in the new ISO 19115-3:2016 or other standard.
- * In such case, we have to iterate over map 'exports' entries until we find an inverse mapping.
+ * In such case, we have to iterate over 'exports' entries until we find an inverse mapping.
*/
- for (final Map.Entry<String,String> e : exports.entrySet()) {
- if (namespaceURI.equals(e.getValue())) {
- final String p = context.getPrefix(e.getKey());
+ for (final Map.Entry<String, FilterVersion.Replacement> e : version.exports().entrySet()) {
+ if (namespaceURI.equals(e.getValue().namespace)) {
+ p = context.getPrefix(e.getKey());
if (p != null) return p;
}
}
@@ -155,7 +189,7 @@ final class FilteredNamespaces implement
*/
@Override
public Iterator<String> getPrefixes(final String namespaceURI) {
- return new Prefixes(context, exports, namespaceURI);
+ return new Prefixes(context, version.exports(), namespaceURI);
}
/**
@@ -169,8 +203,8 @@ final class FilteredNamespaces implement
/** The {@link FilteredNamespaces#context} reference. */
private final NamespaceContext context;
- /** Iterator over the {@link FilteredNamespaces#exports} entries. */
- private final Iterator<Map.Entry<String,String>> exports;
+ /** Iterator over the namespace replacements. */
+ private final Iterator<Map.Entry<String, FilterVersion.Replacement>> exports;
/** Iterator over some (not all) prefixes, or {@code null} if a new iterator needs to be fetched. */
private Iterator<String> prefixes;
@@ -179,7 +213,7 @@ final class FilteredNamespaces implement
private String next;
/** Creates a new iterator for the prefixes associated to the given namespace URI. */
- Prefixes(final NamespaceContext context, final Map<String,String> exports, final String namespaceURI) {
+ Prefixes(final NamespaceContext context, final Map<String, FilterVersion.Replacement> exports, final String namespaceURI) {
this.context = context;
this.exports = exports.entrySet().iterator();
this.namespaceURI = namespaceURI;
@@ -197,8 +231,8 @@ final class FilteredNamespaces implement
if (!exports.hasNext()) {
return false;
}
- final Map.Entry<String,String> e = exports.next();
- if (namespaceURI.equals(e.getValue())) {
+ final Map.Entry<String, FilterVersion.Replacement> e = exports.next();
+ if (namespaceURI.equals(e.getValue().namespace)) {
prefixes = context.getPrefixes(e.getKey());
}
}
Copied: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java (from r1824082, sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java)
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java?p2=sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java&p1=sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java&r1=1824082&r2=1824083&rev=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -27,18 +27,22 @@ import java.io.LineNumberReader;
import java.io.InputStreamReader;
import java.util.InvalidPropertiesFormatException;
import javax.xml.namespace.QName;
+import javax.xml.namespace.NamespaceContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
import org.apache.sis.util.CharSequences;
import org.apache.sis.util.resources.Errors;
import org.apache.sis.internal.util.CollectionsExt;
/**
- * A {@code StreamReader} which uses a more complex algorithm backed by a dictionary for identifying the XML namespaces
- * expected by JAXB implementation. This is used when a single namespace in a legacy schema has been splitted into many
- * namespaces in a newer schema. This happen for example in the upgrade from ISO 19139:2007 to ISO 19115-3. In such cases,
- * we need to check which attribute is being mapped in order to determine the new namespace.
+ * A filter replacing the namespaces found in XML documents by the namespaces expected by SIS at unmarshalling time.
+ * This class forwards every method calls to the wrapped {@link XMLStreamReader}, but with some {@code namespaceURI}
+ * modified before being transfered. This class uses a dictionary for identifying the XML namespaces expected by JAXB
+ * implementation. This is needed when a single namespace in a legacy schema has been splitted into many namespaces
+ * in the newer schema. This happen for example in the upgrade from ISO 19139:2007 to ISO 19115-3.
+ * In such cases, we need to check which attribute is being mapped in order to determine the new namespace.
*
* @author Cullen Rombach (Image Matters)
* @author Martin Desruisseaux (Geomatys)
@@ -46,7 +50,7 @@ import org.apache.sis.internal.util.Coll
* @since 1.0
* @module
*/
-final class FilteredStreamResolver extends FilteredStreamReader {
+final class FilteredReader extends StreamReaderDelegate {
/**
* Location of the file listing types and attributes contained in namespaces.
* The file location is relative to this {@code NamespaceContent} class.
@@ -71,13 +75,34 @@ final class FilteredStreamResolver exten
static final String TYPE_KEY = "<type>";
/**
+ * Character used for separating a old name for the new name. For example in {@code SV_OperationMetadata},
+ * {@code "DCP"} in ISO 19139:2007 has been renamed {@code "distributedComputingPlatform"} in ISO 19115-3.
+ * This is encoded in {@value #FILENAME} file as {@code "DCP/distributedComputingPlatform"}.
+ */
+ private static final char RENAME_SEPARATOR = '/';
+
+ /**
+ * Returns {@code true} if the given string is a namespace URI, or {@code false} if it is a property name.
+ * This method implements a very fast check based on the presence of {@code ':'} in {@code "http://foo.bar"}.
+ * It assumes that all namespaces declared in the {@value #FILENAME} file use the {@code "http"} protocol and
+ * no property name use the {@code ':'} character.
+ */
+ private static boolean isNamespace(final String candidate) {
+ return (candidate.length() > 4) && (candidate.charAt(4) == ':');
+ }
+
+ /**
* The mapping from (<var>type</var>, <var>attribute</var>) pairs to namespaces.
*
* <ul>
* <li>Keys are XML names of types (e.g. {@code "CI_Citation"})</li>
* <li>Values are maps where:<ul>
* <li>Keys are XML names of attributes (e.g. {@code "title"}) or {@value #TYPE_KEY}</li>
- * <li>Values are namespace URI</li>
+ * <li>Values are either:<ul>
+ * <li>Namespace URI if {@link #isNamespace(String)} returns {@code true} for that value.</li>
+ * <li>New name of the element otherwise. In such case, the map must be queried again with
+ * that new name for obtaining the namespace.</li>
+ * </ul></li>
* </ul></li>
* </ul>
*
@@ -88,35 +113,42 @@ final class FilteredStreamResolver exten
static {
final Map<String, Map<String,String>> m = new HashMap<>(250);
try (LineNumberReader in = new LineNumberReader(new InputStreamReader(
- FilteredStreamResolver.class.getResourceAsStream(FILENAME), "UTF-8")))
+ FilteredReader.class.getResourceAsStream(FILENAME), "UTF-8")))
{
- Map<String,String> attributes = null; // All attributes for a given type.
- String namespace = null; // Value to store in 'attributes' map.
+ Map<String,String> attributes = null; // All attributes for a given type.
+ String namespace = null; // Value to store in 'attributes' map.
String line;
while ((line = in.readLine()) != null) {
final int length = line.length();
final int start = CharSequences.skipLeadingWhitespaces(line, 0, length);
if (start < length && line.charAt(start) != '#') {
- final String element = line.substring(start).trim().intern();
+ String element = line.substring(start).trim();
switch (start) {
- case 0: { // New namespace URI.
- namespace = element;
+ case 0: { // New namespace URI.
+ if (!isNamespace(element)) break; // Report illegal format.
+ namespace = element.intern();
attributes = null;
continue;
}
- case 2: { // New type in above namespace URI.
- attributes = m.computeIfAbsent(element, (k) -> new HashMap<>());
+ case 2: { // New type in above namespace URI.
+ attributes = m.computeIfAbsent(element.intern(), (k) -> new HashMap<>());
continue;
}
- case 4: { // New attribute in above type.
- if (attributes != null && namespace != null) {
- attributes.put(element, namespace);
- continue;
+ case 4: { // New attribute in above type.
+ if (attributes == null || namespace == null) break; // Report illegal format.
+ final int s = element.indexOf(RENAME_SEPARATOR);
+ if (s >= 0) {
+ final String old = element.substring(0, s).trim().intern();
+ element = element.substring(s+1).trim().intern();
+ attributes.put(old, element);
+ } else {
+ element = element.intern();
}
- // Fall through for reporting illegal format.
+ attributes.put(element, namespace);
+ continue;
}
}
- throw new InvalidPropertiesFormatException(Errors.format( // See FILE javadoc.
+ throw new InvalidPropertiesFormatException(Errors.format( // See FILE javadoc.
Errors.Keys.ErrorInFileAtLine_2, FILENAME, in.getLineNumber()));
}
}
@@ -134,13 +166,16 @@ final class FilteredStreamResolver exten
/**
* The mapping from attribute names to types where such attribute is declared.
* An attribute of the same name may be declared in many types.
+ *
+ * <p>This method does not look at namespaces. Consequently the renaming encoding
+ * (e.g. {@code "DCP/distributedComputingPlatform"}) is not of concern here.</p>
*/
private static final Map<String, Set<String>> DECLARING_TYPES;
static {
final Map<String, Set<String>> m = new HashMap<>(500);
- for (final Map.Entry<String, Map<String,String>> e : NAMESPACES.entrySet()) {
- final String type = e.getKey();
- for (final String attribute : e.getValue().keySet()) {
+ for (final Map.Entry<String, Map<String,String>> forTypes : NAMESPACES.entrySet()) {
+ final String type = forTypes.getKey();
+ for (final String attribute : forTypes.getValue().keySet()) {
m.computeIfAbsent(attribute, (k) -> new HashSet<>()).add(type);
}
}
@@ -159,6 +194,11 @@ final class FilteredStreamResolver exten
}
/**
+ * The external XML format version to unmarshal from.
+ */
+ private final FilterVersion version;
+
+ /**
* List of encountered XML tags, in order. Used for backtracking.
* Elements are removed from this list when they are closed.
*/
@@ -167,8 +207,9 @@ final class FilteredStreamResolver exten
/**
* Creates a new filter for the given version of the standards.
*/
- FilteredStreamResolver(final XMLStreamReader in, final FilterVersion version) {
- super(in, version);
+ FilteredReader(final XMLStreamReader in, final FilterVersion version) {
+ super(in);
+ this.version = version;
outerElements = new ArrayList<>();
}
@@ -221,6 +262,7 @@ final class FilteredStreamResolver exten
/**
* Returns the namespace of the given ISO type, or {@code null} if unknown.
+ * This is the namespace used in JAXB annotations.
*
* @param type a class name defined by ISO 19115 or related standards (e.g. {@code "CI_Citation"}.
* @return a namespace for the given type, or {@code null} if unknown.
@@ -271,13 +313,12 @@ final class FilteredStreamResolver exten
* Converts a name read from the XML document to the name to give to JAXB.
* The new namespace depends on both the old namespace and the element name.
*/
- @Override
- final QName importNS(QName name) {
+ private QName importNS(QName name) {
final String namespaceURI = name.getNamespaceURI();
final String localPart = name.getLocalPart();
String replacement = namespaceOf(localPart);
if (replacement == null) {
- replacement = importNS(namespaceURI);
+ replacement = version.importNS(namespaceURI);
}
if (!replacement.equals(namespaceURI)) {
name = new QName(replacement, localPart, name.getPrefix());
@@ -285,6 +326,30 @@ final class FilteredStreamResolver exten
return name;
}
+ /** Replaces the given URI if needed, then forwards the call. */
+ @Override
+ public void require(final int type, final String namespaceURI, final String localName) throws XMLStreamException {
+ super.require(type, version.exportNS(namespaceURI), localName);
+ }
+
+ /** Returns the context of the underlying reader wrapped in a filter that converts the namespaces on the fly. */
+ @Override
+ public NamespaceContext getNamespaceContext() {
+ return new FilteredNamespaces.Import(super.getNamespaceContext(), version);
+ }
+
+ /** Forwards the call, then replaces the namespace URI if needed. */
+ @Override
+ public QName getName() {
+ return importNS(super.getName());
+ }
+
+ /** Forwards the call, then replaces the namespace URI if needed. */
+ @Override
+ public QName getAttributeName(final int index) {
+ return importNS(super.getAttributeName(index));
+ }
+
/**
* Returns the namespace of current element, after replacement by the URI used by SIS.
* This replacement depends on the current local name in addition of current namespace.
@@ -293,8 +358,37 @@ final class FilteredStreamResolver exten
public String getNamespaceURI() {
String namespace = namespaceOf(getLocalName());
if (namespace == null) {
- namespace = super.getNamespaceURI();
+ namespace = version.importNS(super.getNamespaceURI());
}
return namespace;
}
+
+ /**
+ * Forwards the call, then replaces the returned URI if needed.
+ *
+ * <b>Note:</b> the index passed to this method is the index of a namespace declaration on the root element.
+ * This should not matter as long as each <em>element</em> has the proper namespace URI.
+ */
+ @Override
+ public String getNamespaceURI(int index) {
+ return version.importNS(super.getNamespaceURI(index));
+ }
+
+ /** Forwards the call, then replaces the returned URI if needed. */
+ @Override
+ public String getNamespaceURI(final String prefix) {
+ return version.importNS(super.getNamespaceURI(prefix));
+ }
+
+ /** Forwards the call, then replaces the returned URI if needed. */
+ @Override
+ public String getAttributeNamespace(final int index) {
+ return version.importNS(super.getAttributeNamespace(index));
+ }
+
+ /** Replaces the given URI if needed, then forwards the call. */
+ @Override
+ public String getAttributeValue(final String namespaceUri, final String localName) {
+ return super.getAttributeValue(version.exportNS(namespaceUri), localName);
+ }
}
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredWriter.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredWriter.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredWriter.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -90,35 +90,12 @@ final class FilteredWriter implements XM
}
/**
- * Returns the URI to write in the XML document.
- * If there is no namespace change, then this method returns the given instance as-is.
- */
- private String exportNS(final String uri) {
- return version.exports.getOrDefault(uri, uri);
- }
-
- /**
- * Returns the name (prefix, namespace and local part) to write in the XML document.
- * If there is no name change, then this method returns the given instance as-is.
- */
- private QName export(QName name) {
- String uri = name.getNamespaceURI();
- if (uri != null && !uri.isEmpty()) { // Optimization for a common case.
- uri = version.exports.get(uri);
- if (uri != null) {
- name = new QName(uri, name.getLocalPart(), Namespaces.getPreferredPrefix(uri, name.getPrefix()));
- }
- }
- return name;
- }
-
- /**
* Returns the attribute to write in the XML document.
* If there is no name change, then this method returns the given instance as-is.
*/
private Attribute export(Attribute attribute) {
final QName originalName = attribute.getName();
- final QName name = export(originalName);
+ final QName name = version.export(originalName);
if (name != originalName) {
attribute = new FilteredEvent.Attr(attribute, name);
}
@@ -140,8 +117,8 @@ final class FilteredWriter implements XM
if (uri.charAt(end) == '/') {
uri = uri.substring(0, end); // Trim trailing '/' in URI.
}
- final String exported = version.exports.get(uri);
- if (exported != null) {
+ final String exported = version.exportNS(uri);
+ if (exported != uri) {
return uniqueNamespaces.computeIfAbsent(exported, (k) -> {
return new FilteredEvent.NS(namespace, Namespaces.getPreferredPrefix(k, namespace.getPrefix()), k);
});
@@ -205,7 +182,7 @@ final class FilteredWriter implements XM
uniqueNamespaces.clear(); // Discard entries created by NAMESPACE events.
final StartElement e = event.asStartElement();
final QName originalName = e.getName();
- final QName name = export(originalName);
+ final QName name = version.export(originalName);
boolean changed = name != originalName;
for (final Iterator<Attribute> it = e.getAttributes(); it.hasNext();) {
final Attribute a = it.next();
@@ -232,7 +209,7 @@ final class FilteredWriter implements XM
case END_ELEMENT: {
final EndElement e = event.asEndElement();
final QName originalName = e.getName();
- final QName name = export(originalName);
+ final QName name = version.export(originalName);
final List<Namespace> namespaces = export(e.getNamespaces(), name != originalName);
if (namespaces != null) {
event = new FilteredEvent.End(e, name, namespaces);
@@ -276,7 +253,7 @@ final class FilteredWriter implements XM
*/
@Override
public void setPrefix(final String prefix, final String uri) throws XMLStreamException {
- out.setPrefix(prefix, exportNS(uri));
+ out.setPrefix(prefix, version.exportNS(uri));
}
/**
@@ -288,7 +265,7 @@ final class FilteredWriter implements XM
*/
@Override
public void setDefaultNamespace(final String uri) throws XMLStreamException {
- out.setDefaultNamespace(exportNS(uri));
+ out.setDefaultNamespace(version.exportNS(uri));
}
/**
@@ -302,7 +279,7 @@ final class FilteredWriter implements XM
if (context instanceof FilteredNamespaces) {
context = ((FilteredNamespaces) context).inverse(version);
} else {
- context = new FilteredNamespaces(context, version, true);
+ context = new FilteredNamespaces.Import(context, version);
}
out.setNamespaceContext(context);
}
@@ -312,7 +289,7 @@ final class FilteredWriter implements XM
*/
@Override
public NamespaceContext getNamespaceContext() {
- return new FilteredNamespaces(out.getNamespaceContext(), version, false);
+ return new FilteredNamespaces(out.getNamespaceContext(), version);
}
/**
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/Namespaces.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -632,8 +632,8 @@ public final class Namespaces extends St
*/
public static String guessForType(final String type) {
/*
- * Implementation note: we could invoke FilteredStreamResolver.namespace(type) unconditionally,
- * but that method may be removed in a future SIS version if we replace FilteredStreamResolver
+ * Implementation note: we could invoke FilteredReader.namespace(type) unconditionally,
+ * but that method may be removed in a future SIS version if we replace FilteredReader
* by XSD (https://issues.apache.org/jira/projects/SIS/issues/SIS-381). By using a switch now,
* we reduce the behavioral change is SIS-381 is applied. It can also reduce classes loading.
*/
@@ -647,7 +647,7 @@ public final class Namespaces extends St
case ('L' << Character.SIZE) | 'I': return MRL;
case ('D' << Character.SIZE) | 'S': // Usually MDA except for DS_InitiativeTypeCode
case ('M' << Character.SIZE) | 'D':
- case ('M' << Character.SIZE) | 'I': return FilteredStreamResolver.namespace(type);
+ case ('M' << Character.SIZE) | 'I': return FilteredReader.namespace(type);
case ('M' << Character.SIZE) | 'X': return MDT;
case ('P' << Character.SIZE) | 'T': return LAN;
case ('S' << Character.SIZE) | 'V': return SRV;
@@ -657,7 +657,7 @@ public final class Namespaces extends St
}
} else {
// Needs to handle at least DCPList
- return FilteredStreamResolver.namespace(type);
+ return FilteredReader.namespace(type);
}
}
return null;
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/PooledUnmarshaller.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -50,7 +50,7 @@ import org.apache.sis.internal.jaxb.Cont
* when the unmarshaller is recycled.</li>
* <li>Constructs a SIS {@link Context} object on unmarshalling, in order to give
* additional information to the SIS object being unmarshalled.</li>
- * <li>Wraps the input stream in a {@link FilteredStreamReader} if the document GML version
+ * <li>Wraps the input stream in a {@link FilteredReader} if the document GML version
* in not the SIS native GML version.</li>
* </ul>
*
@@ -120,7 +120,7 @@ final class PooledUnmarshaller extends P
private Object unmarshal(XMLStreamReader input, final FilterVersion version)
throws XMLStreamException, JAXBException
{
- input = FilteredStreamReader.create(input, version);
+ input = new FilteredReader(input, version);
final Context context = begin();
final Object object;
try {
@@ -139,7 +139,7 @@ final class PooledUnmarshaller extends P
private <T> JAXBElement<T> unmarshal(XMLStreamReader input, final FilterVersion version, final Class<T> declaredType)
throws XMLStreamException, JAXBException
{
- input = FilteredStreamReader.create(input, version);
+ input = new FilteredReader(input, version);
final Context context = begin();
final JAXBElement<T> object;
try {
@@ -342,7 +342,7 @@ final class PooledUnmarshaller extends P
public Object unmarshal(XMLStreamReader input) throws JAXBException {
final FilterVersion version = getFilterVersion();
if (version != null) {
- input = FilteredStreamReader.create(input, version);
+ input = new FilteredReader(input, version);
}
final Context context = begin();
try {
@@ -359,7 +359,7 @@ final class PooledUnmarshaller extends P
public <T> JAXBElement<T> unmarshal(XMLStreamReader input, final Class<T> declaredType) throws JAXBException {
final FilterVersion version = getFilterVersion();
if (version != null) {
- input = FilteredStreamReader.create(input, version);
+ input = new FilteredReader(input, version);
}
final Context context = begin();
try {
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/MetadataMock.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/MetadataMock.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/MetadataMock.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/MetadataMock.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -42,8 +42,7 @@ import org.apache.sis.xml.Namespaces;
@XmlRootElement(name = "MD_Metadata", namespace = Namespaces.MDB)
final strictfp class MetadataMock extends SimpleMetadata {
/**
- * The language used for documenting metadata. The namespace should be {@code "gmd"},
- * but we use the newer namespace because of the way {@code FilteredStreamResolver} work.
+ * The language used for documenting metadata.
*/
@XmlElement(namespace = LegacyNamespaces.GMD)
@XmlJavaTypeAdapter(LocaleAdapter.class)
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/FilteredNamespacesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/FilteredNamespacesTest.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/FilteredNamespacesTest.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/FilteredNamespacesTest.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -51,7 +51,7 @@ public final strictfp class FilteredName
*/
@Test
public void testGetPrefixes() {
- final FilteredNamespaces fns = new FilteredNamespaces(this, FilterVersion.ISO19139, false);
+ final FilteredNamespaces fns = new FilteredNamespaces(this, FilterVersion.ISO19139);
final Iterator<String> it = fns.getPrefixes(LegacyNamespaces.GMD);
final Set<String> prefixes = new HashSet<>();
while (it.hasNext()) {
@@ -91,7 +91,7 @@ public final strictfp class FilteredName
*/
@Test
public void testGetPrefix() {
- final FilteredNamespaces fns = new FilteredNamespaces(this, FilterVersion.ISO19139, false);
+ final FilteredNamespaces fns = new FilteredNamespaces(this, FilterVersion.ISO19139);
/*
* Following tests are not really interesting since FilteredNamespaces,
* after failing to find a mapping, just delegates to this.getPrefix(…).
Modified: sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java?rev=1824083&r1=1824082&r2=1824083&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java [UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/test/java/org/apache/sis/xml/NamespacesTest.java [UTF-8] Mon Feb 12 22:40:13 2018
@@ -45,7 +45,7 @@ public final strictfp class NamespacesTe
/**
* Tests {@link Namespaces#guessForType(String)}. This method uses {@code assertSame(…)} instead than
- * {@code assertEquals(…)} for verifying that {@link FilteredStreamResolver} invoked {@link String#intern()}.
+ * {@code assertEquals(…)} for verifying that {@link FilteredReader} invoked {@link String#intern()}.
*/
@Test
public void testGuessForType() {
|