sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1466960 - in /sis/branches/JDK7: sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/ sis-utility/src/mai...
Date Thu, 11 Apr 2013 16:48:02 GMT
Author: desruisseaux
Date: Thu Apr 11 16:48:02 2013
New Revision: 1466960

URL: http://svn.apache.org/r1466960
Log:
Added a small set of Citation constants. This set will need to be completed later.
Note that Geotk defined all constants programmatically. For SIS, we may try to use
an embedded database instead.

Added:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
  (with props)
Modified:
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Identifier.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/UnmodifiableIdentifier.java
    sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Identifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Identifier.java?rev=1466960&r1=1466959&r2=1466960&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Identifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Identifier.java
[UTF-8] Thu Apr 11 16:48:02 2013
@@ -108,14 +108,13 @@ public final class MD_Identifier extends
      */
     @XmlElement(name = "RS_Identifier")
     public UnmodifiableIdentifier getReferenceIdentifier() {
-        if (skip()) return null;
-        final Identifier metadata = this.metadata;
-        if (!(metadata instanceof ReferenceIdentifier)) {
-            return null;
+        if (!skip()) {
+            final Identifier metadata = this.metadata;
+            if (metadata instanceof ReferenceIdentifier) {
+                return UnmodifiableIdentifier.castOrCopy((ReferenceIdentifier) metadata);
+            }
         }
-        return (metadata instanceof UnmodifiableIdentifier) ?
-            (UnmodifiableIdentifier) metadata :
-            new UnmodifiableIdentifier((ReferenceIdentifier) metadata);
+        return null;
     }
 
     /**

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/UnmodifiableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/UnmodifiableIdentifier.java?rev=1466960&r1=1466959&r2=1466960&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/UnmodifiableIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/UnmodifiableIdentifier.java
[UTF-8] Thu Apr 11 16:48:02 2013
@@ -38,7 +38,7 @@ import org.apache.sis.util.resources.Err
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.iso.SimpleInternationalString;
 import org.apache.sis.util.iso.DefaultInternationalString;
-import org.apache.sis.internal.simple.SimpleCitation;
+import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.internal.jaxb.metadata.CI_Citation;
 import org.apache.sis.internal.jaxb.metadata.ReferenceSystemMetadata;
 import org.apache.sis.internal.jaxb.gco.StringAdapter;
@@ -277,7 +277,7 @@ public class UnmodifiableIdentifier impl
                 }
                 case AUTHORITY_KEY: {
                     if (value instanceof String) {
-                        value = new SimpleCitation((String) value);
+                        value = Citations.fromName((String) value);
                     }
                     authority = value;
                     continue;
@@ -394,6 +394,31 @@ public class UnmodifiableIdentifier impl
     }
 
     /**
+     * Returns a SIS identifier implementation with the values of the given arbitrary implementation.
+     * This method performs the first applicable actions in the following choices:
+     *
+     * <ul>
+     *   <li>If the given object is {@code null}, then this method returns {@code null}.</li>
+     *   <li>Otherwise if the given object is already an instance of
+     *       {@code UnmodifiableIdentifier}, then it is returned unchanged.</li>
+     *   <li>Otherwise a new {@code UnmodifiableIdentifier} instance is created using
the
+     *       {@linkplain #UnmodifiableIdentifier(ReferenceIdentifier) copy constructor}
+     *       and returned. Note that this is a <cite>shallow</cite> copy operation,
since the other
+     *       metadata contained in the given object are not recursively copied.</li>
+     * </ul>
+     *
+     * @param  object The object to get as a SIS implementation, or {@code null} if none.
+     * @return A SIS implementation containing the values of the given object (may be the
+     *         given object itself), or {@code null} if the argument was null.
+     */
+    public static UnmodifiableIdentifier castOrCopy(final ReferenceIdentifier object) {
+        if (object == null || object instanceof UnmodifiableIdentifier) {
+            return (UnmodifiableIdentifier) object;
+        }
+        return new UnmodifiableIdentifier(object);
+    }
+
+    /**
      * Identifier code or name, optionally from a controlled list or pattern.
      *
      * @return The code, never {@code null}.

Added: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java?rev=1466960&view=auto
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
(added)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
[UTF-8] Thu Apr 11 16:48:02 2013
@@ -0,0 +1,207 @@
+/*
+ * 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.metadata.iso.citation;
+
+import org.opengis.metadata.citation.Citation;
+import org.apache.sis.util.Static;
+import org.apache.sis.xml.IdentifierSpace;
+import org.apache.sis.internal.simple.SimpleCitation;
+import org.apache.sis.util.CharSequences;
+
+
+/**
+ * A set of pre-defined constants and static methods working on {@linkplain Citation citations}.
+ * The citation constants declared in this class are for:
+ *
+ * <ul>
+ *   <li><cite>Organizations</cite> (e.g. {@linkplain #OGC})</li>
+ *   <li><cite>Specifications</cite> (e.g. {@linkplain #WMS})</li>
+ *   <li><cite>Authorities</cite> that maintain definitions of codes (e.g.
{@linkplain #EPSG})</li>
+ * </ul>
+ *
+ * In the later case, the citations are actually of kind {@link IdentifierSpace}.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.3 (derived from geotk-2.2)
+ * @version 0.3
+ * @module
+ */
+public final class Citations extends Static {
+    /**
+     * The <a href="http://www.iso.org/">International Organization for Standardization</a>.
+     *
+     * @category Organization
+     */
+    public static final Citation ISO = new SimpleCitation("ISO");
+
+    /**
+     * The <a href="http://www.opengeospatial.org">Open Geospatial Consortium</a>
organization.
+     * "Open Geospatial Consortium" is the new name for "OpenGIS consortium".
+     *
+     * @see org.apache.sis.io.wkt.Convention#OGC
+     * @category Organization
+     */
+    public static final Citation OGC = new SimpleCitation("OGC");
+
+    /**
+     * <cite>International Standard Book Number</cite> (ISBN) defined by ISO-2108.
+     * The ISO-19115 metadata standard defines a specific attribute for this information,
+     * but the SIS library handles it like any other identifier.
+     *
+     * @see DefaultCitation#getISBN()
+     *
+     * @category Code space
+     */
+    public static final IdentifierSpace<String> ISBN = DefaultCitation.ISBN;
+
+    /**
+     * <cite>International Standard Serial Number</cite> (ISSN) defined by ISO-3297.
+     * The ISO-19115 metadata standard defines a specific attribute for this information,
+     * but the SIS library handles it like any other identifier.
+     *
+     * @see DefaultCitation#getISSN()
+     *
+     * @category Code space
+     */
+    public static final IdentifierSpace<String> ISSN = DefaultCitation.ISSN;
+
+    /**
+     * List of citations declared in this class.
+     */
+    private static final Citation[] AUTHORITIES = {
+        ISO, OGC, ISBN, ISSN
+    };
+
+    /**
+     * Do not allows instantiation of this class.
+     */
+    private Citations() {
+    }
+
+    /**
+     * Returns a citation of the given name. The method makes the following choice:
+     *
+     * <ul>
+     *   <li>If the given title is {@code null} or empty (ignoring spaces), then this
method
+     *       returns {@code null}.</li>
+     *   <li>Otherwise if the given name matches a {@linkplain Citation#getTitle()
title} or an
+     *       {@linkplain Citation#getAlternateTitles() alternate titles} of one of the pre-defined
+     *       constants ({@link #EPSG}, {@link #GEOTIFF}, <i>etc.</i>), then that
constant
+     *       is returned.</li>
+     *   <li>Otherwise, a new citation is created with the specified name as the title.</li>
+     * </ul>
+     *
+     * @param  title The citation title (or alternate title), or {@code null}.
+     * @return A citation using the specified name, or {@code null} if the given title is
null
+     *         or empty.
+     */
+    public static Citation fromName(String title) {
+        if (title == null || ((title = CharSequences.trimWhitespaces(title)).isEmpty()))
{
+            return null;
+        }
+        for (int i=0; i<AUTHORITIES.length; i++) {
+            final Citation citation = AUTHORITIES[i];
+            if (titleMatches(citation, title)) {
+                return citation;
+            }
+        }
+        return new SimpleCitation(title);
+    }
+
+    /**
+     * Returns {@code true} if at least one {@linkplain Citation#getTitle() title} or
+     * {@linkplain Citation#getAlternateTitles() alternate title} in {@code c1} is leniently
+     * equal to a title or alternate title in {@code c2}. The comparison is case-insensitive
+     * and ignores every character which is not a {@linkplain Character#isLetterOrDigit(int)
+     * letter or a digit}. The titles ordering is not significant.
+     *
+     * @param  c1 The first citation to compare, or {@code null}.
+     * @param  c2 the second citation to compare, or {@code null}.
+     * @return {@code true} if both arguments are non-null, and at least one title or
+     *         alternate title matches.
+     */
+    public static boolean titleMatches(final Citation c1, final Citation c2) {
+        return org.apache.sis.internal.util.Citations.titleMatches(c1, c2);
+    }
+
+    /**
+     * Returns {@code true} if the {@linkplain Citation#getTitle() title} or any
+     * {@linkplain Citation#getAlternateTitles() alternate title} in the given citation
+     * matches the given string. The comparison is case-insensitive and ignores every character
+     * which is not a {@linkplain Character#isLetterOrDigit(int) letter or a digit}.
+     *
+     * @param  citation The citation to check for, or {@code null}.
+     * @param  title The title or alternate title to compare, or {@code null}.
+     * @return {@code true} if both arguments are non-null, and the title or alternate
+     *         title matches the given string.
+     */
+    public static boolean titleMatches(final Citation citation, String title) {
+        return org.apache.sis.internal.util.Citations.titleMatches(citation, title);
+    }
+
+    /**
+     * Returns {@code true} if at least one {@linkplain Citation#getIdentifiers() identifier}
in
+     * {@code c1} is equal to an identifier in {@code c2}. The comparison is case-insensitive
+     * and ignores every character which is not a {@linkplain Character#isLetterOrDigit(int)
+     * letter or a digit}. The identifier ordering is not significant.
+     *
+     * <p>If (and <em>only</em> if) the citations do not contains any identifier,
then this method
+     * fallback on titles comparison using the {@link #titleMatches(Citation,Citation) titleMatches}
+     * method. This fallback exists for compatibility with client codes using the citation
+     * {@linkplain Citation#getTitle() titles} without identifiers.</p>
+     *
+     * @param  c1 The first citation to compare, or {@code null}.
+     * @param  c2 the second citation to compare, or {@code null}.
+     * @return {@code true} if both arguments are non-null, and at least one identifier,
+     *         title or alternate title matches.
+     */
+    public static boolean identifierMatches(final Citation c1, final Citation c2) {
+        return org.apache.sis.internal.util.Citations.identifierMatches(c1, c2);
+    }
+
+    /**
+     * Returns {@code true} if any {@linkplain Citation#getIdentifiers() identifiers} in
the given
+     * citation matches the given string. The comparison is case-insensitive and ignores
every
+     * character which is not a {@linkplain Character#isLetterOrDigit(int) letter or a digit}.
+     *
+     * <p>If (and <em>only</em> if) the citation does not contain any identifier,
then this method
+     * fallback on titles comparison using the {@link #titleMatches(Citation,String) titleMatches}
+     * method. This fallback exists for compatibility with client codes using citation
+     * {@linkplain Citation#getTitle() titles} without identifiers.</p>
+     *
+     * @param  citation The citation to check for, or {@code null}.
+     * @param  identifier The identifier to compare, or {@code null}.
+     * @return {@code true} if both arguments are non-null, and the title or alternate title
+     *         matches the given string.
+     */
+    public static boolean identifierMatches(final Citation citation, final String identifier)
{
+        return org.apache.sis.internal.util.Citations.identifierMatches(citation, identifier);
+    }
+
+    /**
+     * Returns the shortest identifier for the specified citation, or the title if there
is
+     * no identifier. This method is useful for extracting the namespace from an authority,
+     * for example {@code "EPSG"}.
+     *
+     * @param  citation The citation for which to get the identifier, or {@code null}.
+     * @return The shortest identifier of the given citation, or {@code null} if the
+     *         given citation was null or doesn't declare any identifier or title.
+     */
+    public static String getIdentifier(final Citation citation) {
+        return org.apache.sis.internal.util.Citations.getIdentifier(citation);
+    }
+}

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java?rev=1466960&r1=1466959&r2=1466960&view=diff
==============================================================================
--- sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/DefaultCitation.java
[UTF-8] Thu Apr 11 16:48:02 2013
@@ -81,8 +81,8 @@ public class DefaultCitation extends ISO
      * The authority for International Standard Book Number.
      *
      * <p><b>Implementation note:</b> This field is read by reflection
in
-     * {@link org.apache.sis.internal.jaxb.NonMarshalledAuthority}. IF this
-     * field is renamed or moved, then {@code NonMarshalledAuthority} needs
+     * {@link org.apache.sis.internal.jaxb.NonMarshalledAuthority#getCitation(String)}.
+     * If this field is renamed or moved, then {@code NonMarshalledAuthority} needs
      * to be updated.</p>
      */
     static final IdentifierSpace<String> ISBN = new NonMarshalledAuthority<>("ISBN",
NonMarshalledAuthority.ISBN);
@@ -91,8 +91,8 @@ public class DefaultCitation extends ISO
      * The authority for International Standard Serial Number.
      *
      * <p><b>Implementation note:</b> This field is read by reflection
in
-     * {@link org.apache.sis.internal.jaxb.NonMarshalledAuthority}. IF this
-     * field is renamed or moved, then {@code NonMarshalledAuthority} needs
+     * {@link org.apache.sis.internal.jaxb.NonMarshalledAuthority#getCitation(String)}.
+     * If this field is renamed or moved, then {@code NonMarshalledAuthority} needs
      * to be updated.</p>
      */
     static final IdentifierSpace<String> ISSN = new NonMarshalledAuthority<>("ISSN",
NonMarshalledAuthority.ISSN);

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java?rev=1466960&r1=1466959&r2=1466960&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/jaxb/NonMarshalledAuthority.java
[UTF-8] Thu Apr 11 16:48:02 2013
@@ -19,12 +19,15 @@ package org.apache.sis.internal.jaxb;
 import java.util.Iterator;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.io.Serializable;
 import java.io.ObjectStreamException;
 import java.lang.reflect.Field;
 import org.opengis.metadata.Identifier;
 import org.apache.sis.internal.simple.SimpleCitation;
 import org.apache.sis.util.logging.Logging;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.xml.IdentifierSpace;
 
 
@@ -71,6 +74,12 @@ public final class NonMarshalledAuthorit
     private static final long serialVersionUID = 6299502270649111201L;
 
     /**
+     * Sets to {@code true} if {@link #getCitation(String)} has already logged a warning.
+     * This is used in order to avoid flooding the logs with the same message.
+     */
+    private static volatile boolean warningLogged;
+
+    /**
      * Ordinal values for switch statements. The constant defined here shall
      * mirror the constants defined in the {@link IdentifierSpace} interface
      * and {@link org.apache.sis.metadata.iso.citation.DefaultCitation} class.
@@ -210,7 +219,9 @@ public final class NonMarshalledAuthorit
     }
 
     /**
-     * Returns one of the constants in the {@link DefaultCitation} class.
+     * Returns one of the constants in the {@link DefaultCitation} class, or {@code null}
if none.
+     * We need to use Java reflection because the {@code sis-metadata} module may not be
in the
+     * classpath.
      */
     private static IdentifierSpace<?> getCitation(final String name) throws ObjectStreamException
{
         try {
@@ -218,13 +229,19 @@ public final class NonMarshalledAuthorit
             field.setAccessible(true);
             return (IdentifierSpace<?>) field.get(null);
         } catch (ReflectiveOperationException e) {
-            Logging.unexpectedException(NonMarshalledAuthority.class, "readResolve", e);
+            if (!warningLogged) {
+                warningLogged = true;
+                final LogRecord record = Errors.getResources(null).getLogRecord(Level.WARNING,
+                        Errors.Keys.MissingRequiredModule_1, "sis-metadata");
+                record.setThrown(e);
+                Logging.log(NonMarshalledAuthority.class, "readResolve", record);
+            }
         }
         return null;
     }
 
     /**
-     * Invoked at deserialization time in order to setIdentifiers the deserialized instance
+     * Invoked at deserialization time in order to replace the deserialized instance
      * by the appropriate instance defined in the {@link IdentifierSpace} interface.
      */
     private Object readResolve() throws ObjectStreamException {



Mime
View raw message