Author: desruisseaux
Date: Sat Feb 17 12:27:26 2018
New Revision: 1824584
URL: http://svn.apache.org/viewvc?rev=1824584&view=rev
Log:
Minor refactoring and documentation fixes.
Added:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/InfiniteSet.java
(with props)
Modified:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java
Modified:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java?rev=1824584&r1=1824583&r2=1824584&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/lineage/DefaultLineageTest.java
[UTF-8] Sat Feb 17 12:27:26 2018
@@ -21,6 +21,7 @@ import javax.xml.bind.JAXBException;
import org.apache.sis.internal.jaxb.LegacyNamespaces;
import org.apache.sis.util.iso.SimpleInternationalString;
import org.apache.sis.metadata.iso.DefaultIdentifier;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.XMLTestCase;
import org.junit.Test;
@@ -38,22 +39,31 @@ import static org.apache.sis.test.Assert
*/
public final strictfp class DefaultLineageTest extends XMLTestCase {
/**
- * Tests the marshalling of an {@code "gmd:LI_Source"} element, which
shall become
- * {@code "gmi:LE_Source"} when some ISO 19115-2 properties are defined.
- *
- * @throws JAXBException if an error occurred while marshalling the XML.
+ * Create a lineage to marshal. If {@code extension} is {@code false},
then this method uses
+ * only properties defined in ISO 19115-1. If {@code extension} is {@code
true}, then this
+ * method adds an ISO 19115-2 property.
*/
- @Test
- public void testSource() throws JAXBException {
+ private static DefaultLineage create(final boolean extension) {
final DefaultLineage lineage = new DefaultLineage();
final DefaultSource source = new DefaultSource();
source.setDescription(new SimpleInternationalString("Description of
source data level."));
lineage.setSources(Arrays.asList(source));
- /*
- * If this simpler case, only ISO 19115 elements are defined (no ISO
19115-2).
- * Consequently the XML name shall be "gmd:LI_Source".
- */
- String actual = marshal(lineage, VERSION_2007);
+ if (extension) {
+ source.setProcessedLevel(new DefaultIdentifier("DummyLevel"));
+ }
+ return lineage;
+ }
+
+ /**
+ * Tests the marshalling of a legacy {@code "gmd:LI_Source"} element.
+ * If this case, the test uses only ISO 19115-1 elements (no ISO 19115-2).
+ * Consequently the legacy XML name shall be {@code "gmd:LI_Source"}.
+ *
+ * @throws JAXBException if an error occurred while marshalling the XML.
+ */
+ @Test
+ public void testLegacySource() throws JAXBException {
+ String actual = marshal(create(false), VERSION_2007);
assertXmlEquals(
"<gmd:LI_Lineage xmlns:gmd=\"" + LegacyNamespaces.GMD + '"' +
" xmlns:gco=\"" + LegacyNamespaces.GCO + "\">\n" +
@@ -65,11 +75,20 @@ public final strictfp class DefaultLinea
" </gmd:LI_Source>\n" +
" </gmd:source>\n" +
"</gmd:LI_Lineage>", actual, "xmlns:*");
- /*
- * Now add a ISO 19115-2 specific property. The XML name shall become
"gmi:LE_Source".
- */
- source.setProcessedLevel(new DefaultIdentifier("DummyLevel"));
- actual = marshal(lineage, VERSION_2007);
+ }
+
+ /**
+ * Tests the marshalling of a legacy {@code "gmi:LE_Source"} element.
+ * This test starts with the same metadata than {@link
#testLegacySource()} and adds
+ * an ISO 19115-2 specific property. Consequently the XML name, which was
originally
+ * {@code "gmd:LI_Source"}, shall become {@code "gmi:LE_Source"}.
+ *
+ * @throws JAXBException if an error occurred while marshalling the XML.
+ */
+ @Test
+ @DependsOnMethod("testLegacySource")
+ public void testLegacySourceImagery() throws JAXBException {
+ String actual = marshal(create(true), VERSION_2007);
assertXmlEquals(
"<gmd:LI_Lineage xmlns:gmd=\"" + LegacyNamespaces.GMD + '"' +
" xmlns:gmi=\"" + LegacyNamespaces.GMI + '"' +
Added:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/InfiniteSet.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/InfiniteSet.java?rev=1824584&view=auto
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/InfiniteSet.java
(added)
+++
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/InfiniteSet.java
[UTF-8] Sat Feb 17 12:27:26 2018
@@ -0,0 +1,58 @@
+/*
+ * 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.test.xml;
+
+import java.util.Set;
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Iterator;
+
+
+/**
+ * An unmodifiable set used as a sentinel value meaning "all" elements.
+ * All {@code add(…)} operations are no-op since the set already contains
everything.
+ * All {@code contains(…)} operations always return {@code true}.
+ * The later is not strictly correct since we should check the type,
+ * but this is not needed for the purpose of this internal class.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ *
+ * @param <E> ignored.
+ *
+ * @since 1.0
+ * @module
+ */
+final class InfiniteSet<E> extends AbstractSet<E> {
+ /**
+ * The singleton instance. This is not parameterized on intend.
+ */
+ @SuppressWarnings("rawtypes")
+ static final Set INSTANCE = new InfiniteSet();
+
+ /** For the unique {@link #INSTANCE} only. */
+ private InfiniteSet() {}
+
+ @Override public int size() {return
Integer.MAX_VALUE;}
+ @Override public boolean isEmpty() {return
false;}
+ @Override public boolean add(E e) {return
false;}
+ @Override public boolean addAll(Collection<? extends E> c) {return
false;}
+ @Override public boolean contains(Object v) {return
true;}
+ @Override public boolean containsAll(Collection<?> c) {return
true;}
+ @Override public Iterator<E> iterator() {throw new
UnsupportedOperationException();}
+ @Override public String toString() {return
"InfiniteSet";}
+}
Propchange:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/InfiniteSet.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/InfiniteSet.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java?rev=1824584&r1=1824583&r2=1824584&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-metadata/src/test/java/org/apache/sis/test/xml/PackageVerifier.java
[UTF-8] Sat Feb 17 12:27:26 2018
@@ -19,10 +19,8 @@ package org.apache.sis.test.xml;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Collection;
import java.util.Collections;
-import java.util.AbstractSet;
import java.io.IOException;
import java.lang.reflect.Type;
import java.lang.reflect.Field;
@@ -58,11 +56,8 @@ final strictfp class PackageVerifier {
/**
* Sentinel value used in {@link #LEGACY_NAMESPACES} for meaning "all
properties in that namespace".
*/
- private static final Set<String> ALL = new AbstractSet<String>() {
- @Override public boolean contains(Object v) {return true;}
- @Override public int size() {return 0;}
- @Override public Iterator<String> iterator() {return
Collections.emptyIterator();}
- };
+ @SuppressWarnings("unchecked")
+ private static final Set<String> ALL = InfiniteSet.INSTANCE;
/**
* Classes or properties having a JAXB annotation in this namespace should
be deprecated.
Modified:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java?rev=1824584&r1=1824583&r2=1824584&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/internal/util/CollectionsExt.java
[UTF-8] Sat Feb 17 12:27:26 2018
@@ -17,6 +17,7 @@
package org.apache.sis.internal.util;
import java.util.*;
+import java.util.function.Predicate;
import java.lang.reflect.Array;
import org.opengis.util.CodeList;
import org.apache.sis.util.Static;
@@ -28,9 +29,6 @@ import org.opengis.parameter.InvalidPara
import static org.apache.sis.util.collection.Containers.hashMapCapacity;
-// Branch-dependent imports
-import java.util.function.Predicate;
-
/**
* Static methods working on {@link Collection} objects.
@@ -63,6 +61,21 @@ public final class CollectionsExt extend
}
/**
+ * Returns a queue which is always empty and accepts no element.
+ * This method will be removed if a future JDK version provides such
method in {@link Collections}.
+ *
+ * @param <E> the type of elements in the empty collection.
+ * @return an empty collection.
+ *
+ * @see Collections#emptyList()
+ * @see Collections#emptySet()
+ */
+ @SuppressWarnings("unchecked")
+ public static <E> Queue<E> emptyQueue() {
+ return EmptyQueue.INSTANCE;
+ }
+
+ /**
* Returns an empty collection of the given type, or {@code null} if the
given type is unknown to this method.
*
* @param type the desired collection type.
@@ -141,20 +154,6 @@ public final class CollectionsExt extend
}
/**
- * Returns a {@linkplain Queue queue} which is always empty and accepts no
element.
- *
- * @param <E> the type of elements in the empty collection.
- * @return an empty collection.
- *
- * @see Collections#emptyList()
- * @see Collections#emptySet()
- */
- @SuppressWarnings({"unchecked","rawtype"})
- public static <E> Queue<E> emptyQueue() {
- return EmptyQueue.INSTANCE;
- }
-
- /**
* Returns the given value as a singleton if non-null, or returns an empty
set otherwise.
*
* @param <E> the element type.
Modified:
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java
URL:
http://svn.apache.org/viewvc/sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java?rev=1824584&r1=1824583&r2=1824584&view=diff
==============================================================================
---
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java
[UTF-8] (original)
+++
sis/branches/ISO-19115-3/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredReader.java
[UTF-8] Sat Feb 17 12:27:26 2018
@@ -59,14 +59,14 @@ import static javax.xml.stream.XMLStream
*/
final class FilteredReader extends FilteredXML implements XMLEventReader {
/**
- * Location of the file listing types and attributes contained in
namespaces.
- * The file location is relative to this {@code NamespaceContent} class.
+ * Location of the file listing types and properties contained in
namespaces.
+ * The file location is relative to this {@code FilteredReader} class.
* The file format is a tree structured with indentation as below:
*
* <ul>
- * <li>Lines with zero-spaces indentation are namespace URIs.</li>
+ * <li>Lines with zero-space indentation are namespace URIs.</li>
* <li>Lines with two-spaces indentation are classes within the last
namespace URIs found so far.</li>
- * <li>Lines with four-spaces indentation are attributes within the last
class found so far.</li>
+ * <li>Lines with four-spaces indentation are properties within the last
class found so far.</li>
* <li>All other indentations are illegal and cause an {@link
InvalidPropertiesFormatException} to be thrown.
* This exception type is not really appropriate since the file
format is not a {@code .properties} file,
* but it is the closest we could find in existing exceptions and we
don't want to define a new exception
@@ -102,9 +102,9 @@ final class FilteredReader extends Filte
* The mapping from (<var>type</var>, <var>attribute</var>) pairs to
namespaces.
*
* <ul>
- * <li>Keys are XML names of types (e.g. {@code "CI_Citation"})</li>
+ * <li>Keys are XML names of types, ignoring {@code "_TYPE"} suffix
(e.g. {@code "CI_Citation"})</li>
* <li>Values are maps where:<ul>
- * <li>Keys are XML names of attributes (e.g. {@code "title"}) or
{@value #TYPE_KEY}</li>
+ * <li>Keys are XML names of properties (e.g. {@code "title"}) or
{@value #TYPE_KEY}</li>
* <li>Values are either:<ul>
* <li>Namespace URI if {@link #isNamespace(String)} returns {@code
true} for that value.</li>
* <li>New name of the element otherwise. In such case, the map must
be queried again with
@@ -531,6 +531,9 @@ final class FilteredReader extends Filte
/**
* Reads the content of a text-only element. Forwards from the underlying
reader as-is.
+ *
+ * @todo Untested. In particular, it is not clear how to update {@link
#outerElements}.
+ * By change, JAXB does not seem to invoke this method.
*/
@Override
public String getElementText() throws XMLStreamException {