sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1640671 - in /sis/branches/JDK6: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/ core/sis-metadata/src/main/java/org/apache/sis/metadata/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ core/sis-metadata/...
Date Thu, 20 Nov 2014 04:28:46 GMT
Author: desruisseaux
Date: Thu Nov 20 04:28:46 2014
New Revision: 1640671

URL: http://svn.apache.org/r1640671
Log:
Merge from the JDK7 branch: update for GeoAPI change: use Obligation Enum instead than CodeList,
for ISO 19115 compliance.

Modified:
    sis/branches/JDK6/   (props changed)
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_ObligationCode.java
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
    sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
    sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java
    sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
    sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java

Propchange: sis/branches/JDK6/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK8:r1640591-1640667
  Merged /sis/branches/JDK7:r1640592-1640670

Modified: sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_ObligationCode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_ObligationCode.java?rev=1640671&r1=1640670&r2=1640671&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_ObligationCode.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/MD_ObligationCode.java
[UTF-8] Thu Nov 20 04:28:46 2014
@@ -16,9 +16,9 @@
  */
 package org.apache.sis.internal.jaxb.code;
 
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import org.opengis.metadata.Obligation;
-import org.apache.sis.util.iso.Types;
+import javax.xml.bind.annotation.XmlElement;
+import org.opengis.annotation.Obligation;
+import org.apache.sis.internal.jaxb.gmd.EnumAdapter;
 
 
 /**
@@ -28,32 +28,46 @@ import org.apache.sis.util.iso.Types;
  *
  * @author  Cédric Briançon (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @version 0.5
  * @module
  */
-public final class MD_ObligationCode extends XmlAdapter<String, Obligation> {
+public final class MD_ObligationCode extends EnumAdapter<MD_ObligationCode, Obligation>
{
     /**
-     * Returns the obligation enumeration for the given name.
+     * The enumeration value.
+     */
+    @XmlElement(name = "MD_ObligationCode")
+    private String value;
+
+    /**
+     * Empty constructor for JAXB only.
+     */
+    public MD_ObligationCode() {
+    }
+
+    /**
+     * Returns the wrapped value.
      *
-     * @param value The obligation name.
-     * @return The obligation enumeration for the given name.
+     * @param wrapper The wrapper.
+     * @return The wrapped value.
      */
     @Override
-    public Obligation unmarshal(String value) {
-        return Types.forCodeName(Obligation.class, value, true);
+    public final Obligation unmarshal(final MD_ObligationCode wrapper) {
+        return Obligation.valueOf(name(wrapper.value));
     }
 
     /**
-     * Returns the name of the given obligation.
+     * Wraps the given value.
      *
-     * @param value The obligation enumeration.
-     * @return The name of the given obligation.
+     * @param  e The value to wrap.
+     * @return The wrapped value.
      */
     @Override
-    public String marshal(final Obligation value) {
-        if (value == null) {
+    public final MD_ObligationCode marshal(final Obligation e) {
+        if (e == null) {
             return null;
         }
-        return value.name();
+        final MD_ObligationCode wrapper = new MD_ObligationCode();
+        wrapper.value = value(e);
+        return wrapper;
     }
 }

Modified: sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java?rev=1640671&r1=1640670&r2=1640671&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/PropertyInformation.java
[UTF-8] Thu Nov 20 04:28:46 2014
@@ -21,8 +21,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.lang.reflect.Method;
 import org.opengis.annotation.UML;
+import org.opengis.annotation.Obligation;
 import org.opengis.metadata.Datatype;
-import org.opengis.metadata.Obligation;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.ExtendedElementInformation;
 import org.opengis.metadata.citation.Responsibility;

Modified: sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java?rev=1640671&r1=1640670&r2=1640671&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/DefaultExtendedElementInformation.java
[UTF-8] Thu Nov 20 04:28:46 2014
@@ -22,8 +22,8 @@ import java.util.Iterator;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import org.opengis.annotation.Obligation;
 import org.opengis.metadata.Datatype;
-import org.opengis.metadata.Obligation;
 import org.opengis.metadata.citation.Responsibility;
 import org.opengis.metadata.ExtendedElementInformation;
 import org.opengis.util.InternationalString;

Modified: sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java?rev=1640671&r1=1640670&r2=1640671&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/PropertyInformationTest.java
[UTF-8] Thu Nov 20 04:28:46 2014
@@ -18,8 +18,8 @@ package org.apache.sis.metadata;
 
 import java.util.Locale;
 import org.opengis.util.InternationalString;
+import org.opengis.annotation.Obligation;
 import org.opengis.metadata.Datatype;
-import org.opengis.metadata.Obligation;
 import org.opengis.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.PresentationForm;

Modified: sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java?rev=1640671&r1=1640670&r2=1640671&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/AllMetadataTest.java
[UTF-8] Thu Nov 20 04:28:46 2014
@@ -60,6 +60,7 @@ public final strictfp class AllMetadataT
     @SuppressWarnings("deprecation")
     public AllMetadataTest() {
         super(MetadataStandard.ISO_19115,
+            org.opengis.annotation.Obligation.class,
             org.opengis.metadata.ApplicationSchemaInformation.class,
             org.opengis.metadata.Datatype.class,
             org.opengis.metadata.ExtendedElementInformation.class,
@@ -68,7 +69,6 @@ public final strictfp class AllMetadataT
             org.opengis.metadata.Metadata.class,
             org.opengis.metadata.MetadataExtensionInformation.class,
             org.opengis.metadata.MetadataScope.class,
-//          org.opengis.metadata.Obligation.class, // Excluded CodeList because it doesn't
use the usual kind of adapter.
             org.opengis.metadata.PortrayalCatalogueReference.class,
             org.opengis.metadata.acquisition.AcquisitionInformation.class,
             org.opengis.metadata.acquisition.Context.class,

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java?rev=1640671&r1=1640670&r2=1640671&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8]
(original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/util/iso/Types.java [UTF-8]
Thu Nov 20 04:28:46 2014
@@ -431,16 +431,22 @@ public final class Types extends Static 
     }
 
     /**
-     * Returns all known values for the given type of code list.
+     * Returns all known values for the given type of code list or enumeration.
      * Note that the size of the returned array may growth between different invocations
of this method,
      * since users can add their own codes to an existing list.
      *
+     * {@note This method works with both <code>Enum</code> and <code>CodeList</code>.
However if the type
+     *        is known to be an <code>Enum</code>, then the standard <code>Class.getEnumConstants()</code>
+     *        method is more efficient.}
+     *
      * @param <T> The compile-time type given as the {@code codeType} parameter.
-     * @param codeType The type of code list.
-     * @return The list of values for the given code list, or an empty array if none.
+     * @param codeType The type of code list or enumeration.
+     * @return The list of values for the given code list or enumeration, or an empty array
if none.
+     *
+     * @see Class#getEnumConstants()
      */
     @SuppressWarnings("unchecked")
-    public static <T extends CodeList<?>> T[] getCodeValues(final Class<T>
codeType) {
+    public static <T extends Enumerated> T[] getCodeValues(final Class<T> codeType)
{
         Object values;
         try {
             values = codeType.getMethod("values", (Class<?>[]) null).invoke(null, (Object[])
null);
@@ -543,11 +549,8 @@ public final class Types extends Static 
         if (name != null && !name.isEmpty()) try {
             return Enum.valueOf(enumType, name);
         } catch (IllegalArgumentException e) {
-            final Enum<?>[] values;
-            try {
-                values = (Enum<?>[]) enumType.getMethod("values", (Class[]) null).invoke((Object[])
null);
-            } catch (Exception r) { // (ReflectiveOperationException | ClassCastException)
on the JDK7 branch.
-                // Should never happen, except if 'enumType' is not an Enum.
+            final T[] values = enumType.getEnumConstants();
+            if (values == null) {
                 throw e;
             }
             if (values instanceof Enumerated[]) {



Mime
View raw message