sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1823774 - in /sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml: FilterVersion.java FilteredEvent.java FilteredNamespaces.java FilteredStreamReader.java FilteredStreamResolver.java FilteredWriter.java
Date Sat, 10 Feb 2018 14:16:10 GMT
Author: desruisseaux
Date: Sat Feb 10 14:16:09 2018
New Revision: 1823774

URL: http://svn.apache.org/viewvc?rev=1823774&view=rev
Log:
Rename some private fields and methods with less confusing names.

Modified:
    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/FilteredStreamReader.java
    sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamResolver.java
    sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredWriter.java

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=1823774&r1=1823773&r2=1823774&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] Sat Feb 10 14:16:09 2018
@@ -77,7 +77,7 @@ enum FilterVersion {
         Collections.singletonMap(LegacyNamespaces.GCO, Namespaces.GCO)),
         /*
          * 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 'toImpl', because some namespaces
+         * 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").
@@ -101,21 +101,21 @@ enum FilterVersion {
      * 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.
      *
-     * @see FilteredNamespaces#toView
+     * @see FilteredNamespaces#exports
      */
-    final Map<String,String> toView;
+    final Map<String,String> exports;
 
     /**
      * The URI replacements to apply when going from the filtered reader/writer to the "real"
-     * data consumer (JAXB unmarshaller). This map is the converse of {@link #toView}.
+     * data consumer (JAXB unmarshaller). This map is the converse of {@link #exports}.
      *
-     * @see FilteredNamespaces#toImpl
+     * @see FilteredNamespaces#imports
      */
-    final Map<String,String> toImpl;
+    final Map<String,String> imports;
 
     /**
-     * {@code true} if application of {@link #toView} result in many namespaces collapsed
into
-     * a single namespace. In those case, {@link #toImpl} is not sufficient for performing
the
+     * {@code true} if application of {@link #exports} result 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}.
      */
     final boolean manyToOne;
@@ -127,8 +127,8 @@ enum FilterVersion {
      * @param  view  the namespace used in the XML file to (un)marshall (older schema).
      */
     private FilterVersion(final String impl, final String view) {
-        this.toView = singletonMap(impl, view);
-        this.toImpl = singletonMap(view, impl);
+        this.exports = singletonMap(impl, view);
+        this.imports = singletonMap(view, impl);
         manyToOne = false;
     }
 
@@ -143,15 +143,15 @@ enum FilterVersion {
      *                     having different {@code view} values.
      */
     private FilterVersion(final String[] impl, final String view, final String[] additional,
-            final Map<String,String> toImpl)
+            final Map<String,String> imports)
     {
-        toView = new HashMap<>(Containers.hashMapCapacity(impl.length));
-        this.toImpl = toImpl;
+        exports = new HashMap<>(Containers.hashMapCapacity(impl.length));
+        this.imports = imports;
         for (final String e : impl) {
-            toView.put(e, view);
+            exports.put(e, view);
         }
         for (int i=0; i<additional.length;) {
-            toView.put(additional[i++],
+            exports.put(additional[i++],
                        additional[i++]);
         }
         manyToOne = true;
@@ -161,10 +161,10 @@ enum FilterVersion {
      * Creates the {@link #ALL} enumeration.
      */
     private FilterVersion(final FilterVersion first, final FilterVersion more) {
-        toView = new HashMap<>(first.toView);
-        toImpl = new HashMap<>(first.toImpl);
-        toView.putAll(more.toView);
-        toImpl.putAll(more.toImpl);
+        exports = new HashMap<>(first.exports);
+        imports = new HashMap<>(first.imports);
+        exports.putAll(more.exports);
+        imports.putAll(more.imports);
         manyToOne = first.manyToOne | more.manyToOne;
     }
 }

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=1823774&r1=1823773&r2=1823774&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] Sat Feb 10 14:16:09 2018
@@ -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.toView.getOrDefault(uri, uri);
+                return version.exports.getOrDefault(uri, 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=1823774&r1=1823773&r2=1823774&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] Sat Feb 10 14:16:09 2018
@@ -73,17 +73,17 @@ final class FilteredNamespaces implement
     /**
      * The URI replacements to apply when going from the wrapped context to the filtered
context.
      *
-     * @see FilterVersion#toView
+     * @see FilterVersion#exports
      */
-    private final Map<String,String> toView;
+    private final Map<String,String> exports;
 
     /**
      * The URI replacements to apply when going from the filtered context to the wrapped
context.
-     * This map is the converse of {@link #toView}.
+     * This map is the converse of {@link #exports}.
      *
-     * @see FilterVersion#toImpl
+     * @see FilterVersion#imports
      */
-    private final Map<String,String> toImpl;
+    private final Map<String,String> imports;
 
     /**
      * Creates a new namespaces filter for the given target version.
@@ -91,11 +91,11 @@ final class FilteredNamespaces implement
     FilteredNamespaces(final NamespaceContext context, final FilterVersion version, final
boolean inverse) {
         this.context = context;
         if (!inverse) {
-            toView = version.toView;
-            toImpl = version.toImpl;
+            exports = version.exports;
+            imports = version.imports;
         } else {
-            toView = version.toImpl;
-            toImpl = version.toView;
+            exports = version.imports;
+            imports = version.exports;
         }
     }
 
@@ -104,7 +104,7 @@ final class FilteredNamespaces implement
      * specified by the given version.
      */
     NamespaceContext inverse(final FilterVersion version) {
-        if (toView == version.toView && toImpl == version.toImpl) {
+        if (exports == version.exports && imports == version.imports) {
             return this;
         }
         return new FilteredNamespaces(this, version, true);
@@ -116,7 +116,7 @@ final class FilteredNamespaces implement
     @Override
     public String getNamespaceURI(final String prefix) {
         final String uri = context.getNamespaceURI(prefix);
-        return toView.getOrDefault(uri, uri);
+        return exports.getOrDefault(uri, uri);
     }
 
     /**
@@ -124,7 +124,7 @@ final class FilteredNamespaces implement
      */
     @Override
     public String getPrefix(final String namespaceURI) {
-        return context.getPrefix(toImpl.getOrDefault(namespaceURI, namespaceURI));
+        return context.getPrefix(imports.getOrDefault(namespaceURI, namespaceURI));
     }
 
     /**
@@ -133,6 +133,6 @@ final class FilteredNamespaces implement
     @Override
     @SuppressWarnings("unchecked")          // TODO: remove on JDK9
     public Iterator<String> getPrefixes(final String namespaceURI) {
-        return context.getPrefixes(toImpl.getOrDefault(namespaceURI, namespaceURI));
+        return context.getPrefixes(imports.getOrDefault(namespaceURI, namespaceURI));
     }
 }

Modified: sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java?rev=1823774&r1=1823773&r2=1823774&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredStreamReader.java
[UTF-8] Sat Feb 10 14:16:09 2018
@@ -65,15 +65,15 @@ class FilteredStreamReader extends Strea
     /**
      * Converts a JAXB URI to the URI seen by the consumer of this wrapper.
      */
-    private String toView(final String uri) {
-        return version.toView.getOrDefault(uri, uri);
+    private String exportNS(final String uri) {
+        return version.exports.getOrDefault(uri, uri);
     }
 
     /**
      * Converts a URI read from the XML document to the URI to give to JAXB.
      */
-    final String toImpl(final String uri) {
-        return version.toImpl.getOrDefault(uri, uri);
+    final String importNS(final String uri) {
+        return version.imports.getOrDefault(uri, uri);
     }
 
     /**
@@ -82,9 +82,9 @@ class FilteredStreamReader extends Strea
      * The {@link FilteredStreamResolver} subclass implements a more complex mapping where
the
      * namespace depends on the element (class or attribute) name.
      */
-    QName toImpl(QName name) {
+    QName importNS(QName name) {
         final String namespaceURI = name.getNamespaceURI();
-        final String replacement = toImpl(namespaceURI);
+        final String replacement = importNS(namespaceURI);
         if (replacement != namespaceURI) {                          // Identity checks are
okay here.
             name = new QName(namespaceURI, name.getLocalPart(), name.getPrefix());
         }
@@ -94,7 +94,7 @@ class FilteredStreamReader extends Strea
     /** 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, toView(namespaceURI), localName);
+        super.require(type, exportNS(namespaceURI), localName);
     }
 
     /** Returns the context of the underlying reader wrapped in a filter that converts the
namespaces on the fly. */
@@ -106,19 +106,19 @@ class FilteredStreamReader extends Strea
     /** Forwards the call, then replaces the namespace URI if needed. */
     @Override
     public QName getName() {
-        return toImpl(super.getName());
+        return importNS(super.getName());
     }
 
     /** Forwards the call, then replaces the namespace URI if needed. */
     @Override
     public QName getAttributeName(final int index) {
-        return toImpl(super.getAttributeName(index));
+        return importNS(super.getAttributeName(index));
     }
 
     /** Forwards the call, then replaces the returned URI if needed. */
     @Override
     public String getNamespaceURI() {
-        return toImpl(super.getNamespaceURI());
+        return importNS(super.getNamespaceURI());
     }
 
     /**
@@ -129,24 +129,24 @@ class FilteredStreamReader extends Strea
      */
     @Override
     public String getNamespaceURI(int index) {
-        return toImpl(super.getNamespaceURI(index));
+        return importNS(super.getNamespaceURI(index));
     }
 
     /** Forwards the call, then replaces the returned URI if needed. */
     @Override
     public String getNamespaceURI(final String prefix) {
-        return toImpl(super.getNamespaceURI(prefix));
+        return importNS(super.getNamespaceURI(prefix));
     }
 
     /** Forwards the call, then replaces the returned URI if needed. */
     @Override
     public String getAttributeNamespace(final int index) {
-        return toImpl(super.getAttributeNamespace(index));
+        return 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(toView(namespaceUri), localName);
+        return super.getAttributeValue(exportNS(namespaceUri), localName);
     }
 }

Modified: 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/FilteredStreamResolver.java?rev=1823774&r1=1823773&r2=1823774&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/FilteredStreamResolver.java
[UTF-8] Sat Feb 10 14:16:09 2018
@@ -234,17 +234,17 @@ final class FilteredStreamResolver exten
      * Return the namespace used by implementation (the SIS classes with JAXB annotations)
      * in the context of the current part of the XML document being read.
      *
-     * @param   name   the local name of the element or attribute currently being read.
+     * @param   localPart   the local name of the element or attribute currently being read.
      * @return  the namespace URI for the element or attribute in the current context (e.g.
an ISO 19115-3 namespace),
      *          or {@code null} if the given name is unknown.
      */
-    private String toImplNamespace(final String name) {
-        final Set<String> declaringTypes = DECLARING_TYPES.get(name);
+    private String namespaceOf(final String localPart) {
+        final Set<String> declaringTypes = DECLARING_TYPES.get(localPart);
         if (declaringTypes == null) {
             /*
              * If the element is a root element, return the associated namespace.
              */
-            final Map<String,String> attributes = NAMESPACES.get(name);
+            final Map<String,String> attributes = NAMESPACES.get(localPart);
             if (attributes != null) {
                 return attributes.get(TYPE_KEY);
             }
@@ -260,7 +260,7 @@ final class FilteredStreamResolver exten
                      * A NullPointerException below would be a bug in our algorithm because
                      * we constructed DECLARING_TYPES from NAMESPACES keys only.
                      */
-                    return NAMESPACES.get(parent).get(name);
+                    return NAMESPACES.get(parent).get(localPart);
                 }
             }
         }
@@ -272,12 +272,12 @@ final class FilteredStreamResolver exten
      * The new namespace depends on both the old namespace and the element name.
      */
     @Override
-    final QName toImpl(QName name) {
+    final QName importNS(QName name) {
         final String namespaceURI = name.getNamespaceURI();
         final String localPart = name.getLocalPart();
-        String replacement = toImplNamespace(localPart);
+        String replacement = namespaceOf(localPart);
         if (replacement == null) {
-            replacement = toImpl(namespaceURI);
+            replacement = importNS(namespaceURI);
         }
         if (!replacement.equals(namespaceURI)) {
             name = new QName(replacement, localPart, name.getPrefix());
@@ -291,7 +291,7 @@ final class FilteredStreamResolver exten
      */
     @Override
     public String getNamespaceURI() {
-        String namespace = toImplNamespace(getLocalName());
+        String namespace = namespaceOf(getLocalName());
         if (namespace == null) {
             namespace = super.getNamespaceURI();
         }

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=1823774&r1=1823773&r2=1823774&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] Sat Feb 10 14:16:09 2018
@@ -93,7 +93,7 @@ final class FilteredWriter implements XM
      * If there is no namespace change, then this method returns the given instance as-is.
      */
     private String export(final String uri) {
-        return version.toView.getOrDefault(uri, uri);
+        return version.exports.getOrDefault(uri, uri);
     }
 
     /**
@@ -103,7 +103,7 @@ final class FilteredWriter implements XM
     private QName export(QName name) {
         String uri = name.getNamespaceURI();
         if (uri != null && !uri.isEmpty()) {                                // Optimization
for a common case.
-            uri = version.toView.get(uri);
+            uri = version.exports.get(uri);
             if (uri != null) {
                 name = new QName(uri, name.getLocalPart(), Namespaces.getPreferredPrefix(uri,
name.getPrefix()));
             }
@@ -139,7 +139,7 @@ final class FilteredWriter implements XM
             if (uri.charAt(end) == '/') {
                 uri = uri.substring(0, end);                            // Trim trailing
'/' in URI.
             }
-            final String exported = version.toView.get(uri);
+            final String exported = version.exports.get(uri);
             if (exported != null) {
                 return uniqueNamespaces.computeIfAbsent(exported, (k) -> {
                     return new FilteredEvent.NS(namespace, Namespaces.getPreferredPrefix(k,
namespace.getPrefix()), k);



Mime
View raw message