sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1551090 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/ sis-utility/src/tes...
Date Mon, 16 Dec 2013 00:31:13 GMT
Author: desruisseaux
Date: Mon Dec 16 00:31:12 2013
New Revision: 1551090

URL: http://svn.apache.org/r1551090
Log:
PT_Locale.unmarshall(...) shall use language and country codes together when building the
Locale.

Added:
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java
      - copied, changed from r1550935, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/DataIdentificationMock.java
Removed:
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/DataIdentificationMock.java
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocaleAdapter.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/LanguageCodeTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java?rev=1551090&r1=1551089&r2=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/PT_Locale.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -24,7 +24,6 @@ import javax.xml.bind.annotation.XmlElem
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import org.opengis.metadata.identification.CharacterSet;
-import org.apache.sis.util.Locales;
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.gmd.Country;
@@ -59,7 +58,7 @@ import org.apache.sis.internal.jaxb.gmd.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see LanguageCode
@@ -158,11 +157,11 @@ public final class PT_Locale extends Xml
     }
 
     /**
-     * Substitutes the locale by the adapter to be marshalled into an XML file
+     * Substitutes the locale by the wrapper to be marshalled into an XML file
      * or stream. JAXB calls automatically this method at marshalling time.
      *
      * @param value The locale value.
-     * @return The adapter for the locale value.
+     * @return The wrapper for the locale value.
      */
     @Override
     public PT_Locale marshal(final Locale value) {
@@ -170,10 +169,10 @@ public final class PT_Locale extends Xml
     }
 
     /**
-     * Substitutes the adapter value read from a XML stream by the object which will
+     * Substitutes the wrapped value read from a XML stream by the object which will
      * contains the value. JAXB calls automatically this method at unmarshalling time.
      *
-     * @param value The adapter for this metadata value.
+     * @param value The wrapper for this metadata value.
      * @return A locale which represents the metadata value.
      */
     @Override
@@ -181,18 +180,7 @@ public final class PT_Locale extends Xml
         if (value != null) {
             final Wrapper element = value.element;
             if (element != null) {
-                Locale language = LanguageCode.getLocale(Context.current(), element.languageCode,
true);
-                Locale country  = Country.getLocale(element.country);
-                if (language == null) {
-                    language = country;
-                } else if (country != null) {
-                    // Merge the language and the country in a single Locale instance.
-                    final String c = country.getCountry();
-                    if (!c.equals(language.getCountry())) {
-                        language = Locales.unique(new Locale(language.getLanguage(), c));
-                    }
-                }
-                return language;
+                return Country.getLocale(Context.current(), element.languageCode, element.country);
             }
         }
         return null;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java?rev=1551090&r1=1551089&r2=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -76,13 +76,16 @@ public class GO_CharacterString {
 
     /**
      * The XML element names for each possible {@link #type} values.
+     * Used for formatting error messages.
      */
-    private static final String[] NAMES = new String[4];
-    static {
-        NAMES[0]         = "CharacterString";
-        NAMES[MIME_TYPE] = "MimeFileType";
-        NAMES[FILENAME]  = "FileName";
-        NAMES[ANCHOR]    = "Anchor";
+    private static String nameOf(final byte type) {
+        switch (type) {
+            case 0:         return "CharacterString";
+            case MIME_TYPE: return "MimeFileType";
+            case FILENAME:  return "FileName";
+            case ANCHOR:    return "Anchor";
+            default:        throw new AssertionError(type);
+        }
     }
 
     /**
@@ -136,7 +139,7 @@ public class GO_CharacterString {
                 noset     = true;
             }
             Context.warningOccured(Context.current(), value, getClass(), "setText",
-                    Messages.class, Messages.Keys.DiscardedExclusiveProperty_2, NAMES[discarded],
NAMES[property]);
+                    Messages.class, Messages.Keys.DiscardedExclusiveProperty_2, nameOf(discarded),
nameOf(property));
             if (noset) {
                 return;
             }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java?rev=1551090&r1=1551089&r2=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -19,12 +19,11 @@ package org.apache.sis.internal.jaxb.gmd
 import java.util.Locale;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
-
-import org.apache.sis.util.Locales;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.gco.GO_CharacterString;
 import org.apache.sis.internal.jaxb.gco.CharSequenceAdapter;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -119,30 +118,41 @@ public final class Country extends GO_Ch
     }
 
     /**
-     * Returns the locale for the given country (which may be null), or {@code null} if none.
+     * Returns the locale for the given language and country (which may be null), or {@code
null} if none.
      *
-     * @param value The wrapper for this metadata value.
-     * @return A locale which represents the metadata value.
+     * @param  context The current (un)marshalling context, or {@code null} if none.
+     * @param  language The wrapper for the language value.
+     * @param  country  The wrapper for the country value.
+     * @return A locale which represents the language and country value.
      *
      * @see LanguageCode#getLocale(Context, LanguageCode, boolean)
      */
-    public static Locale getLocale(final Country value) {
-        if (value != null) {
-            final CodeListProxy proxy = value.proxy;
-            String code = null;
-            if (proxy != null) {
-                code = proxy.codeListValue;
-            }
-            // If the country was not specified as a code list,
-            // look for a simple character string declaration.
-            if (code == null) {
-                code = value.toString();
-            }
-            code = CharSequences.trimWhitespaces(code);
-            if (code != null && !code.isEmpty()) {
-                return Locales.unique(new Locale("", code));
+    public static Locale getLocale(final Context context, final LanguageCode language, final
Country country) {
+        String code = null;
+        if (language != null) {
+            code = language.getLanguage();
+        }
+        if (country != null) {
+            final CodeListProxy proxy = country.proxy;
+            final String c = CharSequences.trimWhitespaces(proxy != null ? proxy.identifier()
: country.toString());
+            if (c != null && !c.isEmpty()) {
+                if (code == null) {
+                    code = "";
+                }
+                int i = code.indexOf('_');
+                if (i < 0) {
+                    code = code + '_' + c;
+                } else {
+                    final int length = code.length();
+                    if (++i == code.length() || code.charAt(i) == '_') {
+                        code = new StringBuilder().append(code, 0, i).append(c).append(code,
i, length).toString();
+                    } else if (!c.equals(CharSequences.token(code, i))) {
+                        Context.warningOccured(context, null, null, "unmarshal", Errors.class,
+                                Errors.Keys.IncompatiblePropertyValue_1, "country");
+                    }
+                }
             }
         }
-        return null;
+        return Context.converter(context).toLocale(context, code);
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java?rev=1551090&r1=1551089&r2=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -19,7 +19,6 @@ package org.apache.sis.internal.jaxb.gmd
 import java.util.Locale;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
-
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.gco.GO_CharacterString;
 import org.apache.sis.internal.jaxb.gco.CharSequenceAdapter;
@@ -43,7 +42,7 @@ import org.apache.sis.internal.jaxb.gco.
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @XmlType(name = "LanguageCode_PropertyType")
@@ -130,30 +129,33 @@ public final class LanguageCode extends 
     }
 
     /**
-     * Returns the locale for the given language (which may be null), or {@code null} if
none.
-     *
-     * @param context The current (un)marshalling context, or {@code null} if none.
-     * @param value The wrapper for this metadata value.
-     * @param useCharSequence Whatever this method should fallback on the
-     *        {@code gco:CharacterString} element if no value were specified for the
-     *        {@code gml:LanguageCode} element.
-     * @return A locale which represents the metadata value.
+     * Returns the language, or {@code null} if none. The language is expected to
+     * be a 2- or 3-letters ISO 639 code, but this is not verified by this method.
      *
-     * @see Country#getLocale(Country)
+     * @return The language code
      */
-    public static Locale getLocale(final Context context, final LanguageCode value, final
boolean useCharSequence) {
-        if (value != null) {
-            final CodeListProxy proxy = value.proxy;
-            if (proxy != null) {
-                final Locale locale = Context.converter(context).toLocale(context, proxy.codeListValue);
-                if (locale != null) {
-                    return locale;
-                }
-            }
-            if (useCharSequence) {
-                return Context.converter(context).toLocale(context, value.toString());
-            }
+    public String getLanguage() {
+        String code;
+        final CodeListProxy proxy = this.proxy;
+        if (proxy != null) {
+            /*
+             * <gmd:language>
+             *   <gmd:LanguageCode codeList="(snip)#LanguageCode" codeListValue="jpn">Japanese</gmd:LanguageCode>
+             * </gmd:language>
+             */
+            code = proxy.identifier(); // May still be null.
+        } else {
+            /*
+             * <gmd:language>
+             *   <gco:CharacterString>jpn</gco:CharacterString>
+             * </gmd:language>
+             */
+            code = toString(); // May still be null.
         }
-        return null;
+        /*
+         * Do not trim whitespaces. We leave that decision to ValueConverter.
+         * The default implementation of ValueConverter does that.
+         */
+        return code;
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocaleAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocaleAdapter.java?rev=1551090&r1=1551089&r2=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocaleAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocaleAdapter.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -18,7 +18,6 @@ package org.apache.sis.internal.jaxb.gmd
 
 import java.util.Locale;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
-import org.apache.sis.internal.jaxb.gco.StringAdapter;
 import org.apache.sis.internal.jaxb.Context;
 
 
@@ -28,14 +27,14 @@ import org.apache.sis.internal.jaxb.Cont
  *
  * {@preformat xml
  *   <gmd:language>
- *     <gco:CharacterString>eng</gco:CharacterString>
+ *     <gmd:LanguageCode codeList="(snip)#LanguageCode" codeListValue="jpn">Japanese</gmd:LanguageCode>
  *   </gmd:language>
  * }
  *
  * @author  Cédric Briançon (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.5)
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see LanguageCode
@@ -58,12 +57,7 @@ public final class LocaleAdapter extends
     @Override
     public Locale unmarshal(final LanguageCode value) {
         final Context context = Context.current();
-        final Locale candidate = LanguageCode.getLocale(context, value, false);
-        if (candidate != null) {
-            return candidate;
-        }
-        final String text = StringAdapter.toString(value);
-        return (text != null) ? Context.converter(context).toLocale(context, text) : null;
+        return Context.converter(context).toLocale(context, value.getLanguage());
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java?rev=1551090&r1=1551089&r2=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -40,10 +40,11 @@ import java.util.Objects;
  */
 final class LocalisedCharacterString {
     /**
-     * A prefix to concatenate with the {@linkplain Locale#getISO3Language() language code}
-     * in order to get the attribute value specified in ISO-19139 for this elements.
+     * A prefix to concatenate with the {@linkplain Locale#getISO3Language() language code}.
+     * This is a hack for a common pattern found in the way locales are specified in ISO
19139 files.
+     * See <a href="https://issues.apache.org/jira/browse/SIS-137">SIS-137</a>
for more information.
      */
-    private static final String LOCALE = "#locale-";
+    private static final String PREFIX = "#locale-";
 
     /**
      * The locale value for this string.
@@ -75,10 +76,10 @@ final class LocalisedCharacterString {
     }
 
     /**
-     * Returns the locale language, as specified by ISO-19139 for
-     * {@code <LocalisedCharacterString>} attribute.
+     * Returns the locale language for {@code <LocalisedCharacterString>} attribute.
      *
      * @return The current locale.
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-137">SIS-137</a>
      */
     @XmlAttribute(name = "locale", required = true)
     public String getLocale() {
@@ -86,7 +87,7 @@ final class LocalisedCharacterString {
             return null;
         }
         final Context context = Context.current();
-        return LOCALE.concat(Context.converter(context).toLanguageCode(context, locale));
+        return PREFIX.concat(Context.converter(context).toLanguageCode(context, locale));
     }
 
     /**
@@ -94,6 +95,7 @@ final class LocalisedCharacterString {
      * where {@code xxx} are the two or three letters representing the language.
      *
      * @param localeId The new locale.
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-137">SIS-137</a>
      */
     public void setLocale(final String localeId) {
         if (localeId != null) {

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/LanguageCodeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/LanguageCodeTest.java?rev=1551090&r1=1551089&r2=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/LanguageCodeTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/LanguageCodeTest.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -23,18 +23,18 @@ import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
-import org.opengis.metadata.identification.DataIdentification;
-import org.apache.sis.test.mock.DataIdentificationMock;
+import org.opengis.metadata.Metadata;
 import org.apache.sis.xml.XML;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
 import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.mock.MetadataMock;
 import org.junit.BeforeClass;
 import org.junit.AfterClass;
 import org.junit.Test;
 
 import static org.apache.sis.test.Assert.*;
-import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
 /**
@@ -42,11 +42,28 @@ import static org.apache.sis.test.TestUt
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.18)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 public final strictfp class LanguageCodeTest extends XMLTestCase {
     /**
+     * XML fragment using the {@code <gco:CharacterString>} construct.
+     */
+    private static final String CHARACTER_STRING = "<gco:CharacterString>jpn</gco:CharacterString>";
+
+    /**
+     * XML fragment using the {@code <gmd:LanguageCode>} construct without attributes.
+     */
+    private static final String LANGUAGE_CODE_WITHOUT_ATTRIBUTE = "<gmd:LanguageCode>jpn</gmd:LanguageCode>";
+
+    /**
+     * XML fragment using the {@code <gmd:LanguageCode>} construct with attributes.
+     */
+    private static final String LANGUAGE_CODE = "<gmd:LanguageCode" +
+            " codeList=\"http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/ML_gmxCodelists.xml#LanguageCode\""
+
+            " codeListValue=\"jpn\">Japanese</gmd:LanguageCode>";
+
+    /**
      * A poll of configured {@link Marshaller} and {@link Unmarshaller}, created when first
needed.
      */
     private static MarshallerPool pool;
@@ -64,7 +81,7 @@ public final strictfp class LanguageCode
         final Map<String,Object> properties = new HashMap<>(4);
         assertNull(properties.put(XML.LOCALE, Locale.UK));
         assertNull(properties.put(XML.TIMEZONE, "UTC"));
-        pool = new MarshallerPool(JAXBContext.newInstance(DataIdentificationMock.class),
properties);
+        pool = new MarshallerPool(JAXBContext.newInstance(MetadataMock.class), properties);
     }
 
     /**
@@ -77,100 +94,131 @@ public final strictfp class LanguageCode
     }
 
     /**
-     * Returns the XML of a data identification element. This method returns the following
string,
-     * where the {@code <gco:CharacterString>} block is replaced by the more complex
-     * {@code <gmd:LanguageCode>} if the {@code languageCode} argument is {@code true}.
+     * Returns the XML of a metadata element. This method returns a string like below,
+     * where the {@code ${languageCode}} string is replaced by the given argument.
      *
      * {@preformat xml
-     *   <gmd:MD_DataIdentification>
+     *   <gmd:MD_Metadata>
      *     <gmd:language>
-     *       <gco:CharacterString>fra</gco:CharacterString>
+     *       ${languageCode}
      *     </gmd:language>
-     *   </gmd:MD_DataIdentification>
+     *   </gmd:MD_Metadata>
      * }
      *
-     * @param languageCode {@code true} for using the {@code gmd:LanguageCode} construct,
-     *        or false for using the {@code gco:CharacterString} construct.
+     * @param languageCode The XML fragment to write inside the {@code <gmd:language>}
element.
      */
-    private static String getDataIdentificationXML(final boolean languageCode) {
-        final StringBuilder buffer = new StringBuilder(
-                "<gmd:MD_DataIdentification" +
-                " xmlns:gmd=\"" + Namespaces.GMD + '"' +
-                " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
-                "  <gmd:language>\n");
-        if (languageCode) {
-            buffer.append("    <gmd:LanguageCode" +
-                    " codeList=\"http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/ML_gmxCodelists.xml#LanguageCode\""
+
-                    " codeListValue=\"fra\">French</gmd:LanguageCode>\n");
-        } else {
-            buffer.append("    <gco:CharacterString>fra</gco:CharacterString>\n");
-        }
-        buffer.append(
-                "  </gmd:language>\n" +
-                "</gmd:MD_DataIdentification>");
-        return buffer.toString();
+    private static String getMetadataXML(final String languageCode) {
+        return "<gmd:MD_Metadata" +
+               " xmlns:gmd=\"" + Namespaces.GMD + '"' +
+               " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
+               "  <gmd:language>\n" +
+               "    " + languageCode + '\n' +
+               "  </gmd:language>\n" +
+               "</gmd:MD_Metadata>";
     }
 
     /**
-     * Tests the parsing of an XML using the {@code gmd:LanguageCode} construct.
+     * Tests marshalling of {@code <gmd:LanguageCode>}.
+     * The result shall be as documented in {@link #testLanguageCode()}.
      *
      * @throws JAXBException Should never happen.
+     *
+     * @see #testMarshallCharacterString()
      */
     @Test
-    public void testLanguageCode() throws JAXBException {
-        final Marshaller   marshaller   = pool.acquireMarshaller();
-        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
-
-        final String xml = getDataIdentificationXML(true);
-        final DataIdentification id = (DataIdentification) unmarshal(unmarshaller, xml);
-        assertEquals(Locale.FRENCH, getSingleton(id.getLanguages()));
-        /*
-         * Reformat and test against the original XML.
-         */
-        assertXmlEquals(xml, marshal(marshaller, id), "xmlns:*");
-        pool.recycle(unmarshaller);
+    public void testMarshallLanguageCode() throws JAXBException {
+        final MetadataMock metadata = new MetadataMock(Locale.JAPANESE);
+        final Marshaller marshaller = pool.acquireMarshaller();
+        assertNull(marshaller.getProperty(XML.STRING_SUBSTITUTES));
+        assertXmlEquals(getMetadataXML(LANGUAGE_CODE), marshal(marshaller, metadata), "xmlns:*");
         pool.recycle(marshaller);
     }
 
     /**
-     * Tests the parsing of an XML using the {@code gco:CharacterString} construct.
+     * Tests the unmarshalling using the {@code <gmd:LanguageCode>} construct. XML
fragment:
+     *
+     * {@preformat xml
+     *   <gmd:MD_Metadata>
+     *     <gmd:language>
+     *       <gmd:LanguageCode codeList="(snip)/ML_gmxCodelists.xml#LanguageCode" codeListValue="jpn">Japanese</gmd:LanguageCode>
+     *     </gmd:language>
+     *   </gmd:MD_Metadata>
+     * }
      *
      * @throws JAXBException Should never happen.
+     *
+     * @see #testMarshallLanguageCode()
      */
     @Test
-    public void testCharacterString() throws JAXBException {
-        final Marshaller   marshaller   = pool.acquireMarshaller();
+    public void testLanguageCode() throws JAXBException {
         final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+        final String xml = getMetadataXML(LANGUAGE_CODE);
+        final Metadata metadata = (Metadata) unmarshal(unmarshaller, xml);
+        assertEquals(Locale.JAPANESE, metadata.getLanguage());
+    }
 
-        final String xml = getDataIdentificationXML(false);
-        final DataIdentification id = (DataIdentification) unmarshal(unmarshaller, xml);
-        assertEquals(Locale.FRENCH, getSingleton(id.getLanguages()));
-        /*
-         * Reformat and test against the expected XML.
-         */
-        assertXmlEquals(getDataIdentificationXML(true), marshal(marshaller, id), "xmlns:*");
+    /**
+     * Tests the unmarshalling using the {@code <gmd:LanguageCode>} construct without
attributes.
+     * The adapter is expected to parse the element value. XML fragment:
+     *
+     * {@preformat xml
+     *   <gmd:MD_Metadata>
+     *     <gmd:language>
+     *       <gmd:LanguageCode>jpn</gmd:LanguageCode>
+     *     </gmd:language>
+     *   </gmd:MD_Metadata>
+     * }
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    @DependsOnMethod("testLanguageCode")
+    public void testLanguageCodeWithoutAttributes() throws JAXBException {
+        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+        final String xml = getMetadataXML(LANGUAGE_CODE_WITHOUT_ATTRIBUTE);
+        final Metadata metadata = (Metadata) unmarshal(unmarshaller, xml);
+        assertEquals(Locale.JAPANESE, metadata.getLanguage());
         pool.recycle(unmarshaller);
-        pool.recycle(marshaller);
     }
 
     /**
-     * Tests the formatting of {@code <gco:CharacterString>}, which require explicit
configuration.
+     * Tests marshalling of {@code <gco:CharacterString>}, which require explicit marshaller
configuration.
+     * The result shall be as documented in {@link #testCharacterString()}.
      *
      * @throws JAXBException Should never happen.
+     *
+     * @see #testMarshallLanguageCode()
      */
     @Test
-    public void testCharacterStringFormat() throws JAXBException {
-        final String inspire = getDataIdentificationXML(true);
-        final String simpler = getDataIdentificationXML(false);
-        final DataIdentificationMock id = new DataIdentificationMock(Locale.FRENCH);
-
+    public void testMarshallCharacterString() throws JAXBException {
+        final MetadataMock metadata = new MetadataMock(Locale.JAPANESE);
         final Marshaller marshaller = pool.acquireMarshaller();
-        assertNull(marshaller.getProperty(XML.STRING_SUBSTITUTES));
-        assertXmlEquals(inspire, marshal(marshaller, id), "xmlns:*");
-
         marshaller.setProperty(XML.STRING_SUBSTITUTES, new String[] {"dummy","language","foo"});
         assertArrayEquals(new String[] {"language"}, (String[]) marshaller.getProperty(XML.STRING_SUBSTITUTES));
-        assertXmlEquals(simpler, marshal(marshaller, id), "xmlns:*");
+        assertXmlEquals(getMetadataXML(CHARACTER_STRING), marshal(marshaller, metadata),
"xmlns:*");
         pool.recycle(marshaller);
     }
+
+    /**
+     * Tests the unmarshalling of an XML using the {@code gco:CharacterString} construct.
+     * XML fragment:
+     *
+     * {@preformat xml
+     *   <gmd:MD_Metadata>
+     *     <gmd:language>
+     *       <gco:CharacterString>jpn</gco:CharacterString>
+     *     </gmd:language>
+     *   </gmd:MD_Metadata>
+     * }
+     *
+     * @throws JAXBException Should never happen.
+     */
+    @Test
+    public void testCharacterString() throws JAXBException {
+        final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
+        final String xml = getMetadataXML(CHARACTER_STRING);
+        final Metadata metadata = (Metadata) unmarshal(unmarshaller, xml);
+        assertEquals(Locale.JAPANESE, metadata.getLanguage());
+        pool.recycle(unmarshaller);
+    }
 }

Copied: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java
(from r1550935, sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/DataIdentificationMock.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java?p2=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java&p1=sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/DataIdentificationMock.java&r1=1550935&r2=1551090&rev=1551090&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/DataIdentificationMock.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java
[UTF-8] Mon Dec 16 00:31:12 2013
@@ -16,45 +16,44 @@
  */
 package org.apache.sis.test.mock;
 
+import java.util.Date;
 import java.util.Locale;
 import java.util.Collection;
-import java.util.Collections;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import org.opengis.metadata.citation.Citation;
+import org.opengis.metadata.Metadata;
+import org.opengis.metadata.MetadataExtensionInformation;
+import org.opengis.metadata.ApplicationSchemaInformation;
+import org.opengis.metadata.PortrayalCatalogueReference;
+import org.opengis.metadata.acquisition.AcquisitionInformation;
 import org.opengis.metadata.citation.ResponsibleParty;
 import org.opengis.metadata.constraint.Constraints;
-import org.opengis.metadata.distribution.Format;
-import org.opengis.metadata.extent.Extent;
-import org.opengis.metadata.identification.AggregateInformation;
-import org.opengis.metadata.identification.BrowseGraphic;
+import org.opengis.metadata.content.ContentInformation;
+import org.opengis.metadata.distribution.Distribution;
 import org.opengis.metadata.identification.CharacterSet;
-import org.opengis.metadata.identification.DataIdentification;
-import org.opengis.metadata.identification.Keywords;
-import org.opengis.metadata.identification.Progress;
-import org.opengis.metadata.identification.Resolution;
-import org.opengis.metadata.identification.TopicCategory;
-import org.opengis.metadata.identification.Usage;
+import org.opengis.metadata.identification.Identification;
 import org.opengis.metadata.maintenance.MaintenanceInformation;
-import org.opengis.metadata.spatial.SpatialRepresentationType;
-import org.opengis.util.InternationalString;
-import org.apache.sis.xml.Namespaces;
+import org.opengis.metadata.maintenance.ScopeCode;
+import org.opengis.metadata.quality.DataQuality;
+import org.opengis.metadata.spatial.SpatialRepresentation;
+import org.opengis.referencing.ReferenceSystem;
 import org.apache.sis.internal.jaxb.gmd.LocaleAdapter;
+import org.apache.sis.xml.Namespaces;
 
 
 /**
- * A dummy implementation of {@link DataIdentification} with minimal XML (un)marshalling
capability.
+ * A dummy implementation of {@link Metadata} with minimal XML (un)marshalling capability.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @since   0.3
- * @version 0.3
+ * @since   0.4
+ * @version 0.4
  * @module
  */
-@XmlRootElement(name = "MD_DataIdentification", namespace = Namespaces.GMD)
-public final strictfp class DataIdentificationMock implements DataIdentification {
+@XmlRootElement(name = "MD_Metadata", namespace = Namespaces.GMD)
+public final strictfp class MetadataMock implements Metadata {
     /**
-     * The locale to (un)marshal as a language.
+     * The language used for documenting metadata.
      */
     @XmlElement(namespace = Namespaces.GMD)
     @XmlJavaTypeAdapter(LocaleAdapter.class)
@@ -64,7 +63,7 @@ public final strictfp class DataIdentifi
      * Creates an initially empty metadata.
      * This constructor is required by JAXB.
      */
-    public DataIdentificationMock() {
+    public MetadataMock() {
     }
 
     /**
@@ -73,18 +72,45 @@ public final strictfp class DataIdentifi
      *
      * @param language The initial {@link #language} value (can be {@code null}).
      */
-    public DataIdentificationMock(final Locale language) {
+    public MetadataMock(final Locale language) {
         this.language = language;
     }
 
     /**
-     * Returns {@link #language} in an unmodifiable collection.
+     * Undefined property.
+     * @return {@code null}.
+     */
+    @Override
+    public String getFileIdentifier() {
+        return null;
+    }
+
+    /**
+     * Returns {@link #language}.
      *
-     * @return {@link #language} singleton.
+     * @return {@link #language}
+     */
+    @Override
+    public Locale getLanguage() {
+        return language;
+    }
+
+    /**
+     * Undefined property.
+     * @return {@code null}.
      */
     @Override
-    public Collection<Locale> getLanguages() {
-        return (language != null) ? Collections.singleton(language) : Collections.<Locale>emptySet();
+    public CharacterSet getCharacterSet() {
+        return null;
+    }
+
+    /**
+     * Undefined property.
+     * @return {@code null}.
+     */
+    @Override
+    public String getParentIdentifier() {
+        return null;
     }
 
     /**
@@ -92,7 +118,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<SpatialRepresentationType> getSpatialRepresentationTypes() {
+    public Collection<ScopeCode> getHierarchyLevels() {
         return null;
     }
 
@@ -101,7 +127,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends Resolution> getSpatialResolutions() {
+    public Collection<String> getHierarchyLevelNames() {
         return null;
     }
 
@@ -110,7 +136,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<CharacterSet> getCharacterSets() {
+    public Collection<? extends ResponsibleParty> getContacts() {
         return null;
     }
 
@@ -119,7 +145,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<TopicCategory> getTopicCategories() {
+    public Date getDateStamp() {
         return null;
     }
 
@@ -128,7 +154,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public InternationalString getEnvironmentDescription() {
+    public String getMetadataStandardName() {
         return null;
     }
 
@@ -137,7 +163,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends Extent> getExtents() {
+    public String getMetadataStandardVersion() {
         return null;
     }
 
@@ -146,7 +172,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public InternationalString getSupplementalInformation() {
+    public String getDataSetUri() {
         return null;
     }
 
@@ -155,7 +181,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Citation getCitation() {
+    public Collection<Locale> getLocales() {
         return null;
     }
 
@@ -164,7 +190,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public InternationalString getAbstract() {
+    public Collection<? extends SpatialRepresentation> getSpatialRepresentationInfo()
{
         return null;
     }
 
@@ -173,7 +199,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public InternationalString getPurpose() {
+    public Collection<? extends ReferenceSystem> getReferenceSystemInfo() {
         return null;
     }
 
@@ -182,7 +208,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<String> getCredits() {
+    public Collection<? extends MetadataExtensionInformation> getMetadataExtensionInfo()
{
         return null;
     }
 
@@ -191,7 +217,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<Progress> getStatus() {
+    public Collection<? extends Identification> getIdentificationInfo() {
         return null;
     }
 
@@ -200,7 +226,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends ResponsibleParty> getPointOfContacts() {
+    public Collection<? extends ContentInformation> getContentInfo() {
         return null;
     }
 
@@ -209,7 +235,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends MaintenanceInformation> getResourceMaintenances() {
+    public Distribution getDistributionInfo() {
         return null;
     }
 
@@ -218,7 +244,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends BrowseGraphic> getGraphicOverviews() {
+    public Collection<? extends DataQuality> getDataQualityInfo() {
         return null;
     }
 
@@ -227,7 +253,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends Format> getResourceFormats() {
+    public Collection<? extends PortrayalCatalogueReference> getPortrayalCatalogueInfo()
{
         return null;
     }
 
@@ -236,7 +262,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends Keywords> getDescriptiveKeywords() {
+    public Collection<? extends Constraints> getMetadataConstraints() {
         return null;
     }
 
@@ -245,7 +271,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends Usage> getResourceSpecificUsages() {
+    public Collection<? extends ApplicationSchemaInformation> getApplicationSchemaInfo()
{
         return null;
     }
 
@@ -254,7 +280,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends Constraints> getResourceConstraints() {
+    public MaintenanceInformation getMetadataMaintenance() {
         return null;
     }
 
@@ -263,7 +289,7 @@ public final strictfp class DataIdentifi
      * @return {@code null}.
      */
     @Override
-    public Collection<? extends AggregateInformation> getAggregationInfo() {
+    public Collection<? extends AcquisitionInformation> getAcquisitionInformation()
{
         return null;
     }
 }



Mime
View raw message