Author: desruisseaux
Date: Thu Mar 20 00:11:07 2014
New Revision: 1579486
URL: http://svn.apache.org/r1579486
Log:
Added a 'crs' sub-command, bug fix in colorized formatting, and javadoc.
Added:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/IdentifiedObjectFormat.java
- copied, changed from r1579026,
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
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/SubCommand.java
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands.properties
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands_fr.properties
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/io/wkt/Colors.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
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=1579486&r1=1579485&r2=1579486&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] Thu Mar 20 00:11:07 2014
@@ -41,7 +41,7 @@ import org.apache.sis.util.logging.Monol
* Each command can accepts an arbitrary amount of the following options:
*
* <blockquote><table class="compact">
- * <tr><td>{@code --format} </td><td>The output format (XML or
text).</td></tr>
+ * <tr><td>{@code --format} </td><td>The output format: {@code xml}, {@code
wkt}, {@code wkt1} or {@code 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>
@@ -151,10 +151,11 @@ public final class Command {
} else {
commandName = commandName.toLowerCase(Locale.US);
switch (commandName) {
- case "help": command = new HelpSC (commandIndex,
args); break;
- case "about": command = new AboutSC (commandIndex,
args); break;
- case "mime-type": command = new MimeTypeSC(commandIndex,
args); break;
- case "metadata": command = new MetadataSC(commandIndex,
args); break;
+ case "help": command = new HelpSC (
commandIndex, args); break;
+ case "about": command = new AboutSC (
commandIndex, args); break;
+ case "mime-type": command = new MimeTypeSC(
commandIndex, args); break;
+ case "metadata": command = new MetadataSC(false,
commandIndex, args); break;
+ case "crs": command = new MetadataSC(true,
commandIndex, args); break;
default: throw new InvalidCommandException(Errors.format(
Errors.Keys.UnknownCommand_1, commandName),
commandName);
}
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=1579486&r1=1579485&r2=1579486&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] Thu Mar 20 00:11:07 2014
@@ -22,6 +22,11 @@ import java.io.IOException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.JAXBException;
import org.opengis.metadata.Metadata;
+import org.opengis.referencing.ReferenceSystem;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.io.wkt.WKTFormat;
+import org.apache.sis.io.wkt.Convention;
+import org.apache.sis.io.wkt.Colors;
import org.apache.sis.metadata.MetadataStandard;
import org.apache.sis.metadata.ValueExistencePolicy;
import org.apache.sis.storage.DataStore;
@@ -36,7 +41,8 @@ import org.apache.sis.xml.XML;
/**
- * The "metadata" subcommand.
+ * The "metadata" and "crs" subcommands.
+ * CRS are considered as a kind of metadata here.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
@@ -45,14 +51,25 @@ import org.apache.sis.xml.XML;
*/
final class MetadataSC extends SubCommand {
/**
- * Creates the {@code "metadata"} sub-command.
+ * {@code true} for the {@code "crs"} sub-command,
+ * or {@code false} for the {@code "metadata"} sub-command.
*/
- MetadataSC(final int commandIndex, final String... args) throws
InvalidOptionException {
- super(commandIndex, args, EnumSet.of(Option.FORMAT, Option.LOCALE,
Option.TIMEZONE, Option.ENCODING, Option.HELP));
+ private final boolean isCRS;
+
+ /**
+ * Creates the {@code "metadata"} or {@code "crs"} sub-command.
+ *
+ * @param isCRS {@code true} for the {@code "crs"} sub-command,
+ * or {@code false} for the {@code "metadata"} sub-command.
+ */
+ MetadataSC(final boolean isCRS, final int commandIndex, final String...
args) throws InvalidOptionException {
+ super(commandIndex, args, EnumSet.of(Option.FORMAT, Option.LOCALE,
Option.TIMEZONE, Option.ENCODING,
+ Option.COLORS, Option.HELP));
+ this.isCRS = isCRS;
}
/**
- * Prints metadata information.
+ * Prints metadata or CRS information.
*
* @throws DataStoreException If an error occurred while reading the file.
* @throws JAXBException If an error occurred while producing the XML
output.
@@ -62,18 +79,30 @@ final class MetadataSC extends SubComman
public int run() throws InvalidOptionException, DataStoreException,
JAXBException, IOException {
/*
* Output format can be either "text" (the default) or "xml".
+ * In the case of "crs" sub-command, we accept also WKT variants.
*/
boolean toXML = false;
+ Convention wkt = null;
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 = format.equalsIgnoreCase("xml");
+ if (!toXML) {
+ if (isCRS) {
+ if (format.equalsIgnoreCase("wkt") ||
format.equalsIgnoreCase("wkt2")) {
+ wkt = Convention.WKT2;
+ } else if (format.equalsIgnoreCase("wkt1")) {
+ wkt = Convention.WKT1;
+ }
+ }
+ if (wkt == null) {
+ throw new InvalidOptionException(Errors.format(
+ Errors.Keys.IllegalOptionValue_2, "format",
format), format);
+ }
}
- toXML = true;
}
/*
* Read metadata from the data storage.
+ * If we are executing the "crs" sub-command, extract the first CRS.
*/
if (hasUnexpectedFileCount(1, 1)) {
return Command.INVALID_ARGUMENT_EXIT_CODE;
@@ -82,31 +111,52 @@ final class MetadataSC extends SubComman
try (DataStore store = DataStores.open(files.get(0))) {
metadata = store.getMetadata();
}
+ if (metadata == null) {
+ return 0;
+ }
+ CoordinateReferenceSystem crs = null;
+ if (isCRS) {
+ for (final ReferenceSystem rs : metadata.getReferenceSystemInfo())
{
+ if (rs instanceof CoordinateReferenceSystem) {
+ crs = (CoordinateReferenceSystem) rs;
+ break;
+ }
+ }
+ if (crs == null) {
+ return 0;
+ }
+ }
/*
* Format metadata to the standard output stream.
*/
- if (metadata != null) {
- if (toXML) {
- final MarshallerPool pool = new MarshallerPool(null);
- final Marshaller marshaller = pool.acquireMarshaller();
- marshaller.setProperty(XML.LOCALE, locale);
- marshaller.setProperty(XML.TIMEZONE, timezone);
- if (isConsole()) {
- marshaller.marshal(metadata, out);
- } else {
- out.flush();
- marshaller.setProperty(Marshaller.JAXB_ENCODING,
encoding.name());
- marshaller.marshal(metadata, System.out); // Use
OutputStream instead than Writer.
- System.out.flush();
- }
+ if (toXML) {
+ final MarshallerPool pool = new MarshallerPool(null);
+ final Marshaller marshaller = pool.acquireMarshaller();
+ marshaller.setProperty(XML.LOCALE, locale);
+ marshaller.setProperty(XML.TIMEZONE, timezone);
+ if (isConsole()) {
+ marshaller.marshal(crs != null ? crs : 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();
+ marshaller.setProperty(Marshaller.JAXB_ENCODING,
encoding.name());
+ marshaller.marshal(crs != null ? crs : metadata, System.out);
// Use OutputStream instead than Writer.
+ System.out.flush();
+ }
+ } else if (wkt != null) {
+ final WKTFormat f = new WKTFormat(locale, timezone);
+ f.setConvention(wkt);
+ if (colors) {
+ f.setColors(Colors.DEFAULT);
}
- out.flush();
+ f.format(crs, out);
+ out.println();
+ } 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/SubCommand.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
[UTF-8] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -85,7 +85,7 @@ abstract class SubCommand {
* This is the value specified by the {@code --colors} arguments if
present,
* or a value inferred from the system otherwise.
*/
- protected final Boolean colors;
+ protected final boolean colors;
/**
* Output stream to the console. This output stream uses the encoding
Modified:
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands.properties?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands.properties
[ISO-8859-1] Thu Mar 20 00:11:07 2014
@@ -4,5 +4,6 @@ Usage=Usage: sis <command> [options] [fi
help=Show a help overview.
about=Show information about Apache SIS and system configuration.
+crs=Show Coordinate Reference System information for the given file.
mime-type=Show MIME type for the given file.
metadata=Show metadata information for the given file.
Modified:
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands_fr.properties
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands_fr.properties?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands_fr.properties
[ISO-8859-1] (original)
+++
sis/branches/JDK7/application/sis-console/src/main/resources/org/apache/sis/console/Commands_fr.properties
[ISO-8859-1] Thu Mar 20 00:11:07 2014
@@ -4,5 +4,6 @@ Usage=Usage: sis <commande> [options] [f
help=Affiche un écran d\u2019aide.
about=Affiche des informations à propos de Apache SIS et de la configuration
du système.
+crs=Affiche le système de référence des coordonnées du fichier spécifié.
mime-type=Affiche le type MIME du fichier spécifié.
metadata=Affiche les méta-données du fichier spécifié.
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=1579486&r1=1579485&r2=1579486&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] Thu Mar 20 00:11:07 2014
@@ -1,5 +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).
+format=The output format: xml, wkt, wkt1 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=1579486&r1=1579485&r2=1579486&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] Thu Mar 20 00:11:07 2014
@@ -1,5 +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).
+format=Le format de sortie: xml, wkt, wkt1 ou text.
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=1579486&r1=1579485&r2=1579486&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] Thu Mar 20 00:11:07 2014
@@ -45,7 +45,7 @@ public final strictfp class MetadataSCTe
public void testNetCDF() throws Exception {
final URL url = IOTestCase.class.getResource(IOTestCase.NCEP);
assertNotNull(IOTestCase.NCEP, url);
- final MetadataSC test = new MetadataSC(0, SubCommand.TEST,
url.toString());
+ final MetadataSC test = new MetadataSC(false, 0, SubCommand.TEST,
url.toString());
test.run();
verifyNetCDF("Metadata", test.outputBuffer.toString());
}
@@ -71,7 +71,7 @@ public final strictfp class MetadataSCTe
@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");
+ final MetadataSC test = new MetadataSC(false, 0, SubCommand.TEST,
url.toString(), "--format", "XML");
test.run();
verifyNetCDF("<?xml", test.outputBuffer.toString());
}
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Colors.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Colors.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Colors.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Colors.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -66,11 +66,11 @@ public class Colors implements Cloneable
map.put(ElementKind.PARAMETER, X364.FOREGROUND_GREEN);
map.put(ElementKind.METHOD, X364.FOREGROUND_GREEN);
map.put(ElementKind.DATUM, X364.FOREGROUND_GREEN);
+ map.put(ElementKind.SCOPE, X364.FOREGROUND_GRAY);
+ map.put(ElementKind.EXTENT, X364.FOREGROUND_GRAY);
+ map.put(ElementKind.CITATION, X364.FOREGROUND_GRAY);
+ map.put(ElementKind.REMARKS, X364.FOREGROUND_GRAY);
map.put(ElementKind.ERROR, X364.BACKGROUND_RED);
- map.put(ElementKind.SCOPE, X364.BACKGROUND_GRAY);
- map.put(ElementKind.EXTENT, X364.BACKGROUND_GRAY);
- map.put(ElementKind.CITATION, X364.BACKGROUND_GRAY);
- map.put(ElementKind.REMARKS, X364.BACKGROUND_GRAY);
DEFAULT.isImmutable = true;
}
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/core/LatLonPointRadius.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -34,7 +34,7 @@ import org.apache.sis.measure.Longitude;
* Represents a 2D point associated with a radius to enable great circle
* estimation on earth surface.
*
- * <div class="warning">This class may be refactored as a geometric object in
a future SIS version.
+ * <div class="warning"><b>Warning:</b> This class may be refactored as a
geometric object in a future SIS version.
* Current implementation does not verify the CRS of circle center or the
datum.</div>
*/
public class LatLonPointRadius {
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/distance/DistanceUtils.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -24,8 +24,8 @@ import org.apache.sis.geometry.DirectPos
* Class to calculate distances on earth surface. Actual calculation code very
* similar to Apache SIS but refractor to allow use of custom classes.
*
- * <div class="warning">This class may change in a future SIS version. Current
implementation performs
- * computations on a sphere of hard-coded radius. A future implementation
should perform computations
+ * <div class="warning"><b>Warning:</b> This class may change in a future SIS
version. Current implementation
+ * performs computations on a sphere of hard-coded radius. A future
implementation should perform computations
* on a given ellipsoid.</div>
*/
public class DistanceUtils {
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -282,8 +282,28 @@ public class AbstractCRS extends Abstrac
* <div class="note"><b>Implementation note:</b>
* It was easy to put JAXB annotations directly on datum fields in
subclasses because each CRS type
* can be associated to only one datum type. But we do not have this
convenience for coordinate systems,
- * where the same CRS may accept more than one kind of CS. In GML, the
different kinds of CS are marshalled
- * in different XML elements.</div>
+ * where the same CRS may accept different kinds of CS. In GML, the
different kinds of CS are marshalled
+ * as different XML elements. The usual way to handle such {@code
<xs:choice>} with JAXB is to annotate
+ * a single method like below:
+ *
+ * {@preformat java
+ * @Override
+ * @XmlElements({
+ * @XmlElement(name = "cartesianCS", type =
DefaultCartesianCS.class),
+ * @XmlElement(name = "affineCS", type =
DefaultAffineCS.class),
+ * @XmlElement(name = "cylindricalCS", type =
DefaultCylindricalCS.class),
+ * @XmlElement(name = "linearCS", type =
DefaultLinearCS.class),
+ * @XmlElement(name = "polarCS", type =
DefaultPolarCS.class),
+ * @XmlElement(name = "sphericalCS", type =
DefaultSphericalCS.class),
+ * @XmlElement(name = "userDefinedCS", type =
DefaultUserDefinedCS.class)
+ * })
+ * public CoordinateSystem getCoordinateSystem() {
+ * return super.getCoordinateSystem();
+ * }
+ * }
+ *
+ * However our attempts to apply this approach have not been conclusive.
+ * For an unknown reason, the unmarlshalled CS object was empty.</div>
*
* @param name The property name, used only in case of error message to
format.
* @throws IllegalStateException If the coordinate system has already been
set.
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -23,7 +23,7 @@ import org.apache.sis.util.Classes;
/**
- * Used by {@link CompoundFormat} for formatting the names of object of type
{@link Class}.
+ * Used by {@link CompoundFormat} for formatting the name of objects of type
{@link Class}.
*
* {@section Thread safety}
* The same {@link #INSTANCE} can be safely used by many threads without
synchronization on the part of the caller.
Modified:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/CompoundFormat.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -32,11 +32,13 @@ import java.text.SimpleDateFormat;
import javax.measure.unit.Unit;
import javax.measure.unit.UnitFormat;
+import org.opengis.referencing.IdentifiedObject;
import org.apache.sis.measure.Angle;
import org.apache.sis.measure.AngleFormat;
import org.apache.sis.measure.Range;
import org.apache.sis.measure.RangeFormat;
import org.apache.sis.util.Localized;
+import org.apache.sis.util.ArraysExt;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.collection.BackingStoreException;
import org.apache.sis.internal.util.LocalizedParseException;
@@ -445,6 +447,11 @@ public abstract class CompoundFormat<T>
return new RangeFormat(locale);
} else if (valueType == Class.class) {
return ClassFormat.INSTANCE;
+ } else {
+ final Class<?>[] interfaces = valueType.getInterfaces();
+ if (ArraysExt.contains(interfaces, IdentifiedObject.class)) {
+ return new IdentifiedObjectFormat(locale);
+ }
}
return null;
}
Copied:
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/IdentifiedObjectFormat.java
(from r1579026,
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java)
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/IdentifiedObjectFormat.java?p2=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/IdentifiedObjectFormat.java&p1=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java&r1=1579026&r2=1579486&rev=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/ClassFormat.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/IdentifiedObjectFormat.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -16,62 +16,73 @@
*/
package org.apache.sis.io;
+import java.util.Locale;
import java.text.Format;
import java.text.FieldPosition;
import java.text.ParsePosition;
-import org.apache.sis.util.Classes;
+import org.opengis.util.GenericName;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.ReferenceIdentifier;
+import org.apache.sis.internal.util.Citations;
+import org.apache.sis.util.iso.DefaultNameSpace;
+import org.apache.sis.util.resources.Vocabulary;
/**
- * Used by {@link CompoundFormat} for formatting the names of object of type
{@link Class}.
- *
- * {@section Thread safety}
- * The same {@link #INSTANCE} can be safely used by many threads without
synchronization on the part of the caller.
- * Note that this is specific to {@code ClassFormat} and generally not true
for arbitrary {@code Format} classes.
+ * Used by {@link CompoundFormat} for formatting the name of objects of type
{@link IdentifiedObject}.
*
* @author Martin Desruisseaux (Geomatys)
- * @since 0.3
- * @version 0.3
+ * @since 0.4
+ * @version 0.4
* @module
*/
-final class ClassFormat extends Format {
+final class IdentifiedObjectFormat extends Format {
/**
* For cross-version compatibility.
*/
- private static final long serialVersionUID = 2321788892790539107L;
+ private static final long serialVersionUID = -832517434580782189L;
/**
- * The unique instance.
+ * The locale to use.
*/
- static final ClassFormat INSTANCE = new ClassFormat();
+ private final Locale locale;
/**
- * For the unique {@link #INSTANCE} only.
+ * Creates an instance for the given locale.
*/
- private ClassFormat() {
+ IdentifiedObjectFormat(final Locale locale) {
+ this.locale = locale;
}
/**
- * Formats the given class. The given {@code obj} must be an instance of
{@link Class},
- * otherwise a {@link ClassCastException} will be thrown.
+ * Formats the given object.
*/
@Override
public StringBuffer format(final Object obj, final StringBuffer
toAppendTo, final FieldPosition pos) {
- return toAppendTo.append(Classes.getShortName((Class<?>) obj));
+ final ReferenceIdentifier identifier = ((IdentifiedObject)
obj).getName();
+ if (identifier == null) {
+ return
toAppendTo.append(Vocabulary.getResources(locale).getString(Vocabulary.Keys.Unnamed));
+ }
+ if (identifier instanceof GenericName) {
+ // The toString() behavior is specified by the GenericName javadoc.
+ return toAppendTo.append(((GenericName)
identifier).toInternationalString().toString(locale));
+ }
+ final String code = identifier.getCode();
+ String cs = identifier.getCodeSpace();
+ if (cs == null || cs.isEmpty()) {
+ cs = Citations.getIdentifier(identifier.getAuthority());
+ }
+ if (cs != null) {
+ toAppendTo.append(cs).append(DefaultNameSpace.DEFAULT_SEPARATOR);
+ }
+ return toAppendTo.append(code);
}
/**
- * Can not parse unqualified class name.
+ * Can not parse object only from their name.
*/
@Override
public Object parseObject(final String source, final ParsePosition pos) {
throw new UnsupportedOperationException();
}
-
- /**
- * Resolves to the singleton instance on deserialization.
- */
- private Object readResolve() {
- return INSTANCE;
- }
}
Modified:
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java?rev=1579486&r1=1579485&r2=1579486&view=diff
==============================================================================
---
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
[UTF-8] (original)
+++
sis/branches/JDK7/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/xml/XMLStore.java
[UTF-8] Thu Mar 20 00:11:07 2014
@@ -26,10 +26,12 @@ import java.io.IOException;
import javax.xml.bind.JAXBException;
import javax.xml.transform.stream.StreamSource;
import org.opengis.metadata.Metadata;
+import org.opengis.referencing.ReferenceSystem;
import org.apache.sis.xml.XML;
import org.apache.sis.storage.DataStore;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.metadata.iso.DefaultMetadata;
import org.apache.sis.util.logging.WarningListener;
import org.apache.sis.util.resources.Errors;
@@ -41,6 +43,7 @@ import org.apache.sis.util.resources.Err
*
* <ul>
* <li>{@link Metadata}, typically built from the {@code <gmd:MD_Metadata>}
XML element.</li>
+ * <li>{@link ReferenceSystem}, accessible by {@link
Metadata#getReferenceSystemInfo()}.</li>
* </ul>
*
* The above list may be extended in any future SIS version.
@@ -68,6 +71,11 @@ public class XMLStore extends DataStore
private Object object;
/**
+ * The metadata object, determined when first needed.
+ */
+ private Metadata metadata;
+
+ /**
* Creates a new XML store from the given file, URL or stream.
*
* @param connector Information about the storage (URL, stream,
<i>etc</i>).
@@ -162,11 +170,22 @@ public class XMLStore extends DataStore
@Override
public Metadata getMetadata() throws DataStoreException {
unmarshal();
- return (object instanceof Metadata) ? (Metadata) object : null;
+ if (metadata == null) {
+ if (object instanceof Metadata) {
+ metadata = (Metadata) object;
+ } else if (object instanceof ReferenceSystem) {
+ final DefaultMetadata d = new DefaultMetadata();
+ d.getReferenceSystemInfo().add((ReferenceSystem) object);
+ metadata = d;
+ }
+ }
+ return metadata;
}
/**
* Closes this data store and releases any underlying resources.
+ *
+ * @throws DataStoreException If an error occurred while closing this data
store.
*/
@Override
public void close() throws DataStoreException {