Author: desruisseaux
Date: Fri Jun 14 11:29:46 2013
New Revision: 1493029
URL: http://svn.apache.org/r1493029
Log:
Enabled support for ISO 19139 XML output on the command-line.
Added:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataTypes.java
(with props)
sis/branches/JDK7/core/sis-metadata/src/main/resources/
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration
(with props)
Modified:
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Option.java
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options.properties
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options_fr.properties
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java
sis/branches/JDK7/ide-project/NetBeans/build.xml
Modified:
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
[UTF-8] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -32,23 +32,24 @@ import org.apache.sis.util.logging.Monol
/**
* Command line interface for Apache SIS. The {@link #main(String[])} method
accepts the following commands:
*
- * <ul>
- * <li>{@code help} - Show a help overview.</li>
- * <li>{@code about} - Show information about Apache SIS and system
configuration.</li>
- * <li>{@code metadata} - Show metadata information for the given file.</li>
- * </ul>
+ * <blockquote><table class="compact">
+ * <tr><td>{@code help} </td><td>Show a help overview.</td></tr>
+ * <tr><td>{@code about} </td><td>Show information about Apache SIS and
system configuration.</td></tr>
+ * <tr><td>{@code metadata} </td><td>Show metadata information for the given
file.</td></tr>
+ * </table></blockquote>
*
* Each command can accepts an arbitrary amount of the following options:
*
- * <ul>
- * <li>{@code --locale} - The locale to use for the command output.</li>
- * <li>{@code --timezone} - The timezone for the dates to be formatted.</li>
- * <li>{@code --encoding} - The encoding to use for the command output.</li>
- * <li>{@code --colors} - Whether colorized output shall be enabled.</li>
- * <li>{@code --brief} - Whether the output should contains only brief
information.</li>
- * <li>{@code --verbose} - Whether the output should contains more detailed
information.</li>
- * <li>{@code --help} - Lists the options available for a specific
command.</li>
- * </ul>
+ * <blockquote><table class="compact">
+ * <tr><td>{@code --format} </td><td>The output format (XML or
text).</td></tr>
+ * <tr><td>{@code --locale} </td><td>The locale to use for the command
output.</td></tr>
+ * <tr><td>{@code --timezone} </td><td>The timezone for the dates to be
formatted.</td></tr>
+ * <tr><td>{@code --encoding} </td><td>The encoding to use for the command
output.</td></tr>
+ * <tr><td>{@code --colors} </td><td>Whether colorized output shall be
enabled.</td></tr>
+ * <tr><td>{@code --brief} </td><td>Whether the output should contains only
brief information.</td></tr>
+ * <tr><td>{@code --verbose} </td><td>Whether the output should contains more
detailed information.</td></tr>
+ * <tr><td>{@code --help} </td><td>Lists the options available for a
specific command.</td></tr>
+ * </table></blockquote>
*
* The {@code --locale}, {@code --timezone} and {@code --encoding} options
apply to the command output sent
* to the {@linkplain System#out standard output stream}, but usually do not
apply to the error messages sent
Modified:
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
[UTF-8] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -18,6 +18,8 @@ package org.apache.sis.console;
import java.util.EnumSet;
import java.io.IOException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.JAXBException;
import org.opengis.metadata.Metadata;
import org.apache.sis.metadata.MetadataStandard;
import org.apache.sis.metadata.ValueExistencePolicy;
@@ -27,6 +29,9 @@ import org.apache.sis.storage.netcdf.Net
import org.apache.sis.util.collection.TableColumn;
import org.apache.sis.util.collection.TreeTable;
import org.apache.sis.util.collection.TreeTableFormat;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.xml.MarshallerPool;
+import org.apache.sis.xml.XML;
/**
@@ -42,7 +47,7 @@ final class MetadataSC extends SubComman
* Creates the {@code "metadata"} sub-command.
*/
MetadataSC(final int commandIndex, final String... args) throws
InvalidOptionException {
- super(commandIndex, args, EnumSet.of(Option.LOCALE, Option.TIMEZONE,
Option.ENCODING, Option.HELP));
+ super(commandIndex, args, EnumSet.of(Option.FORMAT, Option.LOCALE,
Option.TIMEZONE, Option.ENCODING, Option.HELP));
}
/**
@@ -51,10 +56,26 @@ final class MetadataSC extends SubComman
* @todo NetCDF data store is hard-coded for now. Will need a dynamic
mechanism in the future.
*
* @throws DataStoreException If an error occurred while reading the
NetCDF file.
+ * @throws JAXBException If an error occurred while producing the XML
output.
* @throws IOException Should never happen, since we are appending to a
print writer.
*/
@Override
- public int run() throws DataStoreException, IOException {
+ public int run() throws InvalidOptionException, DataStoreException,
JAXBException, IOException {
+ /*
+ * Output format can be either "text" (the default) or "xml".
+ */
+ boolean toXML = false;
+ final String format = options.get(Option.FORMAT);
+ if (format != null && !format.equalsIgnoreCase("text")) {
+ if (!format.equalsIgnoreCase("xml")) {
+ throw new InvalidOptionException(Errors.format(
+ Errors.Keys.IllegalOptionValue_2, "format", format),
format);
+ }
+ toXML = true;
+ }
+ /*
+ * Read metadata from the data storage.
+ */
if (hasUnexpectedFileCount(1, 1)) {
return Command.INVALID_ARGUMENT_EXIT_CODE;
}
@@ -62,11 +83,22 @@ final class MetadataSC extends SubComman
try (NetcdfStore store = new NetcdfStore(new
StorageConnector(files.get(0)))) {
metadata = store.getMetadata();
}
+ /*
+ * Format metadata to the standard output stream.
+ */
if (metadata != null) {
- final TreeTable tree =
MetadataStandard.ISO_19115.asTreeTable(metadata,
ValueExistencePolicy.NON_EMPTY);
- final TreeTableFormat format = new TreeTableFormat(locale,
timezone);
- format.setColumns(TableColumn.NAME, TableColumn.VALUE);
- format.format(tree, out);
+ if (toXML) {
+ final MarshallerPool pool = new MarshallerPool(null);
+ final Marshaller marshaller = pool.acquireMarshaller();
+ marshaller.setProperty(XML.LOCALE, locale);
+ marshaller.setProperty(XML.TIMEZONE, timezone);
+ marshaller.marshal(metadata, out);
+ } else {
+ final TreeTable tree =
MetadataStandard.ISO_19115.asTreeTable(metadata,
ValueExistencePolicy.NON_EMPTY);
+ final TreeTableFormat tf = new TreeTableFormat(locale,
timezone);
+ tf.setColumns(TableColumn.NAME, TableColumn.VALUE);
+ tf.format(tree, out);
+ }
out.flush();
}
return 0;
Modified:
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Option.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Option.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Option.java
[UTF-8] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Option.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -30,6 +30,11 @@ import org.apache.sis.util.resources.Err
*/
enum Option {
/**
+ * The output format. Examples: {@code "xml"}, {@code "text"}.
+ */
+ FORMAT(true),
+
+ /**
* The locale for the output produced by the command.
*/
LOCALE(true),
Modified:
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options.properties?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options.properties
[ISO-8859-1] Fri Jun 14 11:29:46 2013
@@ -1,4 +1,5 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.
+format=The output format (for instance XML or text).
locale=The locale to use for the command output.
timezone=The timezone for the dates to be formatted.
encoding=The encoding to use for the command output.
Modified:
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options_fr.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options_fr.properties?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options_fr.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Options_fr.properties
[ISO-8859-1] Fri Jun 14 11:29:46 2013
@@ -1,4 +1,5 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.
+format=Le format de sortie (par exemple XML ou texte).
locale=Les paramètres régionaux à utiliser pour la sortie de la commande.
timezone=Le fuseau horaire des dates à écrire.
encoding=L\u2019encodage des caractères à utiliser pour la sortie de la
commande.
Modified:
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -18,6 +18,7 @@ package org.apache.sis.console;
import java.net.URL;
import org.opengis.wrapper.netcdf.IOTestCase;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
@@ -46,11 +47,32 @@ public final strictfp class MetadataSCTe
assertNotNull(IOTestCase.NCEP, url);
final MetadataSC test = new MetadataSC(0, SubCommand.TEST,
url.toString());
test.run();
- final String result = test.outputBuffer.toString();
- assertTrue("DefaultMetadata",
result.startsWith("DefaultMetadata"));
- assertTrue("ISO 19115-2", result.contains
("ISO 19115-2"));
- assertTrue("Sea Surface Temperature Analysis Model", result.contains
("Sea Surface Temperature Analysis Model"));
- assertTrue("GCMD Science Keywords", result.contains
("GCMD Science Keywords"));
- assertTrue("NOAA/NWS/NCEP", result.contains
("NOAA/NWS/NCEP"));
+ verifyNetCDF("DefaultMetadata", test.outputBuffer.toString());
+ }
+
+ /**
+ * Verifies the NetCDF metadata. The given string can be either a text
format or XML format.
+ * This method will check only for some keyword - this is not an extensive
check of the result.
+ */
+ private static void verifyNetCDF(final String expectedHeader, final String
result) {
+ assertTrue(expectedHeader,
result.startsWith(expectedHeader));
+ assertTrue("ISO 19115-2",
result.contains("ISO 19115-2"));
+ assertTrue("Sea Surface Temperature Analysis Model",
result.contains("Sea Surface Temperature Analysis Model"));
+ assertTrue("GCMD Science Keywords",
result.contains("GCMD Science Keywords"));
+ assertTrue("NOAA/NWS/NCEP",
result.contains("NOAA/NWS/NCEP"));
+ }
+
+ /**
+ * Tests with the same file than {@link #testNetCDF()}, but producing a
XML output.
+ *
+ * @throws Exception Should never happen.
+ */
+ @Test
+ @DependsOnMethod("testNetCDF")
+ public void testFormatXML() throws Exception {
+ final URL url = IOTestCase.class.getResource(IOTestCase.NCEP);
+ final MetadataSC test = new MetadataSC(0, SubCommand.TEST,
url.toString(), "--format", "XML");
+ test.run();
+ verifyNetCDF("<?xml", test.outputBuffer.toString());
}
}
Added:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataTypes.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataTypes.java?rev=1493029&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataTypes.java
(added)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataTypes.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -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.
+ */
+package org.apache.sis.internal.metadata;
+
+import java.util.Collection;
+import org.apache.sis.internal.jaxb.TypeRegistration;
+import org.apache.sis.metadata.iso.DefaultMetadata;
+
+
+/**
+ * Declares the classes of objects to be marshalled using a default {@code
MarshallerPool}.
+ * This class is declared in the {@code
META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration} file.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+public final class MetadataTypes extends TypeRegistration {
+ /**
+ * Adds to the given collection the metadata types that should be given to
the initial JAXB context.
+ */
+ @Override
+ public void getTypes(final Collection<Class<?>> addTo) {
+ addTo.add(DefaultMetadata.class);
+ }
+}
Propchange:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataTypes.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/MetadataTypes.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/content/DefaultCoverageDescription.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -41,7 +41,7 @@ import org.apache.sis.xml.Namespaces;
* @module
*/
@XmlType(name = "MD_CoverageDescription_Type", propOrder = {
- "attributeDescription",
+// TODO "attributeDescription",
"contentType",
"dimensions",
"rangeElementDescriptions"
@@ -135,7 +135,7 @@ public class DefaultCoverageDescription
* Returns the description of the attribute described by the measurement
value.
*/
@Override
- @XmlElement(name = "attributeDescription", required = true)
+ // TODO @XmlElement(name = "attributeDescription", required = true)
public RecordType getAttributeDescription() {
return attributeDescription;
}
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -126,7 +126,7 @@ public class DefaultTemporalExtent exten
* @return The content date.
*/
@Override
- @XmlElement(name = "extent", required = true)
+ // TODO @XmlElement(name = "extent", required = true)
public TemporalPrimitive getExtent() {
return extent;
}
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultVerticalExtent.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -45,7 +45,7 @@ import org.apache.sis.internal.metadata.
@XmlType(name = "EX_VerticalExtent_Type", propOrder = {
"minimumValue",
"maximumValue",
- "verticalCRS"
+// TODO "verticalCRS"
})
@XmlRootElement(name = "EX_VerticalExtent")
public class DefaultVerticalExtent extends ISOMetadata implements
VerticalExtent {
@@ -178,7 +178,7 @@ public class DefaultVerticalExtent exten
* identification includes unit of measure.
*/
@Override
- @XmlElement(name = "verticalCRS", required = true)
+ // TODO @XmlElement(name = "verticalCRS", required = true)
public VerticalCRS getVerticalCRS() {
return verticalCRS;
}
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/identification/DefaultResolution.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -48,7 +48,7 @@ import org.apache.sis.internal.metadata.
*/
@XmlType(name = "MD_Resolution_Type", propOrder = {
"equivalentScale",
- "distance"
+// TODO "distance"
})
@XmlRootElement(name = "MD_Resolution")
public class DefaultResolution extends ISOMetadata implements Resolution {
@@ -170,7 +170,7 @@ public class DefaultResolution extends I
@Override
@ValueRange(minimum=0, isMinIncluded=false)
// @XmlJavaTypeAdapter(GO_Distance.class) // TODO
- @XmlElement(name = "distance")
+// @XmlElement(name = "distance")
public Double getDistance() {
return isDistance() ? (Double) scaleOrDistance : null;
}
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/maintenance/DefaultMaintenanceInformation.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -48,7 +48,7 @@ import static org.apache.sis.internal.me
@XmlType(name = "MD_MaintenanceInformation_Type", propOrder = {
"maintenanceAndUpdateFrequency",
"dateOfNextUpdate",
- "userDefinedMaintenanceFrequency",
+// TODO "userDefinedMaintenanceFrequency",
"updateScopes",
"updateScopeDescriptions",
"maintenanceNotes",
@@ -209,7 +209,7 @@ public class DefaultMaintenanceInformati
* @todo needs an implementation of org.opengis.temporal modules to
anntote this parameter.
*/
@Override
- @XmlElement(name = "userDefinedMaintenanceFrequency")
+ // TODO @XmlElement(name = "userDefinedMaintenanceFrequency")
public PeriodDuration getUserDefinedMaintenanceFrequency() {
return userDefinedMaintenanceFrequency;
}
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultQuantitativeResult.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -37,7 +37,7 @@ import org.opengis.util.RecordType;
* @module
*/
@XmlType(name = "DQ_QuantitativeResult_Type", propOrder = {
- "valueType",
+// TODO "valueType",
"valueUnit",
"errorStatistic"
})
@@ -138,7 +138,7 @@ public class DefaultQuantitativeResult e
* Return the value type for reporting a data quality result, or {@code
null} if none.
*/
@Override
- @XmlElement(name = "valueType")
+ // TODO @XmlElement(name = "valueType")
public RecordType getValueType() {
return valueType;
}
Added:
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration?rev=1493029&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration
(added)
+++
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -0,0 +1 @@
+org.apache.sis.internal.metadata.MetadataTypes
Propchange:
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-metadata/src/main/resources/META-INF/services/org.apache.sis.internal.jaxb.TypeRegistration
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/TypeRegistration.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -19,6 +19,11 @@ package org.apache.sis.internal.jaxb;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ServiceLoader;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import org.apache.sis.internal.util.SystemListener;
/**
@@ -41,6 +46,18 @@ import java.util.ServiceLoader;
*/
public abstract class TypeRegistration {
/**
+ * The JAXB context, or {@code null} if not yet created.
+ */
+ private static Reference<JAXBContext> context;
+ static {
+ SystemListener.add(new SystemListener() {
+ @Override protected void classpathChanged() {
+ context = null;
+ }
+ });
+ }
+
+ /**
* For subclasses constructors.
*/
protected TypeRegistration() {
@@ -64,7 +81,7 @@ public abstract class TypeRegistration {
*
* @return The default set of classes to be bound to the {@code
JAXBContext}.
*/
- public static Class<?>[] defaultClassesToBeBound() {
+ private static Class<?>[] defaultClassesToBeBound() {
/*
* Implementation note: do not keep the ServiceLoader in static field
because:
*
@@ -77,4 +94,25 @@ public abstract class TypeRegistration {
}
return types.toArray(new Class<?>[types.size()]);
}
+
+ /**
+ * Returns the shared {@code JAXBContext} for the set of {@link
#defaultClassesToBeBound()}.
+ * Note that the {@code JAXBContext} class is thread safe, but the {@code
Marshaller},
+ * {@code Unmarshaller}, and {@code Validator} classes are not thread safe.
+ *
+ * @return The shared JAXB context.
+ * @throws JAXBException If an error occurred while creating the JAXB
context.
+ */
+ public static synchronized JAXBContext getSharedContext() throws
JAXBException {
+ final Reference<JAXBContext> ref = context; // Protect from changes by
the listener.
+ if (ref != null) {
+ final JAXBContext instance = ref.get();
+ if (instance != null) {
+ return instance;
+ }
+ }
+ final JAXBContext instance =
JAXBContext.newInstance(defaultClassesToBeBound());
+ context = new WeakReference<>(instance);
+ return instance;
+ }
}
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/MarshallerPool.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -18,7 +18,6 @@ package org.apache.sis.xml;
import java.util.Map;
import java.util.Deque;
-import java.util.Collections;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.xml.bind.JAXBContext;
@@ -30,6 +29,8 @@ import org.apache.sis.util.logging.Loggi
import org.apache.sis.internal.util.DelayedExecutor;
import org.apache.sis.internal.util.DelayedRunnable;
import org.apache.sis.internal.jaxb.AdapterReplacement;
+import org.apache.sis.internal.jaxb.TypeRegistration;
+import org.apache.sis.util.ArgumentChecks;
/**
@@ -54,6 +55,7 @@ import org.apache.sis.internal.jaxb.Adap
* @module
*
* @see XML
+ * @see <a
href="http://jaxb.java.net/guide/Performance_and_thread_safety.html">JAXB
Performance and thread-safety</a>
*/
@ThreadSafe
public class MarshallerPool {
@@ -70,12 +72,6 @@ public class MarshallerPool {
private static final byte INTERNAL = 0, ENDORSED = 1, OTHER = 2;
/**
- * The key to be used in the map given to the constructors for specifying
the default namespace.
- * An example of value for this key is {@code
"http://www.isotc211.org/2005/gmd"}.
- */
- public static final String DEFAULT_NAMESPACE_KEY =
"org.apache.sis.xml.defaultNamespace";
-
- /**
* The JAXB context to use for creating marshaller and unmarshaller.
*/
private final JAXBContext context;
@@ -127,68 +123,42 @@ public class MarshallerPool {
private final AtomicBoolean isRemovalScheduled;
/**
- * Creates a new factory for the given class to be bound, with a default
empty namespace.
- *
- * @param classesToBeBound The classes to be bound, for example {@code
DefaultMetadata.class}.
- * @throws JAXBException If the JAXB context can not be created.
- */
- public MarshallerPool(final Class<?>... classesToBeBound) throws
JAXBException {
- this(Collections.<String,String>emptyMap(), classesToBeBound);
- }
-
- /**
- * Creates a new factory for the given class to be bound. The keys in the
{@code properties} map
- * shall be one or many of the constants defined in this class like {@link
#DEFAULT_NAMESPACE_KEY}.
+ * Creates a new factory using the SIS default {@code JAXBContext}
instance.
+ * The keys in the {@code properties} map can be one or many of following
constants:
*
- * @param properties The set of properties to be given to the pool.
- * @param classesToBeBound The classes to be bound, for example {@code
DefaultMetadata.class}.
- * @throws JAXBException If the JAXB context can not be created.
- */
- public MarshallerPool(final Map<String,String> properties, final
Class<?>... classesToBeBound) throws JAXBException {
- this(properties, JAXBContext.newInstance(classesToBeBound));
- }
-
- /**
- * Creates a new factory for the given packages, with a default empty
namespace.
- * The separator character for the packages is the colon. Example:
- *
- * {@preformat text
- * "org.apache.sis.metadata.iso:org.apache.sis.metadata.iso.citation"
- * }
+ * <ul>
+ * <li>{@link XML#DEFAULT_NAMESPACE} for specifying the default
namespace of the XML document to write.</li>
+ * </ul>
*
- * @param packages The colon-separated list of packages in which
JAXB will search for annotated classes.
+ * @param properties The set of properties to be given to the pool, or
{@code null} if none.
* @throws JAXBException If the JAXB context can not be created.
*/
- public MarshallerPool(final String packages) throws JAXBException {
- this(Collections.<String,String>emptyMap(), packages);
+ public MarshallerPool(final Map<String,String> properties) throws
JAXBException {
+ this(TypeRegistration.getSharedContext(), properties);
}
/**
- * Creates a new factory for the given packages. The separator character
for the packages is the
- * colon. The keys in the {@code properties} map shall be one or many of
the constants defined
- * in this class like {@link #DEFAULT_NAMESPACE_KEY}.
+ * Creates a new factory using the given JAXB context.
+ * The keys in the {@code properties} map can be one or many of following
constants:
*
- * @param properties The set of properties to be given to the pool.
- * @param packages The colon-separated list of packages in which
JAXB will search for annotated classes.
- * @throws JAXBException If the JAXB context can not be created.
- */
- public MarshallerPool(final Map<String,String> properties, final String
packages) throws JAXBException {
- this(properties, JAXBContext.newInstance(packages));
- }
-
- /**
- * Creates a new factory for the given packages.
+ * <ul>
+ * <li>{@link XML#DEFAULT_NAMESPACE} for specifying the default
namespace of the XML document to write.</li>
+ * </ul>
*
- * @param properties The set of properties to be given to the pool.
* @param context The JAXB context.
- * @throws JAXBException If the OGC namespace prefix mapper can not be
created.
+ * @param properties The set of properties to be given to the pool, or
{@code null} if none.
+ * @throws JAXBException If the marshaller pool can not be created.
*/
@SuppressWarnings({"unchecked", "rawtypes"}) // Generic array creation
- private MarshallerPool(final Map<String,String> properties, final
JAXBContext context) throws JAXBException {
+ public MarshallerPool(final JAXBContext context, final Map<String,String>
properties) throws JAXBException {
+ ArgumentChecks.ensureNonNull("context", context);
this.context = context;
- String rootNamespace = properties.get(DEFAULT_NAMESPACE_KEY);
- if (rootNamespace == null) {
- rootNamespace = "";
+ String rootNamespace = "";
+ if (properties != null) {
+ rootNamespace = properties.get(XML.DEFAULT_NAMESPACE);
+ if (rootNamespace == null) {
+ rootNamespace = "";
+ }
}
/*
* Detects if we are using the endorsed JAXB implementation (i.e. the
one provided in
@@ -370,11 +340,21 @@ public class MarshallerPool {
/**
* Declares a marshaller as available for reuse.
- * The caller should not use anymore the given marshaller after this
method call.
+ * The caller should not use anymore the given marshaller after this
method call,
+ * since the marshaller may be re-used by another thread at any time after
recycle.
+ *
+ * {@section Cautions}
+ * <ul>
+ * <li>Do not invoke this method if the marshaller threw an exception,
since the
+ * marshaller may be in an invalid state. In particular, this method
should not
+ * be invoked in a {@code finally} block.</li>
+ * <li>Do not invoke this method twice for the same marshaller, unless
the marshaller
+ * has been obtained by a new call to {@link #acquireMarshaller()}.
+ * In case of doubt, it is better to not recycle the marshaller at
all.</li>
+ * </ul>
*
- * <p>Do not invoke this method if the marshaller threw an exception,
since the
- * marshaller may be in an invalid state. In particular, this method
should not
- * be invoked in a {@code finally} block.</p>
+ * Note that this method does not close any output stream.
+ * Closing the marshaller stream is caller's or JAXB responsibility.
*
* @param marshaller The marshaller to return to the pool.
*/
@@ -384,11 +364,21 @@ public class MarshallerPool {
/**
* Declares a unmarshaller as available for reuse.
- * The caller should not use anymore the given unmarshaller after this
method call.
+ * The caller should not use anymore the given unmarshaller after this
method call,
+ * since the unmarshaller may be re-used by another thread at any time
after recycle.
+ *
+ * {@section Cautions}
+ * <ul>
+ * <li>Do not invoke this method if the unmarshaller threw an exception,
since the
+ * unmarshaller may be in an invalid state. In particular, this
method should not
+ * be invoked in a {@code finally} block.</li>
+ * <li>Do not invoke this method twice for the same unmarshaller, unless
the unmarshaller
+ * has been obtained by a new call to {@link #acquireUnmarshaller()}.
+ * In case of doubt, it is better to not recycle the unmarshaller at
all.</li>
+ * </ul>
*
- * <p>Do not invoke this method if the marshaller threw an exception,
since the
- * marshaller may be in an invalid state. In particular, this method
should not
- * be invoked in a {@code finally} block.</p>
+ * Note that this method does not close any input stream.
+ * Closing the unmarshaller stream is caller's or JAXB responsibility.
*
* @param unmarshaller The unmarshaller to return to the pool.
*/
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/XML.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -39,6 +39,7 @@ import org.apache.sis.internal.jaxb.Type
* <li>{@link #LOCALE} for specifying the locale to use for international
strings and code lists.</li>
* <li>{@link #TIMEZONE} for specifying the timezone to use for dates and
times.</li>
* <li>{@link #SCHEMAS} for specifying the root URL of metadata schemas to
use.</li>
+ * <li>{@link #DEFAULT_NAMESPACE} for specifying the default namespace of
the XML document to write.</li>
* <li>{@link #RESOLVER} for replacing {@code xlink} or {@code uuidref}
attributes by the actual object to use.</li>
* <li>{@link #CONVERTER} for controlling the conversion of URL, UUID, Units
or similar objects.</li>
* <li>{@link #STRING_SUBSTITUTES} for specifying which code lists to
replace by simpler {@code <gco:CharacterString>} elements.</li>
@@ -52,7 +53,7 @@ import org.apache.sis.internal.jaxb.Type
*/
public final class XML extends Static {
/**
- * Allows client code to specify the locale to use for marshalling
+ * Specifies the locale to use for marshalling
* {@link org.opengis.util.InternationalString} and {@link
org.opengis.util.CodeList}
* instances. The value for this property shall be an instance of {@link
Locale}.
*
@@ -82,7 +83,7 @@ public final class XML extends Static {
public static final String LOCALE = "org.apache.sis.xml.locale";
/**
- * The timezone to use for marshalling dates and times.
+ * Specifies the timezone to use for marshalling dates and times.
*
* {@section Default behavior}
* If this property is never set, then (un)marshalling will use the
@@ -91,9 +92,9 @@ public final class XML extends Static {
public static final String TIMEZONE = "org.apache.sis.xml.timezone";
/**
- * Allows client code to specify the root URL of schemas. The value for
this property shall
- * be an instance of {@link java.util.Map Map<String,String>}. This
property controls
- * the URL to be used when marshalling the following elements:
+ * Specifies the root URL of schemas. The value for this property shall
+ * be an instance of {@link java.util.Map Map<String,String>}.
+ * This property controls the URL to be used when marshalling the
following elements:
*
* <ul>
* <li>The value of the {@code codeList} attribute when marshalling
subclasses of
@@ -120,6 +121,17 @@ public final class XML extends Static {
// If more keys are documented, update the Pooled.SCHEMAS_KEY array.
/**
+ * Specifies the default namespace of the XML document to write.
+ * An example of value for this key is {@code
"http://www.isotc211.org/2005/gmd"}.
+ *
+ * {@section Current limitation}
+ * In current SIS implementation, this property is honored only by the
{@link MarshallerPool} constructors.
+ * Specifying this property to {@link
javax.xml.bind.Marshaller#setProperty(String, Object)} is too late.
+ * This limitation may be fixed in a future SIS version.
+ */
+ public static final String DEFAULT_NAMESPACE =
"org.apache.sis.xml.defaultNamespace";
+
+ /**
* Specifies the GML version to be marshalled or unmarshalled. The GML
version may affect the
* set of XML elements to be marshalled. Newer versions typically have
more elements, but not
* always. For example in {@code gml:VerticalDatum}, the {@code
gml:verticalDatumType} property
@@ -156,9 +168,8 @@ public final class XML extends Static {
public static final String RESOLVER = "org.apache.sis.xml.resolver";
/**
- * Allows client code to control the behavior of the (un)marshalling
process when an element
- * can not be processed, or alter the element values. The value for this
property shall be an
- * instance of {@link ValueConverter}.
+ * Control the behaviors of the (un)marshalling process when an element
can not be processed,
+ * or alter the element values. The value for this property shall be an
instance of {@link ValueConverter}.
*
* <p>If an element in a XML document can not be parsed (for example if a
{@linkplain java.net.URL}
* string is not valid), the default behavior is to throw an exception
which cause the
@@ -279,7 +290,7 @@ public final class XML extends Static {
synchronized (XML.class) {
pool = POOL; // Double-check idiom: see javadoc.
if (pool == null) {
- POOL = pool = new
MarshallerPool(TypeRegistration.defaultClassesToBeBound());
+ POOL = pool = new MarshallerPool(null);
}
}
}
Modified:
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/xml/MarshallerPoolTest.java
[UTF-8] Fri Jun 14 11:29:46 2013
@@ -17,6 +17,7 @@
package org.apache.sis.xml;
import javax.xml.bind.Marshaller;
+import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
@@ -44,7 +45,7 @@ public final strictfp class MarshallerPo
*/
@Test
public void testAcquireRelease() throws JAXBException {
- final MarshallerPool pool = new MarshallerPool(new Class<?>[0]);
+ final MarshallerPool pool = new
MarshallerPool(JAXBContext.newInstance(new Class<?>[0]), null);
final Marshaller marshaller = pool.acquireMarshaller();
assertNotNull(marshaller);
/*
Modified: sis/branches/JDK7/ide-project/NetBeans/build.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/ide-project/NetBeans/build.xml?rev=1493029&r1=1493028&r2=1493029&view=diff
==============================================================================
--- sis/branches/JDK7/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK7/ide-project/NetBeans/build.xml Fri Jun 14 11:29:46 2013
@@ -23,6 +23,9 @@
<fileset dir="${project.root}/core/sis-utility/src/main/resources">
<include name="META-INF/services/*"/>
</fileset>
+ <fileset dir="${project.root}/core/sis-metadata/src/main/resources">
+ <include name="META-INF/services/*"/>
+ </fileset>
</copy>
</target>
</project>