sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1818424 - in /sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso: DefaultMetadata.java package-info.java
Date Sat, 16 Dec 2017 15:30:28 GMT
Author: desruisseaux
Date: Sat Dec 16 15:30:28 2017
New Revision: 1818424

URL: http://svn.apache.org/viewvc?rev=1818424&view=rev
Log:
Upgrade some DefaultMetadata methods to ISO 19115-3.
This is part of commit e780d66b4d7d59368e742ba01777a151d8827ea8 from Image Matter.

The project at this revision can be built but is known to have test failure.
Tests will pass only after we completed the port of all ISO 19115-3 work.

Modified:
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
    sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java?rev=1818424&r1=1818423&r2=1818424&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
[UTF-8] Sat Dec 16 15:30:28 2017
@@ -66,7 +66,9 @@ import org.apache.sis.internal.metadata.
 import org.apache.sis.internal.metadata.OtherLocales;
 import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.util.CollectionsExt;
-import org.apache.sis.internal.jaxb.code.PT_Locale;
+import org.apache.sis.internal.jaxb.gmd.LocaleAdapter;
+import org.apache.sis.internal.jaxb.LegacyNamespaces;
+import org.apache.sis.internal.jaxb.FilterByVersion;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.xml.Namespaces;
 
@@ -121,24 +123,43 @@ import org.apache.sis.xml.Namespaces;
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Touraïvane (IRD)
  * @author  Cédric Briançon (Geomatys)
- * @version 0.8
+ * @author  Cullen Rombach (Image Matters)
+ * @version 1.0
  * @since   0.3
  * @module
  */
 @SuppressWarnings("CloneableClassWithoutClone")                 // ModifiableMetadata needs
shallow clones.
 @XmlType(name = "MD_Metadata_Type", propOrder = {
+    // Attributes new in ISO 19115-3
+    "metadataIdentifier",
+    "defaultLocale",
+    "parentMetadata",
+    "metadataScopes",
+
+    // Legacy ISO 19139:2007 attributes
     "fileIdentifier",
     "language",
     "characterSet",
     "parentIdentifier",
     "hierarchyLevels",
     "hierarchyLevelNames",
+
+    // Common to both formats
     "contacts",
+
+    // Attributes new in ISO 19115-3
+    "dateInfo",
+    "metadataStandards",
+    "otherLocales",
+
+    // Legacy ISO 19139:2007 attributes
     "dateStamp",
     "metadataStandardName",
     "metadataStandardVersion",
     "dataSetUri",
     "locales",
+
+    // Common to both formats
     "spatialRepresentationInfo",
     "referenceSystemInfo",
     "metadataExtensionInfo",
@@ -390,8 +411,9 @@ public class DefaultMetadata extends ISO
      * @since 0.5
      */
     @Override
+    @XmlElement(name = "metadataIdentifier")
     public Identifier getMetadataIdentifier() {
-        return metadataIdentifier;
+        return FilterByVersion.CURRENT_METADATA.accept() ? metadataIdentifier : null;
     }
 
     /**
@@ -416,11 +438,14 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "fileIdentifier")
     @Dependencies("getMetadataIdentifier")
+    @XmlElement(name = "fileIdentifier", namespace = LegacyNamespaces.GMD)
     public String getFileIdentifier() {
-        final Identifier identifier = getMetadataIdentifier();
-        return (identifier != null) ? identifier.getCode() : null;
+        if (FilterByVersion.LEGACY_METADATA.accept()) {
+            final Identifier identifier = getMetadataIdentifier();
+            if (identifier != null) return identifier.getCode();
+        }
+        return null;
     }
 
     /**
@@ -476,7 +501,7 @@ public class DefaultMetadata extends ISO
      */
     public void setLanguages(final Collection<Locale> newValues) {
         languages = writeCollection(newValues, languages, Locale.class);
-        // The "magik" applying this language to every children
+        // The "magic" applying this language to every children
         // is performed by the 'beforeMarshal(Marshaller)' method.
     }
 
@@ -489,10 +514,11 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "language")
     @Dependencies("getLanguages")
+    @XmlElement(name = "language", namespace = LegacyNamespaces.GMD)
+    @XmlJavaTypeAdapter(LocaleAdapter.class)
     public Locale getLanguage() {
-        return CollectionsExt.first(getLanguages());
+        return FilterByVersion.LEGACY_METADATA.accept() ? CollectionsExt.first(getLanguages())
: null;
         /*
          * No warning if the collection contains more than one locale, because
          * this is allowed by the "getLanguage() + getLocales()" contract.
@@ -500,6 +526,15 @@ public class DefaultMetadata extends ISO
     }
 
     /**
+     * Gets the default locale for this record (used in ISO 19115-3 format).
+     */
+    @Dependencies("getLanguages")
+    @XmlElement(name = "defaultLocale")
+    private Locale getDefaultLocale() {
+        return FilterByVersion.CURRENT_METADATA.accept() ? CollectionsExt.first(getLanguages())
: null;
+    }
+
+    /**
      * Sets the language used for documenting metadata.
      * This method modifies the collection returned by {@link #getLanguages()} as below:
      *
@@ -515,10 +550,27 @@ public class DefaultMetadata extends ISO
     @Deprecated
     public void setLanguage(final Locale newValue) {
         checkWritePermission();
+        setDefaultLocale(newValue);
+    }
+
+    /**
+     * Sets the default locale for this record (used in ISO 19115-3 format).
+     */
+    @SuppressWarnings("unused")
+    private void setDefaultLocale(final Locale newValue) {
         setLanguages(OtherLocales.setFirst(languages, newValue)); // See "Note about deprecated
methods implementation"
     }
 
     /**
+     * Gets the other locales for this record (used in ISO 19115-3 format).
+     */
+    @Dependencies("getLanguages")
+    @XmlElement(name = "otherLocale")
+    private Collection<Locale> getOtherLocales() {
+        return FilterByVersion.CURRENT_METADATA.accept() ? OtherLocales.filter(getLanguages())
: null;
+    }
+
+    /**
      * Provides information about an alternatively used localized character string for a
linguistic extension.
      *
      * @return alternatively used localized character string for a linguistic extension.
@@ -527,11 +579,10 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "locale")
-    @XmlJavaTypeAdapter(PT_Locale.class)
     @Dependencies("getLanguages")
+    @XmlElement(name = "locale", namespace = LegacyNamespaces.GMD)
     public Collection<Locale> getLocales() {
-        return OtherLocales.filter(getLanguages());
+        return FilterByVersion.LEGACY_METADATA.accept() ? OtherLocales.filter(getLanguages())
: null;
     }
 
     /**
@@ -544,6 +595,14 @@ public class DefaultMetadata extends ISO
     @Deprecated
     public void setLocales(final Collection<? extends Locale> newValues) {
         checkWritePermission();
+        setOtherLocales(newValues);
+    }
+
+    /**
+     * Sets the other locales for this record (used in ISO 19115-3 format).
+     */
+    @SuppressWarnings("unused")
+    private void setOtherLocales(final Collection<? extends Locale> newValues) {
         setLanguages(OtherLocales.merge(CollectionsExt.first(languages), newValues)); //
See "Note about deprecated methods implementation"
     }
 
@@ -597,23 +656,25 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "characterSet")
     @Dependencies("getCharacterSets")
+    @XmlElement(name = "characterSet", namespace = LegacyNamespaces.GMD)
     public CharacterSet getCharacterSet() {
-        final Charset cs = LegacyPropertyAdapter.getSingleton(getCharacterSets(),
-                Charset.class, null, DefaultMetadata.class, "getCharacterSet");
-        if (cs == null) {
-            return null;
-        }
-        final String name = cs.name();
-        for (final CharacterSet candidate : CharacterSet.values()) {
-            for (final String n : candidate.names()) {
-                if (name.equals(n)) {
-                    return candidate;
+        if (FilterByVersion.LEGACY_METADATA.accept()) {
+            final Charset cs = LegacyPropertyAdapter.getSingleton(getCharacterSets(),
+                    Charset.class, null, DefaultMetadata.class, "getCharacterSet");
+            if (cs != null) {
+                final String name = cs.name();
+                for (final CharacterSet candidate : CharacterSet.values()) {
+                    for (final String n : candidate.names()) {
+                        if (name.equals(n)) {
+                            return candidate;
+                        }
+                    }
                 }
+                return CharacterSet.valueOf(name);
             }
         }
-        return CharacterSet.valueOf(name);
+        return null;
     }
 
     /**
@@ -637,8 +698,9 @@ public class DefaultMetadata extends ISO
      * @since 0.5
      */
     @Override
+    @XmlElement(name = "parentMetadata")
     public Citation getParentMetadata() {
-        return parentMetadata;
+        return FilterByVersion.CURRENT_METADATA.accept() ? parentMetadata : null;
     }
 
     /**
@@ -662,14 +724,16 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "parentIdentifier")
     @Dependencies("getParentMetadata")
+    @XmlElement(name = "parentIdentifier", namespace = LegacyNamespaces.GMD)
     public String getParentIdentifier() {
-        final Citation parentMetadata = getParentMetadata();
-        if (parentMetadata != null) {
-            final InternationalString title = parentMetadata.getTitle();
-            if (title != null) {
-                return title.toString();
+        if (FilterByVersion.LEGACY_METADATA.accept()) {
+            final Citation parentMetadata = getParentMetadata();
+            if (parentMetadata != null) {
+                final InternationalString title = parentMetadata.getTitle();
+                if (title != null) {
+                    return title.toString();
+                }
             }
         }
         return null;
@@ -702,7 +766,9 @@ public class DefaultMetadata extends ISO
      * @since 0.5
      */
     @Override
+    @XmlElement(name = "metadataScope")
     public Collection<MetadataScope> getMetadataScopes() {
+        if (!FilterByVersion.CURRENT_METADATA.accept()) return null;
         return metadataScopes = nonNullCollection(metadataScopes, MetadataScope.class);
     }
 
@@ -727,9 +793,10 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "hierarchyLevel")
     @Dependencies("getMetadataScopes")
+    @XmlElement(name = "hierarchyLevel", namespace = LegacyNamespaces.GMD)
     public final Collection<ScopeCode> getHierarchyLevels() {
+        if (!FilterByVersion.LEGACY_METADATA.accept()) return null;
         return new MetadataScopeAdapter<ScopeCode>(getMetadataScopes()) {
             /** Stores a legacy value into the new kind of value. */
             @Override protected MetadataScope wrap(final ScopeCode value) {
@@ -776,9 +843,10 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "hierarchyLevelName")
     @Dependencies("getMetadataScopes")
+    @XmlElement(name = "hierarchyLevelName", namespace = LegacyNamespaces.GMD)
     public final Collection<String> getHierarchyLevelNames() {
+        if (!FilterByVersion.LEGACY_METADATA.accept()) return null;
         return new MetadataScopeAdapter<String>(getMetadataScopes()) {
             /** Stores a legacy value into the new kind of value. */
             @Override protected MetadataScope wrap(final String value) {
@@ -847,7 +915,9 @@ public class DefaultMetadata extends ISO
      * @since 0.5
      */
     @Override
+    @XmlElement(name = "dateInfo", required = true)
     public Collection<CitationDate> getDateInfo() {
+        if (!FilterByVersion.CURRENT_METADATA.accept()) return null;
         return dateInfo = nonNullCollection(dateInfo, CitationDate.class);
     }
 
@@ -872,14 +942,16 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "dateStamp", required = true)
     @Dependencies("getDateInfo")
+    @XmlElement(name = "dateStamp", namespace = LegacyNamespaces.GMD, required = true)
     public Date getDateStamp() {
-        final Collection<CitationDate> dates = getDateInfo();
-        if (dates != null) {
-            for (final CitationDate date : dates) {
-                if (DateType.CREATION.equals(date.getDateType())) {
-                    return date.getDate();
+        if (FilterByVersion.LEGACY_METADATA.accept()) {
+            final Collection<CitationDate> dates = getDateInfo();
+            if (dates != null) {
+                for (final CitationDate date : dates) {
+                    if (DateType.CREATION.equals(date.getDateType())) {
+                        return date.getDate();
+                    }
                 }
             }
         }
@@ -936,7 +1008,9 @@ public class DefaultMetadata extends ISO
      * @since 0.5
      */
     @Override
+    @XmlElement(name = "metadataStandard")
     public Collection<Citation> getMetadataStandards() {
+        if (!FilterByVersion.CURRENT_METADATA.accept()) return null;
         return metadataStandards = nonNullCollection(metadataStandards, Citation.class);
     }
 
@@ -1006,12 +1080,15 @@ public class DefaultMetadata extends ISO
      * Implementation of legacy {@link #getMetadataStandardName()} and {@link #getMetadataStandardVersion()}
methods.
      */
     private String getMetadataStandard(final boolean version) {
-        final Citation standard = LegacyPropertyAdapter.getSingleton(getMetadataStandards(),
-                Citation.class, null, DefaultMetadata.class, version ? "getMetadataStandardName"
: "getMetadataStandardVersion");
-        if (standard != null) {
-            final InternationalString title = version ? standard.getEdition() : standard.getTitle();
-            if (title != null) {
-                return title.toString();
+        if (FilterByVersion.LEGACY_METADATA.accept()) {
+            final Citation standard = LegacyPropertyAdapter.getSingleton(getMetadataStandards(),
+                    Citation.class, null, DefaultMetadata.class,
+                    version ? "getMetadataStandardName" : "getMetadataStandardVersion");
+            if (standard != null) {
+                final InternationalString title = version ? standard.getEdition() : standard.getTitle();
+                if (title != null) {
+                    return title.toString();
+                }
             }
         }
         return null;
@@ -1054,8 +1131,8 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "metadataStandardName")
     @Dependencies("getMetadataStandards")
+    @XmlElement(name = "metadataStandardName", namespace = LegacyNamespaces.GMD)
     public String getMetadataStandardName() {
         return getMetadataStandard(false);
     }
@@ -1083,8 +1160,8 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "metadataStandardVersion")
     @Dependencies("getMetadataStandards")
+    @XmlElement(name = "metadataStandardVersion", namespace = LegacyNamespaces.GMD)
     public String getMetadataStandardVersion() {
         return getMetadataStandard(true);
     }
@@ -1135,12 +1212,12 @@ public class DefaultMetadata extends ISO
      */
     @Override
     @Deprecated
-    @XmlElement(name = "dataSetURI")
     @Dependencies("getIdentificationInfo")
+    @XmlElement(name = "dataSetURI", namespace = LegacyNamespaces.GMD)
     public String getDataSetUri() {
         String linkage = null;
-        final Collection<Identification> info = getIdentificationInfo();
-        if (info != null) {
+        final Collection<Identification> info;
+        if (FilterByVersion.LEGACY_METADATA.accept() && (info = getIdentificationInfo())
!= null) {
             for (final Identification identification : info) {
                 final Citation citation = identification.getCitation();
                 if (citation != null) {
@@ -1494,6 +1571,7 @@ public class DefaultMetadata extends ISO
      * Invoked by JAXB {@link javax.xml.bind.Marshaller} before this object is marshalled
to XML.
      * This method sets the locale to be used for XML marshalling to the metadata language.
      */
+    @SuppressWarnings("unused")
     private void beforeMarshal(final Marshaller marshaller) {
         Context.push(CollectionsExt.first(languages));
     }
@@ -1502,6 +1580,7 @@ public class DefaultMetadata extends ISO
      * Invoked by JAXB {@link javax.xml.bind.Marshaller} after this object has been marshalled
to
      * XML. This method restores the locale to be used for XML marshalling to its previous
value.
      */
+    @SuppressWarnings("unused")
     private void afterMarshal(final Marshaller marshaller) {
         Context.pull();
     }

Modified: sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java?rev=1818424&r1=1818423&r2=1818424&view=diff
==============================================================================
--- sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java
[UTF-8] (original)
+++ sis/branches/ISO-19115-3/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/package-info.java
[UTF-8] Sat Dec 16 15:30:28 2017
@@ -92,11 +92,13 @@
     @XmlNs(prefix = "lan", namespaceURI = Namespaces.LAN),
     @XmlNs(prefix = "mcc", namespaceURI = Namespaces.MCC),
     @XmlNs(prefix = "gco", namespaceURI = Namespaces.GCO),
-    @XmlNs(prefix = "xsi", namespaceURI = Namespaces.XSI)
+    @XmlNs(prefix = "xsi", namespaceURI = Namespaces.XSI),
+    @XmlNs(prefix = "gmd", namespaceURI = LegacyNamespaces.GMD)
 })
 @XmlAccessorType(XmlAccessType.NONE)
 @XmlJavaTypeAdapters({
     @XmlJavaTypeAdapter(CI_Citation.class),
+    @XmlJavaTypeAdapter(CI_Date.class),
     @XmlJavaTypeAdapter(CI_OnlineResource.class),
     @XmlJavaTypeAdapter(CI_Responsibility.class),
     @XmlJavaTypeAdapter(DQ_DataQuality.class),
@@ -110,8 +112,10 @@
     @XmlJavaTypeAdapter(MD_ExtendedElementInformation.class),
     @XmlJavaTypeAdapter(MD_FeatureTypeList.class),
     @XmlJavaTypeAdapter(MD_Identification.class),
+    @XmlJavaTypeAdapter(MD_Identifier.class),
     @XmlJavaTypeAdapter(MD_MaintenanceInformation.class),
     @XmlJavaTypeAdapter(MD_MetadataExtensionInformation.class),
+    @XmlJavaTypeAdapter(MD_MetadataScope.class),
     @XmlJavaTypeAdapter(MD_ObligationCode.class),
     @XmlJavaTypeAdapter(MD_PortrayalCatalogueReference.class),
     @XmlJavaTypeAdapter(MD_ScopeCode.class),
@@ -120,7 +124,7 @@
     @XmlJavaTypeAdapter(RS_ReferenceSystem.class),
 
     // Java types, primitive types and basic OGC types handling
-    @XmlJavaTypeAdapter(LocaleAdapter.class),
+    @XmlJavaTypeAdapter(PT_Locale.class),
     @XmlJavaTypeAdapter(StringAdapter.class),
     @XmlJavaTypeAdapter(InternationalStringAdapter.class),
     @XmlJavaTypeAdapter(GO_DateTime.class),
@@ -137,8 +141,8 @@ import javax.xml.bind.annotation.XmlAcce
 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.LegacyNamespaces;
 import org.apache.sis.internal.jaxb.Schemas;
 import org.apache.sis.internal.jaxb.gco.*;
-import org.apache.sis.internal.jaxb.gmd.*;
 import org.apache.sis.internal.jaxb.code.*;
 import org.apache.sis.internal.jaxb.metadata.*;



Mime
View raw message