You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2014/12/28 06:24:07 UTC
svn commit: r1648150 - in /sis/branches/JDK8:
core/sis-utility/src/main/java/org/apache/sis/util/resources/
storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/
storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/
storage/s...
Author: desruisseaux
Date: Sun Dec 28 05:24:06 2014
New Revision: 1648150
URL: http://svn.apache.org/r1648150
Log:
Add parsing of unit symbols from NetCDF files.
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Attribute.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -81,6 +81,11 @@ public final class Errors extends Indexe
public static final short CanNotAddToExclusiveSet_2 = 0;
/**
+ * Can not assign units “{1}” to dimension “{0}”.
+ */
+ public static final short CanNotAssignUnitToDimension_2 = 168;
+
+ /**
* Can not assign “{1}” to “{0}”.
*/
public static final short CanNotAssign_2 = 167;
Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Sun Dec 28 05:24:06 2014
@@ -28,6 +28,7 @@ AbstractType_1 = Type
AmbiguousName_3 = Name \u201c{2}\u201d is ambiguous because it can be understood as either \u201c{0}\u201d or \u201c{1}\u201d.
CanNotAddToExclusiveSet_2 = No element can be added to this set because properties \u2018{0}\u2019 and \u2018{1}\u2019 are mutually exclusive.
CanNotAssign_2 = Can not assign \u201c{1}\u201d to \u201c{0}\u201d.
+CanNotAssignUnitToDimension_2 = Can not assign units \u201c{1}\u201d to dimension \u201c{0}\u201d.
CanNotConcatenateTransforms_2 = Can not concatenate transforms \u201c{0}\u201d and \u201c{1}\u201d.
CanNotConnectTo_1 = Can not connect to \u201c{0}\u201d.
CanNotConvertFromType_2 = Can not convert from type \u2018{0}\u2019 to type \u2018{1}\u2019.
Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Sun Dec 28 05:24:06 2014
@@ -18,6 +18,7 @@ AbstractType_1 = Le t
AmbiguousName_3 = Le nom \u00ab\u202f{2}\u202f\u00bb est ambigu\u00eb car il peut \u00eatre interpr\u00e9t\u00e9 comme \u00ab\u202f{0}\u202f\u00bb ou \u00ab\u202f{1}\u202f\u00bb.
CanNotAddToExclusiveSet_2 = Aucun \u00e9l\u00e9ment ne peut \u00eatre ajout\u00e9 \u00e0 cet ensemble car les propri\u00e9t\u00e9s \u2018{0}\u2019 et \u2018{1}\u2019 sont mutuellement exclusives.
CanNotAssign_2 = Ne peut pas assigner \u00ab\u202f{1}\u202f\u00bb \u00e0 \u00ab\u202f{0}\u202f\u00bb.
+CanNotAssignUnitToDimension_2 = Ne peut pas assigner les unit\u00e9s \u00ab\u202f{1}\u202f\u00bb \u00e0 la dimension \u00ab\u202f{0}\u202f\u00bb.
CanNotConcatenateTransforms_2 = Les transformations \u00ab\u202f{0}\u202f\u00bb et \u00ab\u202f{1}\u202f\u00bb ne peuvent pas \u00eatre combin\u00e9es.
CanNotConnectTo_1 = Ne peut pas se connecter \u00e0 \u00ab\u202f{0}\u202f\u00bb.
CanNotConvertFromType_2 = Ne peut pas convertir du type \u2018{0}\u2019 vers le type \u2018{1}\u2019.
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -28,7 +28,7 @@ import org.apache.sis.util.Debug;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.5
* @module
*/
public abstract class Variable {
@@ -68,6 +68,13 @@ public abstract class Variable {
public abstract String getDescription();
/**
+ * Returns the unit of measurement as a string, or {@code null} if none.
+ *
+ * @return The unit of measurement, or {@code null}.
+ */
+ public abstract String getUnitsString();
+
+ /**
* Returns the variable data type, as a primitive type if possible.
*
* @return The variable data type, or {@code null} if unknown.
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Attribute.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Attribute.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Attribute.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/Attribute.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -48,11 +48,17 @@ final class Attribute {
/**
* The value, either as a {@link String} or as an array of primitive type.
* Never {@code null} and never an empty string or empty array.
+ *
+ * <p>If the value is a {@code String}, then leading and trailing spaces and control characters
+ * have been trimmed by {@link String#trim()}.</p>
*/
final Object value;
/**
* Creates a new attribute of the given name and value.
+ *
+ * @param name The attribute name (can not be null).
+ * @param value The value (trimmed if a {@code String}).
*/
Attribute(final String name, final Object value) {
this.name = name;
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -329,10 +329,9 @@ public final class ChannelDecoder extend
if (length < 0) {
throw malformedHeader();
}
- final ByteBuffer buffer = input.buffer;
final int size = ensureBufferContains(length, 1, "<name>");
final String text = input.readString(length, NAME_ENCODING);
- buffer.position(buffer.position() + (size - length));
+ input.buffer.position(input.buffer.position() + (size - length));
return text;
}
@@ -341,6 +340,9 @@ public final class ChannelDecoder extend
* as a {@link String}. Otherwise this method returns the value as an array of the corresponding primitive type
* and the given length.
*
+ * <p>If the value is a {@code String}, then leading and trailing spaces and control characters have been trimmed
+ * by {@link String#trim()}.</p>
+ *
* @return The value, or {@code null} if it was an empty string or an empty array.
*/
private Object readValues(final String name, final int type, final int length) throws IOException, DataStoreException {
@@ -433,6 +435,9 @@ public final class ChannelDecoder extend
* <li>The actual values as a variable length list (use {@link #readValues(String,int,int)})</li>
* </ul>
*
+ * If the value is a {@code String}, then leading and trailing spaces and control characters
+ * have been trimmed by {@link String#trim()}.
+ *
* @param nelems The number of attributes to read.
*/
private Attribute[] readAttributes(final int nelems) throws IOException, DataStoreException {
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -33,7 +33,7 @@ import org.apache.sis.util.resources.Err
* @author Johann Sorel (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.5
* @module
*/
final class VariableInfo extends Variable {
@@ -162,13 +162,25 @@ final class VariableInfo extends Variabl
@Override
public String getDescription() {
for (final String attributeName : DESCRIPTION_ATTRIBUTES) {
- Attribute attribute = attributes.get(attributeName);
+ final Attribute attribute = attributes.get(attributeName);
if (attribute != null && attribute.value instanceof String) {
return (String) attribute.value;
}
}
return null;
}
+
+ /**
+ * Returns the unit of measurement as a string, or {@code null} if none.
+ */
+ @Override
+ public String getUnitsString() {
+ final Attribute attribute = attributes.get(CDM.UNITS);
+ if (attribute != null && attribute.value instanceof String) {
+ return (String) attribute.value;
+ }
+ return null;
+ }
/**
* Returns the type of data as a Java primitive type if possible,
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -30,7 +30,7 @@ import org.apache.sis.internal.netcdf.Va
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
- * @version 0.3
+ * @version 0.5
* @module
*/
final class VariableWrapper extends Variable {
@@ -69,6 +69,14 @@ final class VariableWrapper extends Vari
}
/**
+ * Returns the unit of measurement as a string, or {@code null} if none.
+ */
+ @Override
+ public String getUnitsString() {
+ return variable.getUnitsString();
+ }
+
+ /**
* Returns the variable data type, as a primitive type if possible.
* This method may return {@code null} (UCAR code seems to allow that).
*/
Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -69,6 +69,7 @@ import org.apache.sis.internal.netcdf.Gr
import org.apache.sis.internal.system.DefaultFactories;
import org.apache.sis.internal.metadata.Standards;
import org.apache.sis.util.resources.Errors;
+import org.apache.sis.measure.Units;
// The following dependency is used only for static final String constants.
// Consequently the compiled class files should not have this dependency.
@@ -196,6 +197,15 @@ final class MetadataReader {
}
/**
+ * Returns the localized error resource bundle for the locale given by {@link #getLocale()}.
+ *
+ * @return The localized error resource bundle.
+ */
+ private Errors errors() {
+ return Errors.getResources(decoder.listeners.getLocale());
+ }
+
+ /**
* Reads the attribute value for the given name, then trims the leading and trailing spaces.
* If the value is null, empty or contains only spaces, then this method returns {@code null}.
*/
@@ -225,7 +235,7 @@ final class MetadataReader {
private <T extends Enum<T>> T forEnumName(final Class<T> enumType, final String name) {
final T code = Types.forEnumName(enumType, name);
if (code == null && name != null) {
- decoder.listeners.warning(Errors.format(Errors.Keys.UnknownEnumValue_2, enumType, name), null);
+ decoder.listeners.warning(errors().getString(Errors.Keys.UnknownEnumValue_2, enumType, name), null);
}
return code;
}
@@ -241,7 +251,7 @@ final class MetadataReader {
* CodeLists are not enums, but using the error message for enums is not completly wrong since
* if we did not allowed CodeList to create new elements, then we are using it like an enum.
*/
- decoder.listeners.warning(Errors.format(Errors.Keys.UnknownEnumValue_2, codeType, name), null);
+ decoder.listeners.warning(errors().getString(Errors.Keys.UnknownEnumValue_2, codeType, name), null);
}
return code;
}
@@ -862,9 +872,12 @@ final class MetadataReader {
if (description != null && !(description = description.trim()).isEmpty() && !description.equals(name)) {
band.setDescription(new SimpleInternationalString(description));
}
-//TODO: Can't store the units, because the Band interface restricts it to length.
-// We need the SampleDimension interface proposed in ISO 19115 revision draft.
-// band.setUnits(Units.valueOf(variable.getUnitsString()));
+ final String units = variable.getUnitsString();
+ if (units != null) try {
+ band.setUnits(Units.valueOf(units));
+ } catch (IllegalArgumentException e) {
+ decoder.listeners.warning(errors().getString(Errors.Keys.CanNotAssignUnitToDimension_2, name, units), e);
+ }
return band;
}
Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1648150&r1=1648149&r2=1648150&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] Sun Dec 28 05:24:06 2014
@@ -142,6 +142,7 @@ public final strictfp class MetadataRead
" │ └─Attribute group\n" +
" │ └─Attribute\n" +
" │ ├─Sequence identifier……………………………… SST\n" +
+ " │ ├─Units…………………………………………………………………… K\n" +
" │ └─Description…………………………………………………… Sea temperature\n" +
" ├─Data quality info\n" +
" │ └─Lineage\n" +