sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1417780 - in /sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb: gco/ gmd/ gmx/
Date Thu, 06 Dec 2012 09:05:06 GMT
Author: desruisseaux
Date: Thu Dec  6 09:05:04 2012
New Revision: 1417780

URL: http://svn.apache.org/viewvc?rev=1417780&view=rev
Log:
Ported JAXB adapter related to character sequences.

Added:
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/CharSequenceAdapter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/PT_FreeText.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/TextGroup.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/package-info.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/Anchor.java   (with props)
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/package-info.java   (with props)

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/CharSequenceAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/CharSequenceAdapter.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/CharSequenceAdapter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/CharSequenceAdapter.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,222 @@
+/*
+ * 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.jaxb.gco;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.HashMap;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.internal.jaxb.MarshalContext;
+import org.apache.sis.internal.jaxb.gmx.Anchor;
+import org.apache.sis.internal.jaxb.gmd.PT_FreeText;
+
+
+/**
+ * JAXB adapter in order to wrap the string value with a {@code <gco:CharacterString>} element,
+ * for ISO-19139 compliance. A {@link CharSequenceAdapter} can also substitute text by anchors.
+ * At the difference of most adapters provided in {@code org.apache.sis.internal.jaxb} packages,
+ * this adapter is <em>configurable</em>. It must be created explicitly with a map of bindings
+ * between labels and URNs, and the configured adapter must be given to the mashaller as below:
+ *
+ * {@preformat java
+ *     CharSequenceAdapter adapter = new CharSequenceAdapter();
+ *     adapter.addLinkage(...);
+ *     marshaller.setAdapter(adapter);
+ *     marshaller.setAdapter(new StringAdapter(adapter));
+ *     marshaller.setAdapter(new InternationalStringAdapter(adapter));
+ * }
+ *
+ * This class can also handles {@link InternationalString}, which will be mapped to
+ * {@link PT_FreeText} elements.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @author  Guilhem Legal (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ *
+ * @see StringAdapter
+ * @see InternationalStringAdapter
+ */
+public final class CharSequenceAdapter extends XmlAdapter<GO_CharacterString, CharSequence> {
+    /**
+     * Binds string labels with URNs or anchors. Values can be either {@link URI} or
+     * {@link Anchor} instances. The map is initially null and will be created
+     * when first needed.
+     *
+     * @see #addLinkage(String, URI)
+     * @see #addLinkage(Anchor)
+     */
+    private Map<String,Object> anchors;
+
+    /**
+     * Creates a uninitialized adapter.
+     */
+    public CharSequenceAdapter() {
+    }
+
+    /**
+     * Adds a label associated to the given URN.
+     *
+     * @param  label The label associated to the URN.
+     * @param  linkage The URN.
+     * @throws IllegalStateException If a URN is already associated to the given label.
+     */
+    public void addLinkage(final String label, final URI linkage) throws IllegalStateException {
+        add(label, linkage);
+    }
+
+    /**
+     * Adds an anchor (label associated to an URN).
+     *
+     * @param  anchor The anchor to add.
+     * @throws IllegalStateException If a URN is already associated to the anchor value.
+     */
+    public void addLinkage(final Anchor anchor) throws IllegalStateException {
+        add(anchor.toString(), anchor);
+    }
+
+    /**
+     * Implementation of {@code addLinkage} methods.
+     */
+    private synchronized void add(final String label, final Object linkage) throws IllegalStateException {
+        if (anchors == null) {
+            anchors = new HashMap<>();
+        }
+        final Object old = anchors.put(label, linkage);
+        if (old != null) {
+            anchors.put(label, old);
+            if (!old.equals(linkage)) {
+                throw new IllegalStateException(Errors.format(Errors.Keys.ValueAlreadyDefined_1, label));
+            }
+        }
+    }
+
+    /**
+     * Converts a string read from a XML stream to the object containing
+     * the value. JAXB calls automatically this method at unmarshalling time.
+     *
+     * @param value The adapter for this metadata value.
+     * @return A {@link CharSequence} which represents the metadata value.
+     */
+    @Override
+    public CharSequence unmarshal(final GO_CharacterString value) {
+        if (value != null) {
+            if (value instanceof PT_FreeText) {
+                final PT_FreeText freeText = (PT_FreeText) value;
+                String defaultValue = freeText.toString(); // May be null.
+                if (defaultValue != null && freeText.contains(defaultValue)) {
+                    /*
+                     * If the <gco:CharacterString> value is repeated in one of the
+                     * <gmd:LocalisedCharacterString> elements, keep only the localized
+                     * version  (because it specifies the locale, while the unlocalized
+                     * string saids nothing on that matter).
+                     */
+                    defaultValue = null;
+                }
+                /*
+                 * Create the international string with all locales found in the <gml:textGroup>
+                 * element. If the <gml:textGroup> element is missing or empty, then we will use
+                 * an instance of SimpleInternationalString instead than the more heavy
+                 * DefaultInternationalString.
+                 */
+                return freeText.toInternationalString(defaultValue);
+            }
+            /*
+             * Case where the value is an ordinary GO_CharacterString (not a PT_FreeText).
+             */
+            CharSequence text = value.text;
+            if (text != null) {
+                if (text instanceof String) {
+                    text = ((String) text).trim();
+                }
+                if (text.length() != 0 || text instanceof Anchor) { // Anchor may contain attributes.
+                    return text;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Converts a {@linkplain CharSequence character sequence} to the object to be marshalled
+     * in a XML file or stream. JAXB calls automatically this method at marshalling time.
+     *
+     * @param value The string value.
+     * @return The wrapper for the given string.
+     */
+    @Override
+    public GO_CharacterString marshal(CharSequence value) {
+        if (value instanceof String) {
+            value = ((String) value).trim();
+        }
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        /*
+         * <gmd:someElement xsi:type="gmd:PT_FreeText_PropertyType">
+         *   <gco:CharacterString>...</gco:CharacterString>
+         *   <gmd:PT_FreeText>
+         *     ... see PT_FreeText ...
+         *   </gmd:PT_FreeText>
+         * </gmd:someElement>
+         */
+        if (value instanceof InternationalString) {
+            final PT_FreeText ft = PT_FreeText.create(MarshalContext.current(), (InternationalString) value);
+            if (ft != null) {
+                return ft;
+            }
+        }
+        /*
+         * Substitute <gco:CharacterString> by <gmx:Anchor> if a linkage is found.
+         */
+        if (!(value instanceof Anchor)) {
+            synchronized (this) {
+                if (anchors != null) {
+                    String key = value.toString();
+                    if (key != null) {
+                        key = key.trim();
+                        if (!key.isEmpty()) {
+                            final Object linkage = anchors.get(key);
+                            if (linkage != null) {
+                                if (linkage instanceof URI) {
+                                    value = new Anchor((URI) linkage, key);
+                                } else {
+                                    value = (Anchor) linkage;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        /*
+         * At this stage, the value (typically a String or InternationalString) may
+         * have been replaced by an Anchor. The output will be one of the following:
+         *
+         * ┌──────────────────────────────────────────────────┬────────────────────────────────┐
+         * │ <gmd:someElement>                                │ <gmd:someElement>              │
+         * │   <gco:CharacterString>...</gco:CharacterString> │   <gmx:Anchor>...</gmx:Anchor> │
+         * │ </gmd:someElement>                               │ </gmd:someElement>             │
+         * └──────────────────────────────────────────────────┴────────────────────────────────┘
+         */
+        return new GO_CharacterString(value);
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/CharSequenceAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/CharSequenceAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,136 @@
+/*
+ * 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.jaxb.gco;
+
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
+
+import org.apache.sis.xml.Namespaces;
+import org.apache.sis.internal.jaxb.gmd.PT_FreeText;
+import org.apache.sis.internal.jaxb.gmd.LanguageCode;
+import org.apache.sis.internal.jaxb.gmd.Country;
+import org.apache.sis.internal.jaxb.gmx.Anchor;
+import org.apache.sis.util.CharSequences;
+
+
+/**
+ * JAXB wrapper for string value in a {@code <gco:CharacterString>} or {@code <gmx:Anchor>} element,
+ * for ISO-19139 compliance.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see org.apache.sis.internal.jaxb.gmd.PT_FreeText
+ */
+@XmlType(name = "CharacterString_PropertyType")
+@XmlSeeAlso({PT_FreeText.class, LanguageCode.class, Country.class})
+public class GO_CharacterString {
+    /**
+     * The text or anchor value, or {@code null} if none. May be an instance
+     * of {@link Anchor}, which needs to be handled in a special way.
+     */
+    CharSequence text;
+
+    /**
+     * Empty constructor for JAXB and subclasses.
+     */
+    protected GO_CharacterString() {
+    }
+
+    /**
+     * Builds an wrapper for the given text.
+     *
+     * @param text The string to marshall, or {@code null} if none.
+     */
+    protected GO_CharacterString(final CharSequence text) {
+        this.text = text;
+    }
+
+    /**
+     * Builds an wrapper as a copy of the given one.
+     *
+     * @param text The wrapper to copy, or {@code null} if none.
+     */
+    protected GO_CharacterString(final GO_CharacterString text) {
+        if (text != null) {
+            this.text = text.text;
+        }
+    }
+
+    /**
+     * Returns the text. This method is called by JAXB at marshalling time.
+     *
+     * @return The text, or {@code null}.
+     */
+    @XmlElement(name = "CharacterString")
+    public final String getCharacterString() {
+        final CharSequence text = this.text;
+        return (text == null || text instanceof Anchor) ? null : text.toString();
+    }
+
+    /**
+     * Sets the value to the given string. This method is called by JAXB at unmarshalling time.
+     *
+     * @param text The new text.
+     */
+    public final void setCharacterString(String text) {
+        text = CharSequences.trimWhitespaces(text);
+        if (text != null && text.isEmpty()) {
+            text = null;
+        }
+        this.text = text;
+    }
+
+    /**
+     * Returns the text associated with a reference.
+     * This method is called by JAXB at marshalling time.
+     *
+     * @return The anchor, or {@code null}.
+     */
+    @XmlElement(name = "Anchor", namespace = Namespaces.GMX)
+    public final Anchor getAnchor() {
+        final CharSequence text = this.text;
+        return (text instanceof Anchor) ? (Anchor) text : null;
+    }
+
+    /**
+     * Sets the value for the metadata string.
+     * This method is called by JAXB at unmarshalling time.
+     *
+     * @param anchor The new anchor.
+     */
+    public final void setAnchor(final Anchor anchor) {
+        this.text = anchor;
+    }
+
+    /**
+     * Returns the text as a string, or {@code null} if none.
+     * The null value is expected by various {@code unmarshal} methods.
+     *
+     * {@note Returning <code>null</code> is unusual and not a recommended practice.
+     * But precedents exist (for example Swing <code>DefaultMutableTreeNode</code>)
+     * and this class is not for public usage.}
+     */
+    @Override
+    public final String toString() {
+        final CharSequence text = this.text;
+        return (text != null) ? text.toString() : null; // NOSONAR: Really want to return null.
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/GO_CharacterString.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,63 @@
+/*
+ * 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.jaxb.gco;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import org.opengis.util.InternationalString;
+import org.apache.sis.util.type.SimpleInternationalString;
+
+
+/**
+ * JAXB adapter for string values mapped to {@link InternationalString}. At the difference of
+ * {@link InternationalStringAdapter}, this converter doesn't wrap the string in a new object.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @since   0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ */
+public final class InternationalStringConverter extends XmlAdapter<String,InternationalString> {
+    /**
+     * Empty constructor for JAXB.
+     */
+    public InternationalStringConverter() {
+    }
+
+    /**
+     * Converts an object read from a XML stream to an {@link InternationalString}
+     * implementation. JAXB invokes automatically this method at unmarshalling time.
+     *
+     * @param  adapter The adapter for the string value.
+     * @return An {@link InternationalString} for the string value.
+     */
+    @Override
+    public InternationalString unmarshal(final String adapter) {
+        return (adapter != null) ? new SimpleInternationalString(adapter) : null;
+    }
+
+    /**
+     * Converts an {@link InternationalString} to an object to formatted into a
+     * XML stream. JAXB invokes automatically this method at marshalling time.
+     *
+     * @param  value The string value.
+     * @return The adapter for the string.
+     */
+    @Override
+    public String marshal(final InternationalString value) {
+        return (value != null) ? value.toString() : null;
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/InternationalStringConverter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,151 @@
+/*
+ * 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.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.MarshalContext;
+import org.apache.sis.internal.jaxb.code.CodeListProxy;
+import org.apache.sis.internal.jaxb.gco.GO_CharacterString;
+import org.apache.sis.internal.jaxb.gco.CharSequenceAdapter;
+
+
+/**
+ * JAXB wrapper for {@link Locale}, in order to integrate the value in an element respecting
+ * the ISO-19139 standard. See package documentation for more information about the handling
+ * of {@code CodeList} in ISO-19139.
+ *
+ * <p>This adapter formats the locale like below:</p>
+ *
+ * {@preformat xml
+ *   <gmd:country>
+ *     <gmd:Country codeList="http://(...snip...)" codeListValue="FR">France</gmd:Country>
+ *   </gmd:country>
+ * }
+ *
+ * Note that {@code <gco:CharacterString>} can be substituted to the country code.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+@XmlType(name = "Country_PropertyType")
+public final class Country extends GO_CharacterString {
+    /**
+     * The country using a {@link CodeList}-like format.
+     */
+    @XmlElement(name = "Country")
+    private CodeListProxy proxy;
+
+    /**
+     * Empty constructor for JAXB only.
+     */
+    public Country() {
+    }
+
+    /**
+     * Builds a {@code <gco:CharacterString>} element.
+     * For private use by {@link #create(MarshalContext, Locale, CharSequenceAdapter)} only.
+     */
+    private Country(final GO_CharacterString code) {
+        super(code);
+    }
+
+    /**
+     * Builds a {@code <Country>} element.
+     * For private use by {@link #create(MarshalContext, Locale, CharSequenceAdapter)} only.
+     *
+     * @param context       The current (un)marshalling context, or {@code null} if none.
+     * @param codeListValue The {@code codeListValue} attribute in the XML element.
+     * @param codeSpace     The 3-letters language code of the {@code value} attribute, or {@code null} if none.
+     * @param value         The value in the language specified by the {@code codeSpace} attribute, or {@code null} if none.
+     */
+    private Country(final MarshalContext context, final String codeListValue, final String codeSpace, final String value) {
+        proxy = new CodeListProxy(context, "ML_gmxCodelists.xml", "Country", codeListValue, codeSpace, value);
+    }
+
+    /**
+     * Creates a new wrapper for the given locale.
+     *
+     * @param context The current (un)marshalling context, or {@code null} if none.
+     * @param locale  The value to marshall, or {@code null}.
+     * @paral anchors If non-null, marshall the locale as a {@code <gco:CharacterString>} instead
+     *                than {@code <Country>}, using the given anchors if any.
+     * @return The country to marshal, or {@code null} if the given locale was null
+     *         or if its {@link Locale#getCountry()} attribute is the empty string.
+     */
+    static Country create(final MarshalContext context, final Locale locale, final CharSequenceAdapter anchors) {
+        if (locale != null) {
+            final String codeListValue = MarshalContext.converter(context).toCountryCode(context, locale);
+            if (anchors != null && !codeListValue.isEmpty()) {
+                final GO_CharacterString string = anchors.marshal(codeListValue);
+                if (string != null) {
+                    return new Country(string);
+                }
+            }
+            String codeSpace = null;
+            String value = null;
+            if (context != null) {
+                final Locale marshalLocale = context.getLocale();
+                if (marshalLocale != null) {
+                    codeSpace = MarshalContext.converter(context).toLanguageCode(context, locale);
+                    value = locale.getDisplayCountry(marshalLocale);
+                    if (value.isEmpty()) {
+                        value = null;
+                    }
+                }
+            }
+            if (!codeListValue.isEmpty() || value != null) {
+                return new Country(context, codeListValue, codeSpace, value);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the locale for the given 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.
+     *
+     * @see LanguageCode#getLocale(MarshalContext, LanguageCode, boolean)
+     */
+    static Locale getLocale(final Country value) {
+        if (value != null) {
+            String code = null;
+            if (value.proxy != null) {
+                code = value.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));
+            }
+        }
+        return null;
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/Country.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,149 @@
+/*
+ * 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.jaxb.gmd;
+
+import java.util.Locale;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlElement;
+
+import org.apache.sis.internal.jaxb.MarshalContext;
+import org.apache.sis.internal.jaxb.code.CodeListProxy;
+import org.apache.sis.internal.jaxb.gco.GO_CharacterString;
+import org.apache.sis.internal.jaxb.gco.CharSequenceAdapter;
+
+
+/**
+ * JAXB wrapper for {@link Locale}, in order to integrate the value in an element respecting
+ * the ISO-19139 standard. See package documentation for more information about the handling
+ * of {@code CodeList} in ISO-19139.
+ *
+ * <p>This adapter formats the locale like below:</p>
+ *
+ * {@preformat xml
+ *   <gmd:language>
+ *     <gmd:LanguageCode codeList="http://(...snip...)" codeListValue="eng">English</gmd:LanguageCode>
+ *   </gmd:language>
+ * }
+ *
+ * Note that {@code <gco:CharacterString>} can be substituted to the language code.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ */
+@XmlType(name = "LanguageCode_PropertyType")
+public final class LanguageCode extends GO_CharacterString {
+    /**
+     * The language using a {@link CodeList}-like format.
+     */
+    @XmlElement(name = "LanguageCode")
+    private CodeListProxy proxy;
+
+    /**
+     * Empty constructor for JAXB only.
+     */
+    public LanguageCode() {
+    }
+
+    /**
+     * Builds a {@code <gco:CharacterString>} element.
+     * For private use by {@link #create(MarshalContext, Locale, CharSequenceAdapter)} only.
+     */
+    private LanguageCode(final GO_CharacterString code) {
+        super(code);
+    }
+
+    /**
+     * Builds a {@code <LanguageCode>} element.
+     * For private use by {@link #create(MarshalContext, Locale, CharSequenceAdapter)} only.
+     *
+     * @param context       The current (un)marshalling context, or {@code null} if none.
+     * @param codeListValue The {@code codeListValue} attribute in the XML element.
+     * @param codeSpace     The 3-letters language code of the {@code value} attribute, or {@code null} if none.
+     * @param value         The value in the language specified by the {@code codeSpace} attribute, or {@code null} if none.
+     */
+    private LanguageCode(final MarshalContext context, final String codeListValue, final String codeSpace, final String value) {
+        proxy = new CodeListProxy(context, "ML_gmxCodelists.xml", "LanguageCode", codeListValue, codeSpace, value);
+    }
+
+    /**
+     * Creates a new wrapper for the given locale.
+     *
+     * @param context The current (un)marshalling context, or {@code null} if none.
+     * @param locale  The value to marshall, or {@code null}.
+     * @paral anchors If non-null, marshall the locale as a {@code <gco:CharacterString>} instead
+     *                than {@code <LanguageCode>}, using the given anchors if any.
+     * @return The language to marshal, or {@code null} if the given locale was null
+     *         or if its {@link Locale#getLanguage()} attribute is the empty string.
+     */
+    static LanguageCode create(final MarshalContext context, final Locale locale, final CharSequenceAdapter anchors) {
+        if (locale != null) {
+            final String codeListValue = MarshalContext.converter(context).toLanguageCode(context, locale);
+            if (anchors != null && !codeListValue.isEmpty()) {
+                final GO_CharacterString string = anchors.marshal(codeListValue);
+                if (string != null) {
+                    return new LanguageCode(string);
+                }
+            }
+            String codeSpace = null;
+            String value = null;
+            if (context != null) {
+                final Locale marshalLocale = context.getLocale();
+                if (marshalLocale != null) {
+                    codeSpace = MarshalContext.converter(context).toLanguageCode(context, locale);
+                    value = locale.getDisplayLanguage(marshalLocale);
+                    if (value.isEmpty()) {
+                        value = null;
+                    }
+                }
+            }
+            if (!codeListValue.isEmpty() || value != null) {
+                return new LanguageCode(context, codeListValue, codeSpace, value);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the locale for the given language (which may be null), 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.
+     *
+     * @see Country#getLocale(Country)
+     */
+    static Locale getLocale(final MarshalContext context, final LanguageCode value, final boolean useCharSequence) {
+        if (value != null) {
+            final CodeListProxy proxy = value.proxy;
+            if (proxy != null) {
+                final Locale locale = MarshalContext.converter(context).toLocale(context, proxy.codeListValue);
+                if (locale != null) {
+                    return locale;
+                }
+            }
+            if (useCharSequence) {
+                return MarshalContext.converter(context).toLocale(context, value.toString());
+            }
+        }
+        return null;
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LanguageCode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,138 @@
+/*
+ * 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.jaxb.gmd;
+
+import java.util.Locale;
+import javax.xml.bind.annotation.XmlValue;
+import javax.xml.bind.annotation.XmlAttribute;
+import org.apache.sis.internal.jaxb.MarshalContext;
+
+// Related to JDK7
+import java.util.Objects;
+
+
+/**
+ * The {@code <LocalisedCharacterString>} elements nested in a {@code <textGroup>} one.
+ * This element contains a string for a given {@linkplain Locale locale}.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see TextGroup
+ */
+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.
+     */
+    private static final String LOCALE = "#locale-";
+
+    /**
+     * The locale value for this string.
+     */
+    Locale locale;
+
+    /**
+     * The text in the locale of this localized string. JAXB uses this field for formatting
+     * the {@code <LocalisedCharacterString>} elements in the XML tree at marshalling-time.
+     */
+    @XmlValue
+    String text;
+
+    /**
+     * Empty constructor only used by JAXB.
+     */
+    public LocalisedCharacterString() {
+    }
+
+    /**
+     * Constructs a localized string for the given locale and text.
+     *
+     * @param locale The string language.
+     * @param text The string.
+     */
+    LocalisedCharacterString(final Locale locale, final String text) {
+        this.locale = locale;
+        this.text = text;
+    }
+
+    /**
+     * Returns the locale language, as specified by ISO-19139 for
+     * {@code <LocalisedCharacterString>} attribute.
+     *
+     * @return The current locale.
+     */
+    @XmlAttribute(name = "locale", required = true)
+    public String getLocale() {
+        if (locale == null) {
+            return null;
+        }
+        final MarshalContext context = MarshalContext.current();
+        return LOCALE.concat(MarshalContext.converter(context).toLanguageCode(context, locale));
+    }
+
+    /**
+     * Sets the locale language, using a string formatted as {@code #locale-xxx},
+     * where {@code xxx} are the two or three letters representing the language.
+     *
+     * @param localeId The new locale.
+     */
+    public void setLocale(final String localeId) {
+        if (localeId != null) {
+            final MarshalContext context = MarshalContext.current();
+            locale = MarshalContext.converter(context).toLocale(context, localeId.substring(localeId.indexOf('-') + 1));
+        } else {
+            locale = null;
+        }
+    }
+
+    /**
+     * Returns a hash code value for this string.
+     */
+    @Override
+    public int hashCode() {
+        return Objects.hash(locale, text);
+    }
+
+    /**
+     * Compares this string with the given object for equality.
+     */
+    @Override
+    public boolean equals(final Object object) {
+        if (!(object instanceof LocalisedCharacterString)) {
+            return false;
+        }
+        final LocalisedCharacterString that = (LocalisedCharacterString) object;
+        return Objects.equals(locale, that.locale) && Objects.equals(text, that.text);
+    }
+
+    /**
+     * Returns a string representation of this object for debugging purpose.
+     */
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder(getClass().getSimpleName())
+                .append('[').append(getLocale());
+        if (text != null) {
+            buffer.append(", \"").append(text).append('"');
+        }
+        return buffer.append(']').toString();
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/LocalisedCharacterString.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/PT_FreeText.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/PT_FreeText.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/PT_FreeText.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/PT_FreeText.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,202 @@
+/*
+ * 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.jaxb.gmd;
+
+import java.util.Set;
+import java.util.Locale;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+
+import org.opengis.util.InternationalString;
+import org.apache.sis.internal.jaxb.MarshalContext;
+import org.apache.sis.internal.jaxb.gco.GO_CharacterString;
+import org.apache.sis.util.type.DefaultInternationalString;
+import org.apache.sis.util.type.SimpleInternationalString;
+
+
+/**
+ * JAXB wrapper for ISO-19139 {@code <PT_FreeText>} element mapped to {@link InternationalString}.
+ * It will be used in order to marshall and unmarshall international strings localized in several
+ * language, using the {@link DefaultInternationalString} implementation class. Example:
+ *
+ * {@preformat xml
+ *   <gmd:title xsi:type="gmd:PT_FreeText_PropertyType">
+ *     <gco:CharacterString>Some title in english is present in this node</gco:CharacterString>
+ *     <gmd:PT_FreeText>
+ *       <gmd:textGroup>
+ *         <gmd:LocalisedCharacterString locale="#locale-fra">Un titre en français</gmd:LocalisedCharacterString>
+ *       </gmd:textGroup>
+ *     </gmd:PT_FreeText>
+ *   </gmd:title>
+ * }
+ *
+ * If there is more than one locale, the whole {@code <gmd:textGroup>} block is repeated for each
+ * locale, instead than repeating {@code <gmd:LocalisedCharacterString>} inside the same group as
+ * we could expect. However at unmarshalling time, both forms are accepted. See GEOTK-152 for more
+ * information.
+ *
+ * <p>The {@code <gco:CharacterString>} element is inherited from the {@link GO_CharacterString}
+ * parent class.</p>
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-152">GEOTK-152</a>
+ */
+@XmlType(name = "PT_FreeText_PropertyType")
+public final class PT_FreeText extends GO_CharacterString {
+    /**
+     * A set of {@link LocalisedCharacterString}, representing the {@code <gmd:textGroup>} element.
+     * The array shall contain one element for each locale.
+     *
+     * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-152">GEOTK-152</a>
+     */
+    @XmlElementWrapper(name = "PT_FreeText")
+    @XmlElement(required = true)
+    private TextGroup[] textGroup;
+
+    /**
+     * Empty constructor used only by JAXB.
+     */
+    public PT_FreeText() {
+    }
+
+    /**
+     * Constructs a {@linkplain TextGroup text group} from a {@link DefaultInternationalString}
+     * which could contains several localized strings.
+     *
+     * <p>The {@code <gco:CharacterString> element will typically be set for the {@code null} locale,
+     * which is the "unlocalized" string (not the same thing than the string in the default locale).
+     * Note that the {@link TextGroup} constructor works better if the {@code <gco:CharacterString>}
+     * have been set for the {@code null} locale (the default behavior). If a different locale were
+     * set, the list of localized strings in {@code TextGroup} may contains an element which
+     * duplicate the {@code <gco:CharacterString>} element, or the unlocalized string normally
+     * written in {@code <gco:CharacterString>} may be missing.</p>
+     *
+     * @param context The current (un)marshalling context, or {@code null} if none.
+     * @param text    An international string which could have several translations
+     *                embedded for the same text.
+     *
+     * @see org.apache.sis.xml.XML#LOCALE
+     */
+    private PT_FreeText(final MarshalContext context, final DefaultInternationalString text) {
+        super(text.toString(context != null ? context.getLocale() : null));
+        final Set<Locale> locales = text.getLocales();
+        int n = locales.size();
+        if (locales.contains(null)) {
+            n--;
+        }
+        textGroup = new TextGroup[n];
+        int i = 0;
+        for (final Locale locale : locales) {
+            if (locale != null) {
+                textGroup[i++] = new TextGroup(locale, text.toString(locale));
+            }
+        }
+    }
+
+    /**
+     * Constructs a {@linkplain TextGroup text group} from the given {@link InternationalString}
+     * if it contains at least one non-null locale. Otherwise returns {@code null}, meaning that
+     * the simpler {@link GO_CharacterString} construct should be used instead.
+     *
+     * @param context The current (un)marshalling context, or {@code null} if none.
+     * @param text    An international string which could have several translations
+     *                embedded for the same text.
+     * @return A {@code PT_FreeText} instance if the given text has several translations,
+     *         or {@code null} otherwise.
+     */
+    @SuppressWarnings("fallthrough")
+    public static PT_FreeText create(final MarshalContext context, final InternationalString text) {
+        if (text instanceof DefaultInternationalString) {
+            final DefaultInternationalString df = (DefaultInternationalString) text;
+            final Set<Locale> locales = df.getLocales();
+            switch (locales.size()) {
+                case 0:  break;
+                case 1:  if (locales.contains(null)) break; // Otherwise fallthrough
+                default: return new PT_FreeText(context, df);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns {@code true} if this {@code PT_FreeText} contains the given localized text.
+     * This method searches only in the localized text. The content of the {@link #text}
+     * field is intentionally omitted since it is usually the text we are searching for!
+     * (this method is used for detecting duplicated values).
+     *
+     * @param  search The text to search (usually the {@link #text} value).
+     * @return {@code true} if the given text has been found.
+     */
+    public boolean contains(final String search) {
+        final TextGroup[] textGroup = this.textGroup;
+        if (textGroup != null) {
+            for (final TextGroup group : textGroup) {
+                if (group != null) {
+                    final LocalisedCharacterString[] localised = group.localized;
+                    if (localised != null) {
+                        for (final LocalisedCharacterString candidate : localised) {
+                            if (search.equals(candidate.text)) {
+                                return true;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Returns the international string for this {@code PT_FreeText}.
+     *
+     * @param  defaultValue The unlocalized string to give to {@link DefaultInternationalString},
+     *         or {@code null} if none.
+     * @return The international string, or {@code null} if none.
+     *         This is usually the {@link #text} value.
+     */
+    public InternationalString toInternationalString(final String defaultValue) {
+        DefaultInternationalString i18n = null;
+        final TextGroup[] textGroup = this.textGroup;
+        if (textGroup != null) {
+            for (final TextGroup group : textGroup) {
+                if (group != null) {
+                    final LocalisedCharacterString[] localised = group.localized;
+                    if (localised != null) {
+                        for (final LocalisedCharacterString text : localised) {
+                            if (text != null) {
+                                if (i18n == null) {
+                                    i18n = new DefaultInternationalString(defaultValue);
+                                }
+                                i18n.add(text.locale, text.text);
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        if (i18n == null && defaultValue != null) {
+            return new SimpleInternationalString(defaultValue);
+        }
+        return i18n;
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/PT_FreeText.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/PT_FreeText.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/TextGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/TextGroup.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/TextGroup.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/TextGroup.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,125 @@
+/*
+ * 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.jaxb.gmd;
+
+import java.util.Locale;
+import javax.xml.bind.annotation.XmlElement;
+
+
+/**
+ * A set of strings localized in different languages. This adapter represents the
+ * {@code <gmd:textGroup>} element defined for embedded translations in ISO-19139
+ * standard. See {@link FreeText} class javadoc for an example.
+ *
+ * <p>If a localized string has a {@code null} locale, then this string will not be
+ * included in this text group because that string should be already included in
+ * the {@code <gco:CharacterString>} element of the parent {@link FreeText}  (at
+ * least in default behavior - actually the above may not be true anymore if the
+ * marshaller {@link org.apache.sis.xml.XML#LOCALE} property has been set).</p>
+ *
+ * <p>The {@code TextGroup} name suggests that this object can contain many localized strings.
+ * However it appears that despite its name, {@code TextGroup} shall always contains exactly 1
+ * localized strings and the whole {@code TextGroup} element shall be repeated for each additional
+ * languages. SIS uses the ISO 19139 compliant form for marshalling, but accepts both forms during
+ * unmarshalling. More specifically, the name suggests that the format should be:</p>
+ *
+ * {@preformat xml
+ *   <gco:CharacterString>Geotoolkit.org, projet OpenSource</gco:CharacterString>
+ *   <gmd:PT_FreeText>
+ *     <gmd:textGroup>
+ *       <gmd:LocalisedCharacterString locale="#locale-eng">Apache SIS, OpenSource Project</gmd:LocalisedCharacterString>
+ *       <gmd:LocalisedCharacterString locale="#locale-ita">Apache SIS, progetto OpenSource</gmd:LocalisedCharacterString>
+ *       <gmd:LocalisedCharacterString locale="#locale-fra">Apache SIS, projet OpenSource</gmd:LocalisedCharacterString>
+ *     </gmd:textGroup>
+ *   </gmd:PT_FreeText>
+ * }
+ *
+ * But the actual official format is:
+ *
+ * {@preformat xml
+ *   <gco:CharacterString>Geotoolkit.org, projet OpenSource</gco:CharacterString>
+ *   <gmd:PT_FreeText>
+ *     <gmd:textGroup>
+ *       <gmd:LocalisedCharacterString locale="#locale-eng">Apache SIS, OpenSource Project</gmd:LocalisedCharacterString>
+ *     </gmd:textGroup>
+ *     <gmd:textGroup>
+ *       <gmd:LocalisedCharacterString locale="#locale-ita">Apache SIS, progetto OpenSource</gmd:LocalisedCharacterString>
+ *     </gmd:textGroup>
+ *     <gmd:textGroup>
+ *       <gmd:LocalisedCharacterString locale="#locale-fra">Apache SIS, projet OpenSource</gmd:LocalisedCharacterString>
+ *     </gmd:textGroup>
+ *   </gmd:PT_FreeText>
+ * }
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see LocalisedCharacterString
+ * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-152">GEOTK-152</a>
+ */
+final class TextGroup {
+    /**
+     * The set of {@linkplain LocalisedCharacterString localized string}.
+     * JAXB uses this field at marshalling-time in order to wrap {@code N}
+     * {@code <LocalisedCharacterString>} elements inside a single {@code <textGroup>} element.
+     *
+     * <p>In ISO 19139 compliant documents, the length of this array shall be exactly 1,
+     * as in the second example of class javadoc. However SIS allows arbitrary length
+     * (as in the first example of class javadoc) for compatibility and convenience reasons.</p>
+     */
+    @XmlElement(name = "LocalisedCharacterString")
+    protected LocalisedCharacterString[] localized;
+
+    /**
+     * Empty constructor only used by JAXB.
+     */
+    public TextGroup() {
+    }
+
+    /**
+     * Constructs a {@linkplain TextGroup text group} for a single locale. This constructor
+     * puts exactly one string in the {@code TextGroup}, as required by ISO 19139. However
+     * it would be possible to declare an other constructor allowing the more compact form
+     * (the smaller ) if there is a need for that in the future.
+     *
+     * @param locale The string language.
+     * @param text The string.
+     */
+    TextGroup(final Locale locale, final String text) {
+        localized = new LocalisedCharacterString[] {
+            new LocalisedCharacterString(locale, text)
+        };
+    }
+
+    /**
+     * Returns a string representation of this text group for debugging purpose.
+     */
+    @Override
+    public String toString() {
+        final StringBuilder buffer = new StringBuilder(getClass().getSimpleName());
+        if (localized != null) {
+            final String lineSeparator = System.lineSeparator();
+            for (LocalisedCharacterString string : localized) {
+                buffer.append(lineSeparator).append("  ").append(string);
+            }
+        }
+        return buffer.append(']').toString();
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/TextGroup.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/TextGroup.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/package-info.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/package-info.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/package-info.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+/**
+ * Miscellaneous objects and adapters defined in the {@code "gmd"} namespace.
+ * This package does not include the adapters for ISO 19115 classes and code
+ * lists, which are defined in their own package.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
+ */
+@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED, namespace = Namespaces.GMD, xmlns = {
+    @XmlNs(prefix = "gmd", namespaceURI = Namespaces.GMD)
+})
+@XmlAccessorType(XmlAccessType.NONE)
+package org.apache.sis.internal.jaxb.gmd;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import org.apache.sis.xml.Namespaces;

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/Anchor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/Anchor.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/Anchor.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/Anchor.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,156 @@
+/*
+ * 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.jaxb.gmx;
+
+import java.net.URI;
+import java.util.Locale;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+import org.opengis.util.InternationalString;
+import org.apache.sis.xml.XLink;
+
+// Related to JDK7
+import java.util.Objects;
+
+
+/**
+ * The {@code Anchor} element, which is included in {@code CharacterString} elements.
+ * This class extends {@link InternationalString} in an opportunist way, in order to allow
+ * direct usage with public API expecting {@link CharSequence} or {@link InternationalString}
+ * object.
+ *
+ * @author  Guilhem Legal (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see <a href="http://www.xml.com/pub/a/2000/09/xlink/part2.html">XLink introduction</a>
+ */
+@XmlType(name = "AnchorType")
+public final class Anchor extends XLink implements InternationalString {
+    /**
+     * Defined as a matter of principle (this class is not expected to be serialized).
+     */
+    private static final long serialVersionUID = -6101324942683322597L;
+
+    /**
+     * Often a short textual description of the URN target.
+     * This is the value returned by {@link #toString()}.
+     */
+    @XmlValue
+    private String value;
+
+    /**
+     * Creates a uninitialized {@code Anchor}.
+     * This constructor is required by JAXB.
+     */
+    public Anchor() {
+    }
+
+    /**
+     * Creates an {@code Anchor} initialized to the given value.
+     *
+     * @param href  A URN to an external resources or an identifier.
+     * @param value Often a short textual description of the URN target.
+     */
+    public Anchor(final URI href, final String value) {
+        setHRef(href);
+        this.value = value;
+    }
+
+    /**
+     * Returns the text as a string, or {@code null} if none.
+     * The null value is expected by {@link GO_CharacterString#toString()}.
+     */
+    @Override
+    public String toString() {
+        return value;
+    }
+
+    /**
+     * Returns the text as a string, or {@code null} if none.
+     */
+    @Override
+    public String toString(final Locale locale) {
+        return value;
+    }
+
+    /**
+     * Returns the number of characters in the value.
+     */
+    @Override
+    public int length() {
+        return (value != null) ? value.length() : 0;
+    }
+
+    /**
+     * Returns the character at the given index.
+     */
+    @Override
+    public char charAt(final int index) {
+        return (value != null ? value : "").charAt(index);
+    }
+
+    /**
+     * Returns the sequence of characters in the given range of index.
+     */
+    @Override
+    public CharSequence subSequence(final int start, final int end) {
+        return (value != null ? value : "").subSequence(start, end);
+    }
+
+    /**
+     * Compares the value of this object with the given international string for order.
+     * Null values are sorted last.
+     *
+     * @param other The string to compare with this anchor type.
+     */
+    @Override
+    public int compareTo(final InternationalString other) {
+        final String ot;
+        if (other == null || (ot = other.toString()) == null) {
+            return (value != null) ? -1 : 0;
+        }
+        return (value != null) ? value.compareTo(ot) : +1;
+    }
+
+    /**
+     * Compares this {@code Anchor} with the given object for equality.
+     *
+     * @param object The object to compare with this anchor type.
+     */
+    @Override
+    public boolean equals(final Object object) {
+        if (object == this) {
+            return true;
+        }
+        if (super.equals(object)) {
+            final Anchor that = (Anchor) object;
+            return Objects.equals(this.value, that.value);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a hash code value for this anchor type.
+     */
+    @Override
+    public int hashCode() {
+        return super.hashCode()*31 + Objects.hashCode(value);
+    }
+}

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/Anchor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/Anchor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/package-info.java?rev=1417780&view=auto
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/package-info.java (added)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/package-info.java Thu Dec  6 09:05:04 2012
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+/**
+ * Miscellaneous objects and adapters defined in the {@code "gmx"} namespace.
+ *
+ * @author  Guilhem Legal (Geomatys)
+ * @since   0.3 (derived from geotk-2.5)
+ * @version 0.3
+ * @module
+ *
+ * @see javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter
+ */
+@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED, namespace = Namespaces.GMX, xmlns = {
+    @XmlNs(prefix = "gmx", namespaceURI = Namespaces.GMX)
+})
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlJavaTypeAdapter(InternationalStringConverter.class)
+package org.apache.sis.internal.jaxb.gmx;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import org.apache.sis.internal.jaxb.gco.InternationalStringConverter;
+import org.apache.sis.xml.Namespaces;

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmx/package-info.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message