Author: desruisseaux
Date: Tue Feb 27 18:14:03 2018
New Revision: 1825487

URL: http://svn.apache.org/viewvc?rev=1825487&view=rev
Log:
Merge NameAdapter, GO_GenericName and GO_LocalName in a single class, as they 
were no need to specialize.

Added:
    
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java
      - copied, changed from r1825486, 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java
Removed:
    
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_LocalName.java
    
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java
Modified:
    
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java
    
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
    
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/package-info.java

Copied: 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java
 (from r1825486, 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java)
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java?p2=sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java&p1=sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java&r1=1825486&r2=1825487&rev=1825487&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/NameAdapter.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/GO_GenericName.java
 [UTF-8] Tue Feb 27 18:14:03 2018
@@ -42,6 +42,9 @@ import org.apache.sis.internal.jaxb.Filt
  *   <li>{@code MemberName}</li>
  * </ul>
  *
+ * Note that there is no need to create adapter for above-cited subtypes.
+ * This adapter should be applicable to all.
+ *
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Guilhem Legal (Geomatys)
@@ -49,18 +52,47 @@ import org.apache.sis.internal.jaxb.Filt
  * @since   0.3
  * @module
  */
-abstract class NameAdapter<ValueType extends NameAdapter<ValueType,BoundType>, 
BoundType extends GenericName>
-        extends XmlAdapter<ValueType, BoundType>
-{
+public class GO_GenericName extends XmlAdapter<GO_GenericName, GenericName> {
     /**
      * The generic name to be marshalled.
      */
-    GenericName name;
+    private GenericName name;
+
+    /**
+     * Empty constructor for JAXB only.
+     */
+    public GO_GenericName() {
+    }
+
+    /**
+     * Wraps a name at marshalling-time.
+     */
+    private GO_GenericName(final GenericName value) {
+        name = value;
+    }
 
     /**
-     * Empty constructor for subclasses only.
+     * Replaces a generic name by its wrapper.
+     * JAXB calls automatically this method at marshalling-time.
+     *
+     * @param  value  the implementing class for this metadata value.
+     * @return an wrapper which contains the metadata value.
      */
-    NameAdapter() {
+    @Override
+    public GO_GenericName marshal(final GenericName value) {
+        return (value != null) ? new GO_GenericName(value) : null;
+    }
+
+    /**
+     * Unwraps the generic name from the given element.
+     * JAXB calls automatically this method at unmarshalling-time.
+     *
+     * @param  value  the wrapper, or {@code null} if none.
+     * @return the implementing class.
+     */
+    @Override
+    public final GenericName unmarshal(final GO_GenericName value) {
+        return (value != null) ? value.name : null;
     }
 
     /**
@@ -163,4 +195,23 @@ abstract class NameAdapter<ValueType ext
             throw new 
IllegalStateException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, "name"));
         }
     }
+
+    /**
+     * Wraps the value only if marshalling ISO 19115-3 element.
+     * Otherwise (i.e. if marshalling a legacy ISO 19139:2007 document), omit 
the element.
+     */
+    public static final class Since2014 extends GO_GenericName {
+        /** Empty constructor used only by JAXB. */
+        public Since2014() {
+        }
+
+        /**
+         * Wraps the given value in an ISO 19115-3 element, unless we are 
marshalling an older document.
+         *
+         * @return a non-null value only if marshalling ISO 19115-3 or newer.
+         */
+        @Override public GO_GenericName marshal(final GenericName value) {
+            return FilterByVersion.CURRENT_METADATA.accept() ? 
super.marshal(value) : null;
+        }
+    }
 }

Modified: 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java?rev=1825487&r1=1825486&r2=1825487&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/package-info.java
 [UTF-8] Tue Feb 27 18:14:03 2018
@@ -89,7 +89,7 @@
     @XmlJavaTypeAdapter(CI_Responsibility.class),
     @XmlJavaTypeAdapter(GO_DateTime.class),
     @XmlJavaTypeAdapter(GO_Integer.class),
-    @XmlJavaTypeAdapter(GO_LocalName.class),
+    @XmlJavaTypeAdapter(GO_GenericName.class),
     @XmlJavaTypeAdapter(GO_Real.class),
     @XmlJavaTypeAdapter(MD_DigitalTransferOptions.class),
     @XmlJavaTypeAdapter(MD_Distributor.class),

Modified: 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java?rev=1825487&r1=1825486&r2=1825487&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/DefaultLocalName.java
 [UTF-8] Tue Feb 27 18:14:03 2018
@@ -93,7 +93,7 @@ public class DefaultLocalName extends Ab
      * <div class="section">Note on JAXB annotation</div>
      * The {@link XmlElement} annotation applied here is appropriate for 
{@code TypeName} and {@code MemberName}
      * subtypes only. It is <strong>not</strong> appropriate when 
(un)marshalling directly a {@code LocalName}.
-     * The distinction between the two cases is done by {@link 
org.apache.sis.internal.jaxb.gco.GO_LocalName},
+     * The distinction between the two cases is done by {@link 
org.apache.sis.internal.jaxb.gco.GO_GenericName},
      * which replace the {@code LocalName} instance by an internal {@code 
NameValue} object (so the XML element
      * declared here is never marshalled). Example:
      *

Modified: 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/package-info.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/package-info.java?rev=1825487&r1=1825486&r2=1825487&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/package-info.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/util/iso/package-info.java
 [UTF-8] Tue Feb 27 18:14:03 2018
@@ -127,5 +127,5 @@ import javax.xml.bind.annotation.XmlAcce
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
-import org.apache.sis.xml.Namespaces;
 import org.apache.sis.internal.jaxb.gco.GO_GenericName;
+import org.apache.sis.xml.Namespaces;


Reply via email to