sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1796282 - in /sis/branches/JDK8/core/sis-metadata/src: main/java/org/apache/sis/internal/metadata/ main/java/org/apache/sis/metadata/iso/ main/java/org/apache/sis/metadata/iso/citation/ main/java/org/apache/sis/metadata/iso/content/ main/j...
Date Fri, 26 May 2017 13:05:43 GMT
Author: desruisseaux
Date: Fri May 26 13:05:43 2017
New Revision: 1796282

URL: http://svn.apache.org/viewvc?rev=1796282&view=rev
Log:
When user asks for a property value on a metadata implementation backed by a database (org.apache.sis.metadata.sql package),
we should take in account the cases where the property value is not stored, but rather computed from other property values.
Such cases happen with ISO 19115:2003 properties which have been deprecated and replaced by new properties in ISO 19115:2014.
Supporting on-the-fly computations in ...metadata.sql package requires that we keep trace of dependencies in property values.
The mechanism for tracking dependencies is (at least for now) internal to Apache SIS, not in public API.

Added:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Dependencies.java   (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeDimension.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/AbstractIdentification.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultAggregateInformation.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java

Added: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Dependencies.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Dependencies.java?rev=1796282&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Dependencies.java (added)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Dependencies.java [UTF-8] Fri May 26 13:05:43 2017
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.metadata;
+
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+
+/**
+ * Indicates that the value of a property is computed from values of other properties.
+ * This annotation can be applied on getter methods.  All dependent properties must be
+ * in the same class than the annotated method. Transitive dependencies do not need to
+ * be declared, but the dependency graph shall not contain cycle.
+ *
+ * <div class="note"><b>Example:</b>
+ *
+ * </div>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 0.8
+ * @since   0.8
+ * @module
+ */
+@Target(ElementType.METHOD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Dependencies {
+    /**
+     * Names of other Java method required for computing the annotated property.
+     * Should be Java method names rather than UML identifier, in order to avoid ambiguity when a
+     * property has both a singular and a plural form (usually with the singular form deprecated).
+     *
+     * @return other properties in the same class required for computation, not including transitive dependencies.
+     */
+    String[] value();
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Dependencies.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/Dependencies.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java [UTF-8] Fri May 26 13:05:43 2017
@@ -30,6 +30,7 @@ import org.opengis.util.InternationalStr
 import org.apache.sis.metadata.TitleProperty;
 import org.apache.sis.measure.ValueRange;
 import org.apache.sis.util.iso.Types;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.ensurePositive;
@@ -545,6 +546,7 @@ public class DefaultExtendedElementInfor
     @Override
     @Deprecated
     @XmlElement(name = "rationale")
+    @Dependencies("getRationale")
     public Collection<InternationalString> getRationales() {
         return new AbstractSet<InternationalString>() {
             /** Returns 0 if empty, or 1 if a density has been specified. */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultMetadata.java [UTF-8] Fri May 26 13:05:43 2017
@@ -64,6 +64,7 @@ import org.apache.sis.metadata.iso.ident
 import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 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.Context;
@@ -389,6 +390,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "fileIdentifier")
+    @Dependencies("getMetadataIdentifier")
     public String getFileIdentifier() {
         final Identifier identifier = getMetadataIdentifier();
         return (identifier != null) ? identifier.getCode() : null;
@@ -461,6 +463,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "language")
+    @Dependencies("getLanguages")
     public Locale getLanguage() {
         return CollectionsExt.first(getLanguages());
         /*
@@ -499,6 +502,7 @@ public class DefaultMetadata extends ISO
     @Deprecated
     @XmlElement(name = "locale")
     @XmlJavaTypeAdapter(PT_Locale.class)
+    @Dependencies("getLanguages")
     public Collection<Locale> getLocales() {
         return OtherLocales.filter(getLanguages());
     }
@@ -567,6 +571,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "characterSet")
+    @Dependencies("getCharacterSets")
     public CharacterSet getCharacterSet() {
         final Charset cs = LegacyPropertyAdapter.getSingleton(getCharacterSets(),
                 Charset.class, null, DefaultMetadata.class, "getCharacterSet");
@@ -631,6 +636,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "parentIdentifier")
+    @Dependencies("getParentMetadata")
     public String getParentIdentifier() {
         final Citation parentMetadata = getParentMetadata();
         if (parentMetadata != null) {
@@ -652,7 +658,8 @@ public class DefaultMetadata extends ISO
     @Deprecated
     public void setParentIdentifier(final String newValue) {
         checkWritePermission();
-        DefaultCitation parent = DefaultCitation.castOrCopy(parentMetadata); // See "Note about deprecated methods implementation"
+        // See "Note about deprecated methods implementation"
+        DefaultCitation parent = DefaultCitation.castOrCopy(parentMetadata);
         if (parent == null) {
             parent = new DefaultCitation();
         }
@@ -694,6 +701,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "hierarchyLevel")
+    @Dependencies("getMetadataScopes")
     public final Collection<ScopeCode> getHierarchyLevels() {
         return new MetadataScopeAdapter<ScopeCode>(getMetadataScopes()) {
             /** Stores a legacy value into the new kind of value. */
@@ -742,6 +750,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "hierarchyLevelName")
+    @Dependencies("getMetadataScopes")
     public final Collection<String> getHierarchyLevelNames() {
         return new MetadataScopeAdapter<String>(getMetadataScopes()) {
             /** Stores a legacy value into the new kind of value. */
@@ -837,6 +846,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "dateStamp", required = true)
+    @Dependencies("getDateInfo")
     public Date getDateStamp() {
         final Collection<CitationDate> dates = getDateInfo();
         if (dates != null) {
@@ -1018,6 +1028,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "metadataStandardName")
+    @Dependencies("getMetadataStandards")
     public String getMetadataStandardName() {
         return getMetadataStandard(false);
     }
@@ -1046,6 +1057,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "metadataStandardVersion")
+    @Dependencies("getMetadataStandards")
     public String getMetadataStandardVersion() {
         return getMetadataStandard(true);
     }
@@ -1097,6 +1109,7 @@ public class DefaultMetadata extends ISO
     @Override
     @Deprecated
     @XmlElement(name = "dataSetURI")
+    @Dependencies("getIdentificationInfo")
     public String getDataSetUri() {
         String linkage = null;
         final Collection<Identification> info = getIdentificationInfo();

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultContact.java [UTF-8] Fri May 26 13:05:43 2017
@@ -31,6 +31,7 @@ import org.opengis.metadata.citation.Tel
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.internal.jaxb.Context;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 
 
@@ -217,6 +218,7 @@ public class DefaultContact extends ISOM
     @Override
     @Deprecated
     @XmlElement(name = "phone")
+    @Dependencies("getPhones")
     public Telephone getPhone() {
         Telephone phone = null;
         final Collection<Telephone> phones = getPhones();
@@ -301,6 +303,7 @@ public class DefaultContact extends ISOM
     @Override
     @Deprecated
     @XmlElement(name = "address")
+    @Dependencies("getAddresses")
     public Address getAddress() {
         return LegacyPropertyAdapter.getSingleton(getAddresses(), Address.class, null, DefaultContact.class, "getAddress");
     }
@@ -352,6 +355,7 @@ public class DefaultContact extends ISOM
     @Override
     @Deprecated
     @XmlElement(name = "onlineResource")
+    @Dependencies("getOnlineResources")
     public OnlineResource getOnlineResource() {
         return LegacyPropertyAdapter.getSingleton(getOnlineResources(), OnlineResource.class, null, DefaultContact.class, "getOnlineResource");
     }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultResponsibleParty.java [UTF-8] Fri May 26 13:05:43 2017
@@ -31,6 +31,7 @@ import org.opengis.metadata.citation.Res
 import org.opengis.metadata.citation.Role;
 import org.opengis.util.InternationalString;
 import org.apache.sis.util.iso.Types;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 
 
@@ -158,7 +159,7 @@ public class DefaultResponsibleParty ext
             final Class<? extends Party> type, final boolean position)
     {
         InternationalString name = null;
-        if (parties != null) { // May be null on marshalling.
+        if (parties != null) {                              // May be null on marshalling.
             for (final Party party : parties) {
                 if (type.isInstance(party)) {
                     if (name != null) {
@@ -215,6 +216,7 @@ public class DefaultResponsibleParty ext
     @Override
     @Deprecated
     @XmlElement(name = "individualName")
+    @Dependencies("getParties")
     public String getIndividualName() {
         final InternationalString name = getIndividual(false);
         return (name != null) ? name.toString() : null;
@@ -254,6 +256,7 @@ public class DefaultResponsibleParty ext
     @Override
     @Deprecated
     @XmlElement(name = "organisationName")
+    @Dependencies("getParties")
     public InternationalString getOrganisationName() {
         return getName(getParties(), Organisation.class, false);
     }
@@ -293,6 +296,7 @@ public class DefaultResponsibleParty ext
     @Override
     @Deprecated
     @XmlElement(name = "positionName")
+    @Dependencies("getParties")
     public InternationalString getPositionName() {
         return getIndividual(true);
     }
@@ -329,6 +333,7 @@ public class DefaultResponsibleParty ext
     @Override
     @Deprecated
     @XmlElement(name = "contactInfo")
+    @Dependencies("getParties")
     public Contact getContactInfo() {
         final Collection<Party> parties = getParties();
         if (parties != null) { // May be null on marshalling.

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultTelephone.java [UTF-8] Fri May 26 13:05:43 2017
@@ -26,6 +26,7 @@ import org.opengis.metadata.citation.Tel
 import org.opengis.metadata.citation.TelephoneType;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.metadata.iso.ISOMetadata;
+import org.apache.sis.internal.metadata.Dependencies;
 
 
 /**
@@ -264,6 +265,7 @@ public class DefaultTelephone extends IS
     @Override
     @Deprecated
     @XmlElement(name = "voice")
+    @Dependencies({"getNumber", "getNumberType"})
     public final Collection<String> getVoices() {
         return new LegacyTelephones(getOwner(), TelephoneType.VOICE);
     }
@@ -296,6 +298,7 @@ public class DefaultTelephone extends IS
     @Override
     @Deprecated
     @XmlElement(name = "facsimile")
+    @Dependencies({"getNumber", "getNumberType"})
     public final Collection<String> getFacsimiles() {
         return new LegacyTelephones(getOwner(), TelephoneType.FACSIMILE);
     }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java [UTF-8] Fri May 26 13:05:43 2017
@@ -31,6 +31,7 @@ import org.opengis.metadata.content.Rang
 import org.opengis.metadata.content.RangeElementDescription;
 import org.opengis.util.RecordType;
 import org.apache.sis.xml.Namespaces;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 
 
@@ -228,13 +229,14 @@ public class DefaultCoverageDescription
     @Override
     @Deprecated
     @XmlElement(name = "contentType", required = true)
+    @Dependencies("getAttributeGroups")
     public CoverageContentType getContentType() {
         CoverageContentType type = null;
         final Collection<AttributeGroup> groups = getAttributeGroups();
-        if (groups != null) { // May be null on marshalling.
+        if (groups != null) {                                               // May be null on marshalling.
             for (final AttributeGroup g : groups) {
                 final Collection<? extends CoverageContentType> contentTypes = g.getContentTypes();
-                if (contentTypes != null) { // May be null on marshalling.
+                if (contentTypes != null) {                                 // May be null on marshalling.
                     for (final CoverageContentType t : contentTypes) {
                         if (type == null) {
                             type = t;
@@ -292,6 +294,7 @@ public class DefaultCoverageDescription
     @Override
     @Deprecated
     @XmlElement(name = "dimension")
+    @Dependencies("getAttributeGroups")
     public final Collection<RangeDimension> getDimensions() {
         return new LegacyPropertyAdapter<RangeDimension,AttributeGroup>(getAttributeGroups()) {
             /** Stores a legacy value into the new kind of value. */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultFeatureCatalogueDescription.java [UTF-8] Fri May 26 13:05:43 2017
@@ -25,6 +25,7 @@ import org.opengis.util.GenericName;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.content.FeatureCatalogueDescription;
 import org.opengis.metadata.content.FeatureTypeInfo;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 
 
@@ -239,6 +240,7 @@ public class DefaultFeatureCatalogueDesc
     @Override
     @Deprecated
     @XmlElement(name = "featureTypes")
+    @Dependencies("getFeatureTypeInfo")
     public final Collection<GenericName> getFeatureTypes() {
         return new LegacyPropertyAdapter<GenericName,FeatureTypeInfo>(getFeatureTypeInfo()) {
             /** Stores a legacy value into the new kind of value. */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeDimension.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeDimension.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeDimension.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultRangeDimension.java [UTF-8] Fri May 26 13:05:43 2017
@@ -28,6 +28,7 @@ import org.opengis.metadata.content.Rang
 import org.opengis.metadata.content.SampleDimension;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.metadata.TitleProperty;
+import org.apache.sis.internal.metadata.Dependencies;
 
 
 /**
@@ -193,6 +194,7 @@ public class DefaultRangeDimension exten
     @Override
     @Deprecated
     @XmlElement(name = "descriptor")
+    @Dependencies("getDescription")
     public InternationalString getDescriptor() {
         return getDescription();
     }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultDigitalTransferOptions.java [UTF-8] Fri May 26 13:05:43 2017
@@ -29,6 +29,7 @@ import org.opengis.metadata.distribution
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 import org.apache.sis.measure.ValueRange;
 import org.apache.sis.metadata.iso.ISOMetadata;
+import org.apache.sis.internal.metadata.Dependencies;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.ensurePositive;
 
@@ -257,6 +258,7 @@ public class DefaultDigitalTransferOptio
     @Override
     @Deprecated
     @XmlElement(name = "offLine")
+    @Dependencies("getOffLines")
     public Medium getOffLine() {
         return LegacyPropertyAdapter.getSingleton(getOffLines(), Medium.class, null, DefaultDigitalTransferOptions.class, "getOffLine");
     }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultFormat.java [UTF-8] Fri May 26 13:05:43 2017
@@ -26,6 +26,7 @@ import org.opengis.metadata.citation.Cit
 import org.opengis.metadata.distribution.Format;
 import org.opengis.metadata.distribution.Medium;
 import org.opengis.metadata.distribution.Distributor;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
 import org.apache.sis.metadata.iso.ISOMetadata;
@@ -246,6 +247,7 @@ public class DefaultFormat extends ISOMe
     @Override
     @Deprecated
     @XmlElement(name = "specification")
+    @Dependencies("getFormatSpecificationCitation")
     public InternationalString getSpecification() {
         final Citation citation = getFormatSpecificationCitation();
         return (citation != null) ? citation.getTitle() : null;
@@ -278,6 +280,7 @@ public class DefaultFormat extends ISOMe
     @Override
     @Deprecated
     @XmlElement(name = "name", required = true)
+    @Dependencies("getFormatSpecificationCitation")
     public InternationalString getName() {
         final Citation citation = getFormatSpecificationCitation();
         if (citation != null) {
@@ -315,6 +318,7 @@ public class DefaultFormat extends ISOMe
     @Override
     @Deprecated
     @XmlElement(name = "version", required = true)
+    @Dependencies("getFormatSpecificationCitation")
     public InternationalString getVersion() {
         final Citation citation = getFormatSpecificationCitation();
         return (citation != null) ? citation.getEdition() : null;

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/distribution/DefaultMedium.java [UTF-8] Fri May 26 13:05:43 2017
@@ -32,6 +32,7 @@ import org.apache.sis.measure.ValueRange
 import org.apache.sis.metadata.TitleProperty;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.internal.jaxb.NonMarshalledAuthority;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 
 import static org.apache.sis.internal.metadata.MetadataUtilities.ensurePositive;
@@ -223,6 +224,7 @@ public class DefaultMedium extends ISOMe
     @Override
     @Deprecated
     @XmlElement(name = "density")
+    @Dependencies("getDensity")
     public Collection<Double> getDensities() {
         return new AbstractSet<Double>() {
             /** Returns 0 if empty, or 1 if a density has been specified. */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/AbstractIdentification.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/AbstractIdentification.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/AbstractIdentification.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/AbstractIdentification.java [UTF-8] Fri May 26 13:05:43 2017
@@ -42,6 +42,7 @@ import org.opengis.metadata.maintenance.
 import org.opengis.metadata.spatial.SpatialRepresentationType;
 import org.opengis.temporal.Duration;
 import org.opengis.util.InternationalString;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.util.iso.Types;
@@ -742,6 +743,7 @@ public class AbstractIdentification exte
     @Override
     @Deprecated
     @XmlElement(name = "aggregationInfo")
+    @Dependencies("getAssociatedResources")
     public Collection<AggregateInformation> getAggregationInfo() {
         return new LegacyPropertyAdapter<AggregateInformation,AssociatedResource>(getAssociatedResources()) {
             @Override protected AssociatedResource wrap(final AggregateInformation value) {

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultAggregateInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultAggregateInformation.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultAggregateInformation.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultAggregateInformation.java [UTF-8] Fri May 26 13:05:43 2017
@@ -29,6 +29,7 @@ import org.opengis.metadata.identificati
 import org.opengis.metadata.identification.AssociationType;
 import org.opengis.metadata.identification.InitiativeType;
 import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.internal.metadata.Dependencies;
 
 
 /**
@@ -124,6 +125,7 @@ public class DefaultAggregateInformation
     @Override
     @Deprecated
     @XmlElement(name = "aggregateDataSetName")
+    @Dependencies("getName")
     public Citation getAggregateDataSetName() {
         return getName();
     }
@@ -150,6 +152,7 @@ public class DefaultAggregateInformation
     @Override
     @Deprecated
     @XmlElement(name = "aggregateDataSetIdentifier")
+    @Dependencies("getName")
     public Identifier getAggregateDataSetIdentifier() {
         return getAggregateDataSetIdentifier(getAggregateDataSetName());
     }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/lineage/DefaultSource.java [UTF-8] Fri May 26 13:05:43 2017
@@ -37,6 +37,7 @@ import org.apache.sis.metadata.TitleProp
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.metadata.iso.maintenance.DefaultScope;
 import org.apache.sis.metadata.iso.identification.DefaultResolution;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.xml.Namespaces;
 
@@ -251,6 +252,7 @@ public class DefaultSource extends ISOMe
     @Override
     @Deprecated
     @XmlElement(name = "scaleDenominator")
+    @Dependencies("getSourceSpatialResolution")
     public RepresentativeFraction getScaleDenominator() {
         final Resolution resolution = getSourceSpatialResolution();
         return (resolution != null) ? resolution.getEquivalentScale() : null;
@@ -391,6 +393,7 @@ public class DefaultSource extends ISOMe
     @Override
     @Deprecated
     @XmlElement(name = "sourceExtent")
+    @Dependencies("getScope")
     public Collection<Extent> getSourceExtents() {
         Scope scope = getScope();
         if (!(scope instanceof DefaultScope)) {

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java [UTF-8] Fri May 26 13:05:43 2017
@@ -36,6 +36,7 @@ import org.opengis.util.InternationalStr
 import org.apache.sis.metadata.iso.ISOMetadata;
 import org.apache.sis.metadata.iso.citation.DefaultCitationDate;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
+import org.apache.sis.internal.metadata.Dependencies;
 
 
 /**
@@ -230,6 +231,7 @@ public class DefaultMaintenanceInformati
     @Override
     @Deprecated
     @XmlElement(name = "dateOfNextUpdate")
+    @Dependencies("getMaintenanceDates")
     public Date getDateOfNextUpdate() {
         final Collection<CitationDate> dates = getMaintenanceDates();
         if (dates != null) { // May be null on XML marshalling.
@@ -336,6 +338,7 @@ public class DefaultMaintenanceInformati
     @Override
     @Deprecated
     @XmlElement(name = "updateScope")
+    @Dependencies("getMaintenanceScopes")
     public final Collection<ScopeCode> getUpdateScopes() {
         return new LegacyPropertyAdapter<ScopeCode,Scope>(getMaintenanceScopes()) {
             /** Stores a legacy value into the new kind of value. */
@@ -386,6 +389,7 @@ public class DefaultMaintenanceInformati
     @Override
     @Deprecated
     @XmlElement(name = "updateScopeDescription")
+    @Dependencies("getMaintenanceScopes")
     public final Collection<ScopeDescription> getUpdateScopeDescriptions() {
         return new LegacyPropertyAdapter<ScopeDescription,Scope>(getMaintenanceScopes()) {
             /** Stores a legacy value into the new kind of value. */

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java [UTF-8] Fri May 26 13:05:43 2017
@@ -21,6 +21,7 @@ import javax.xml.bind.annotation.XmlTran
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.quality.Scope;
 import org.opengis.metadata.maintenance.ScopeCode;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.internal.metadata.LegacyPropertyAdapter;
 
 
@@ -117,6 +118,7 @@ public class DefaultScope extends org.ap
      */
     @Override
     @Deprecated
+    @Dependencies("getExtents")
     public Extent getExtent() {
         return LegacyPropertyAdapter.getSingleton(getExtents(), Extent.class, null, DefaultScope.class, "getExtent");
     }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Dispatcher.java [UTF-8] Fri May 26 13:05:43 2017
@@ -25,9 +25,11 @@ import org.apache.sis.util.Classes;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.collection.BackingStoreException;
 import org.apache.sis.internal.util.CollectionsExt;
+import org.apache.sis.metadata.MetadataStandard;
 import org.apache.sis.metadata.KeyNamePolicy;
 import org.apache.sis.metadata.ValueExistencePolicy;
 import org.apache.sis.internal.system.Semaphores;
+import org.apache.sis.internal.metadata.Dependencies;
 
 
 /**
@@ -125,13 +127,11 @@ final class Dispatcher implements Invoca
      */
     @Override
     public Object invoke(final Object proxy, final Method method, final Object[] args) {
-        final Class<?> type = method.getDeclaringClass();
-        final String   name = method.getName();
-        final int      n    = (args != null) ? args.length : 0;
-        switch (name) {
+        final int n = (args != null) ? args.length : 0;
+        switch (method.getName()) {
             case "toString": {
                 if (n != 0) break;
-                return toString(type);
+                return toString(method.getDeclaringClass());
             }
             case "hashCode": {
                 if (n != 0) break;
@@ -146,28 +146,80 @@ final class Dispatcher implements Invoca
                 return (args[0] == source) ? identifier : null;
             }
             default: {
-                if (n != 0 || !source.standard.isMetadata(type)) {
-                    throw new BackingStoreException(Errors.format(Errors.Keys.UnsupportedOperation_1,
-                                Classes.getShortName(type) + '.' + name));
+                if (n != 0) break;
+                /*
+                 * The invoked method is a method from the metadata interface.
+                 * Consequently, the information should exist in the database.
+                 * First, we will check the cache. If the value is not present, we will query the database and
+                 * fetch the cache again (because the class that implement the cache may perform some computation).
+                 */
+                Object value;
+                try {
+                    value = fetchValue(source.getLookupInfo(method.getDeclaringClass()), method);
+                } catch (ReflectiveOperationException | SQLException | MetadataStoreException e) {
+                    Class<?> returnType = method.getReturnType();
+                    if (Collection.class.isAssignableFrom(returnType)) {
+                        final Class<?> elementType = Classes.boundOfParameterizedProperty(method);
+                        if (elementType != null) {
+                            returnType = elementType;
+                        }
+                    }
+                    throw new BackingStoreException(Errors.format(Errors.Keys.DatabaseError_2, returnType, identifier), e);
                 }
-                break;
+                /*
+                 * At this point we got the metadata property value, which may be null.
+                 * If the method returns a collection, replace null value by empty set or empty list.
+                 */
+                if (value == null) {
+                    final Class<?> returnType = method.getReturnType();
+                    if (Collection.class.isAssignableFrom(returnType)) {
+                        value = CollectionsExt.empty(returnType);
+                    }
+                }
+                return value;
             }
         }
         /*
-         * The invoked method is a method from the metadata interface.
-         * Consequently, the information should exist in the database.
-         * First, we will check the cache. If the value is not present, we will query the database and
-         * fetch the cache again (because the class that implement the cache may perform some computation).
+         * Unknown method invoked, or wrong number of arguments.
          */
+        throw new BackingStoreException(Errors.format(Errors.Keys.UnsupportedOperation_1,
+                    Classes.getShortName(method.getDeclaringClass()) + '.' + method.getName()));
+    }
+
+    /**
+     * Gets, computes or read from the database a metadata property value.
+     * This method returns the first non-null value in the following choices:
+     *
+     * <ol>
+     *   <li>If the property value is present in the {@linkplain #cache}, the cached value.</li>
+     *   <li>If the "cache" can compute the value from other property values, the result of that computation.
+     *       This case happen mostly for deprecated properties that are replaced by one or more newer properties.</li>
+     *   <li>The value stored in the database. The database is queried only once for the requested property
+     *       and the result is cached for future reuse.</li>
+     * </ol>
+     *
+     * @param  info    information related to the <em>interface</em> of the metadata object for which a property
+     *                 value is requested. This is used for fetching information from the {@link MetadataStandard}.
+     * @param  method  the method to be invoked. The class given by {@link Method#getDeclaringClass()} is usually
+     *                 the same than the one given by {@link LookupInfo#getMetadataType()}, but not necessarily.
+     *                 The two classes may differ if the method is declared only in the implementation class.
+     * @return the property value, or {@code null} if none.
+     * @throws ReflectiveOperationException if an error occurred while querying the {@link #cache}.
+     * @throws SQLException if an error occurred while querying the database.
+     * @throws MetadataStoreException if a value was not found or can not be converted to the expected type.
+     */
+    private Object fetchValue(final LookupInfo info, final Method method)
+            throws ReflectiveOperationException, SQLException, MetadataStoreException
+    {
         Object value = null;
-        final LookupInfo info = source.getLookupInfo(type);
         final long nullBit = 1L << info.asIndexMap(source.standard).get(method.getName());     // Okay even if overflow.
         /*
          * The NULL_COLLECTION semaphore prevents creation of new empty collections by getter methods
          * (a consequence of lazy instantiation). The intend is to avoid creation of unnecessary objects
          * for all unused properties. Users should not see behavioral difference.
          */
-        if ((nullValues & nullBit) == 0) try {
+        if ((nullValues & nullBit) == 0) {
+            final Class<?> type = info.getMetadataType();
             final boolean allowNull = Semaphores.queryAndSet(Semaphores.NULL_COLLECTION);
             try {
                 Object cache = this.cache;
@@ -199,6 +251,31 @@ final class Dispatcher implements Invoca
                                 value = method.invoke(cache);
                             }
                         }
+                    } else {
+                        /*
+                         * If we found no explicit value for the requested property, maybe it is a deprecated property
+                         * computed from other property values and those other properties have not yet been stored in
+                         * the cache object (because that "cache" is also the object computing deprecated properties).
+                         */
+                        final Class<?> impl = source.standard.getImplementation(type);
+                        if (impl != null) {
+                            final Dependencies dependencies = impl.getMethod(method.getName()).getAnnotation(Dependencies.class);
+                            if (dependencies != null) {
+                                boolean hasValue = false;
+                                for (final String dep : dependencies.value()) {
+                                    info.setMetadataType(type);
+                                    hasValue |= (fetchValue(info, impl.getMethod(dep)) != null);
+                                }
+                                if (hasValue) {
+                                    cache = this.cache;             // Created by recursive 'invoke(…)' call above.
+                                    if (cache != null) {
+                                        synchronized (cache) {
+                                            value = method.invoke(cache);             // Attempt a new computation.
+                                        }
+                                    }
+                                }
+                            }
+                        }
                     }
                 }
             } finally {
@@ -206,22 +283,9 @@ final class Dispatcher implements Invoca
                     Semaphores.clear(Semaphores.NULL_COLLECTION);
                 }
             }
-        } catch (ReflectiveOperationException | SQLException | MetadataStoreException e) {
-            Class<?> returnType = method.getReturnType();
-            if (Collection.class.isAssignableFrom(returnType)) {
-                final Class<?> elementType = Classes.boundOfParameterizedProperty(method);
-                if (elementType != null) {
-                    returnType = elementType;
-                }
-            }
-            throw new BackingStoreException(Errors.format(Errors.Keys.DatabaseError_2, returnType, identifier), e);
         }
         if (value == null) {
             nullValues |= nullBit;
-            final Class<?> returnType = method.getReturnType();
-            if (Collection.class.isAssignableFrom(returnType)) {
-                value = CollectionsExt.empty(returnType);
-            }
         }
         return value;
     }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java [UTF-8] Fri May 26 13:05:43 2017
@@ -906,14 +906,11 @@ public class MetadataSource implements A
             }
         }
         /*
-         * Now converts the value to its final type, including conversion of null
-         * value to empty collections if the return value should be a collection.
+         * Now converts the value to its final type. To be strict, we should convert null values into empty collections
+         * if the return type is a collection type. But we leave this task to the caller (which is the Dispatcher class)
+         * for making easier to detect when a value is absent, for allowing Dispatcher to manage its cache.
          */
-        if (value == null) {
-            if (wantCollection) {
-                return CollectionsExt.empty(returnType);
-            }
-        } else {
+        if (value != null) {
             if (isMetadata) {
                 value = lookup(elementType, value.toString());
             } else try {

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/MetadataTestCase.java [UTF-8] Fri May 26 13:05:43 2017
@@ -20,12 +20,15 @@ import java.util.Date;
 import java.util.Locale;
 import java.util.Random;
 import java.util.Collection;
+import java.util.Map;
+import java.lang.reflect.Method;
 import org.opengis.util.CodeList;
 import org.opengis.util.ControlledVocabulary;
 import org.apache.sis.util.Numbers;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.collection.CheckedContainer;
 import org.apache.sis.internal.util.CollectionsExt;
+import org.apache.sis.internal.metadata.Dependencies;
 import org.apache.sis.test.AnnotationsTestCase;
 import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.DependsOn;
@@ -112,7 +115,7 @@ public abstract strictfp class MetadataT
      * @param  type      the type of value to create.
      * @return the value of the given {@code type}, or of a type convertible to the given type.
      */
-    protected Object valueFor(final String property, final Class<?> type) {
+    protected Object sampleValueFor(final String property, final Class<?> type) {
         if (CharSequence.class.isAssignableFrom(type)) {
             return "Dummy value for " + property + '.';
         }
@@ -266,7 +269,7 @@ public abstract strictfp class MetadataT
                 fail("Non writable property: " + accessor + '.' + property);
             }
             if (isWritable) {
-                final Object newValue = valueFor(property, elementType);
+                final Object newValue = sampleValueFor(property, elementType);
                 final Object oldValue = accessor.set(i, instance, newValue, PropertyAccessor.RETURN_PREVIOUS);
                 assertEquals("PropertyAccessor.set(…) shall return the value previously returned by get(…).", value, oldValue);
                 value = accessor.get(i, instance);
@@ -333,5 +336,51 @@ public abstract strictfp class MetadataT
                 }
             }
         }
+    }
+
+    /**
+     * Verifies the {@link Dependencies} annotations. This method verifies that the annotation is applied on
+     * deprecated getter methods, that the referenced properties exist and the getter methods of referenced
+     * properties are not deprecated.
+     *
+     * @throws NoSuchMethodException if {@link PropertyAccessor} references a non-existent method (would be a bug).
+     *
+     * @since 0.8
+     */
+    @Test
+    public void testDependenciesAnnotation() throws NoSuchMethodException {
+        for (final Class<?> type : types) {
+            final Class<?> impl = standard.getImplementation(type);
+            if (impl != null) {
+                Map<String,String> names = null;
+                for (final Method method : impl.getDeclaredMethods()) {
+                    final Dependencies dep = method.getAnnotation(Dependencies.class);
+                    if (dep != null) {
+                        final String name = method.getName();
+                        if (names == null) {
+                            names = standard.asNameMap(type, KeyNamePolicy.JAVABEANS_PROPERTY, KeyNamePolicy.METHOD_NAME);
+                        }
+                        /*
+                         * Currently, @Dependencies is applied only on deprecated getter methods.
+                         * However this policy may change in future Apache SIS versions.
+                         */
+                        assertTrue(name, name.startsWith("get"));
+                        assertTrue(name, method.isAnnotationPresent(Deprecated.class));
+                        /*
+                         * All dependencies shall be non-deprecated methods. Combined with above
+                         * restriction about @Dependencies applied only on deprected methods, this
+                         * ensure that there is no cycle.
+                         */
+                        for (final String ref : dep.value()) {
+                            // Verify that the dependency is a property name.
+                            assertEquals(name, names.get(ref), ref);
+
+                            // Verify that the referenced method is non-deprecated.
+                            assertFalse(name, impl.getMethod(names.get(ref)).isAnnotationPresent(Deprecated.class));
+                        }
+                    }
+                }
+            }
+        }
     }
 }

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java?rev=1796282&r1=1796281&r2=1796282&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataWriterTest.java [UTF-8] Fri May 26 13:05:43 2017
@@ -16,15 +16,19 @@
  */
 package org.apache.sis.metadata.sql;
 
+import java.util.Collections;
 import javax.sql.DataSource;
 import org.postgresql.ds.PGSimpleDataSource;
+import org.opengis.metadata.citation.Contact;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.PresentationForm;
 import org.opengis.metadata.citation.OnLineFunction;
 import org.opengis.metadata.citation.OnlineResource;
 import org.opengis.metadata.citation.Role;
+import org.opengis.metadata.citation.Telephone;
 import org.apache.sis.internal.metadata.sql.TestDatabase;
 import org.apache.sis.metadata.iso.citation.HardCodedCitations;
+import org.apache.sis.metadata.iso.citation.DefaultTelephone;
 import org.apache.sis.metadata.MetadataStandard;
 import org.apache.sis.test.TestUtilities;
 import org.apache.sis.test.TestCase;
@@ -70,6 +74,7 @@ public final strictfp class MetadataWrit
             write();
             search();
             read();
+            readWriteDeprecated();
             source.close();
         } finally {
             TestDatabase.drop(ds);
@@ -93,6 +98,7 @@ public final strictfp class MetadataWrit
             write();
             search();
             read();
+            readWriteDeprecated();
         } finally {
             source.close();
         }
@@ -158,8 +164,15 @@ public final strictfp class MetadataWrit
 
         final Party party = TestUtilities.getSingleton(responsible.getParties());
         assertEquals("International Association of Oil & Gas Producers", party.getName().toString());
-
-        OnlineResource resource = TestUtilities.getSingleton(TestUtilities.getSingleton(party.getContactInfo()).getOnlineResources());
+        final Contact contact = TestUtilities.getSingleton(party.getContactInfo());
+        /*
+         * Invoke for the deprecated 'getOnlineResource()' method (singular form) before the non-deprecated
+         * 'getOnlineResources()' (plural form) replacement. They shall give the same result no matter which
+         * form were stored in the database.
+         */
+        @SuppressWarnings("deprecation")
+        final OnlineResource resource = contact.getOnlineResource();
+        assertSame(resource, TestUtilities.getSingleton(contact.getOnlineResources()));
         assertEquals("http://www.epsg.org", resource.getLinkage().toString());
         assertEquals(OnLineFunction.INFORMATION, resource.getFunction());
         /*
@@ -181,4 +194,28 @@ public final strictfp class MetadataWrit
         assertEquals("EPSG", source.proxy (c));
         assertEquals("EPSG", source.search(c));
     }
+
+    /**
+     * Read and write a metadata object containing deprecated properties.
+     * The metadata tested by this method is:
+     *
+     * {@preformat text
+     *   Telephone
+     *     ├─Number………………… 01.02.03.04
+     *     └─Number type…… Voice
+     * }
+     *
+     * The metadata should be stored in columns named {@code "number"} and {@code "numberType"} even if we
+     * constructed the metadata using the deprecated {@code "voice"} property. Conversely, at reading time
+     * the deprecated {@code "voice"} property should be converted in reading of non-deprecated properties.
+     */
+    @SuppressWarnings("deprecation")
+    private void readWriteDeprecated() throws MetadataStoreException {
+        final DefaultTelephone tel = new DefaultTelephone();
+        tel.setVoices(Collections.singleton("01.02.03.04"));
+        assertEquals("01.02.03.04", source.add(tel));
+
+        final Telephone check = source.lookup(Telephone.class, "01.02.03.04");
+        assertEquals("01.02.03.04", TestUtilities.getSingleton(check.getVoices()));
+    }
 }



Mime
View raw message