| java.lang.Object org.geotools.image.io.metadata.MetadataAccessor
All known Subclasses: org.geotools.image.io.metadata.ImageGeometry, org.geotools.image.io.metadata.ImageReferencing, org.geotools.image.io.metadata.Band, org.geotools.image.io.metadata.Axis, org.geotools.image.io.metadata.ChildList,
MetadataAccessor | public class MetadataAccessor (Code) | | Base class for
parsers. This class
provides convenience methods for encoding and decoding metadata information. A metadata
root
is specified at construction time, together with a path to
the
of interest. Example of valid paths:
-
"CoordinateReferenceSystem/Datum"
-
"CoordinateReferenceSystem/CoordinateSystem"
-
"GridGeometry/Envelope"
In addition, some elements contains an arbitrary amount of childs. The path to child
elements can also be specified to the constructor. Examples (note that the constructor
expects paths relative to the parent; we show absolute paths below for completness):
-
"CoordinateReferenceSystem/CoordinateSystem/Axis"
-
"GridGeometry/Envelope/CoordinateValues"
-
"SampleDimensions/SampleDimension"
The
get and
set methods defined in this class will operate on the
selected
, which may be either the one
specified at construction time, or one of its childs. The element can be selected
by
MetadataAccessor.selectParent (the default) or
MetadataAccessor.selectChild .
The example below creates an accessor for a node called
"CoordinateSystem" which is expected to have childs called
"Axis" :
MetadataAccessor accessor = new MetadataAccessor(metadata,
"CoordinateReferenceSystem/CoordinateSystem", "Axis");
accessor.selectParent();
String csName = accessor.getString("name");
accessor.selectChild(0);
String firstAxisName = accessor.getString("name");
since: 2.4 version: $Id: MetadataAccessor.java 27583 2007-10-23 11:29:26Z desruisseaux $ author: Martin Desruisseaux |
Method Summary | |
protected int | appendChild() Adds a new child
at the path given at construction time.
The
will be increased by 1.
The new child is not automatically selected. | protected int | childCount() Returns the number of child
. | protected Date | getDate(String attribute) Returns an attribute as a date for the
,
or
null if none. | protected Double | getDouble(String attribute) Returns an attribute as a floating point for the
,
or
null if none. | protected double[] | getDoubles(String attribute, boolean unique) Returns an attribute as an array of floating point for the
, or
null if none. | protected Integer | getInteger(String attribute) Returns an attribute as an integer for the
,
or
null if none. | protected int[] | getIntegers(String attribute, boolean unique) Returns an attribute as an array of integers for the
, or
null if none. | protected String | getString(String attribute) Returns an attribute as a string for the
,
or
null if none. | protected Object | getUserObject() Returns the
associated with the
, or
null if none. | protected Object | getUserObject(Class type) Returns the user object associated as an instance of the specified class. | protected void | selectChild(int index) Selects the
at the given index. | protected void | selectParent() Selects the parent of child elements. | protected void | setDate(String attribute, Date value) Set the attribute to the specified value, or remove the attribute if the value is null. | protected void | setDouble(String attribute, double value) Set the attribute to the specified floating point value,
or remove the attribute if the value is NaN. | protected void | setDoubles(String attribute, double[] values) Set the attribute to the specified array of values,
or remove the attribute if the array is
null . | final void | setEnum(String attribute, String value, Collection enums) Set the attribute to the specified enumeration value,
or remove the attribute if the value is null. | protected void | setInteger(String attribute, int value) Set the attribute to the specified integer value. | protected void | setIntegers(String attribute, int[] values) Set the attribute to the specified array of values,
or remove the attribute if the array is
null . | protected void | setString(String attribute, String value) Set the attribute to the specified value,
or remove the attribute if the value is null.
Every
set methods in this class except
MetadataAccessor.setUserObject setUserObject invoke this method last. | protected void | setUserObject(Object value) Sets the
associated with the
. | protected boolean | setWarningsEnabled(boolean enabled) Enables or disables the warnings. | public String | toString() Returns a string representation of metadata, mostly for debugging purpose. | public static String | trimFractionalPart(String value) Trims the factional part of the given string, provided that it doesn't change the value.
More specifically, this method removes the trailing
".0" characters if any. | final void | warning(String method, int key, Object value) Convenience method for logging a warning. | protected void | warningOccurred(LogRecord record) Invoked when a warning occured. |
MetadataAccessor | protected MetadataAccessor(MetadataAccessor clone)(Code) | | Creates an accessor with the same parent and childs than the specified one. The two
accessors will share the same
(including the list
of childs), so change in one accessor will be immediately reflected in the other
accessor. However each accessor can
independently.
The main purpose of this constructor is to create many views over the same list
of childs, where each view
a different child.
|
MetadataAccessor | protected MetadataAccessor(GeographicMetadata metadata, String parentPath, String childPath)(Code) | | Creates an accessor for the
at the given path. Paths are
separated by the
'/' character. See
for path examples.
Parameters: metadata - The metadata node. Parameters: parentPath - The path to the of interest, or null if the metadata root node is directly the node of interest. Parameters: childPath - The path (relative to parentPath ) to the child, or null if none. |
getDate | protected Date getDate(String attribute)(Code) | | Returns an attribute as a date for the
,
or
null if none. If the attribute can't be parsed as a date, then this method
logs a warning and returns
null .
Parameters: attribute - The attribute to fetch (e.g. "origin" ). The attribute value, or null if none or unparseable. |
getDouble | protected Double getDouble(String attribute)(Code) | | Returns an attribute as a floating point for the
,
or
null if none. If the attribute can't be parsed as a floating point, then this
method logs a warning and returns
null .
Parameters: attribute - The attribute to fetch (e.g. "minimum" ). The attribute value, or null if none or unparseable. |
getDoubles | protected double[] getDoubles(String attribute, boolean unique)(Code) | | Returns an attribute as an array of floating point for the
, or
null if none. If an element can't be parsed as a floating
point, then this method logs a warning and returns
null .
Parameters: attribute - The attribute to fetch (e.g. "fillValues" ). Parameters: unique - true if duplicated values should be collapsed into unique values,or false for preserving duplicated values. The attribute values, or null if none. |
getInteger | protected Integer getInteger(String attribute)(Code) | | Returns an attribute as an integer for the
,
or
null if none. If the attribute can't be parsed as an integer, then this method
logs a warning and returns
null .
Parameters: attribute - The attribute to fetch (e.g. "minimum" ). The attribute value, or null if none or unparseable. |
getIntegers | protected int[] getIntegers(String attribute, boolean unique)(Code) | | Returns an attribute as an array of integers for the
, or
null if none. If an element can't be parsed as an integer, then this
method logs a warning and returns
null .
Parameters: attribute - The attribute to fetch (e.g. "minimum" ). Parameters: unique - true if duplicated values should be collapsed into unique values,or false for preserving duplicated values. The attribute values, or null if none. |
getString | protected String getString(String attribute)(Code) | | Returns an attribute as a string for the
,
or
null if none. This method never returns an empty string.
Every
get methods in this class except
MetadataAccessor.getUserObject getUserObject invoke this method first. Consequently, this method provides a single point for
overriding if subclasses want to process the attribute before parsing.
Parameters: attribute - The attribute to fetch (e.g. "name" ). The attribute value (never an empty string), or null if none. |
setDate | protected void setDate(String attribute, Date value)(Code) | | Set the attribute to the specified value, or remove the attribute if the value is null.
Parameters: attribute - The attribute name. Parameters: value - The attribute value. |
setDouble | protected void setDouble(String attribute, double value)(Code) | | Set the attribute to the specified floating point value,
or remove the attribute if the value is NaN.
Parameters: attribute - The attribute name. Parameters: value - The attribute value. |
setDoubles | protected void setDoubles(String attribute, double[] values)(Code) | | Set the attribute to the specified array of values,
or remove the attribute if the array is
null .
Parameters: attribute - The attribute name. Parameters: value - The attribute value. |
setEnum | final void setEnum(String attribute, String value, Collection enums)(Code) | | Set the attribute to the specified enumeration value,
or remove the attribute if the value is null.
Parameters: attribute - The attribute name. Parameters: value - The attribute value. Parameters: enums - The set of allowed values, or null if unknown. |
setInteger | protected void setInteger(String attribute, int value)(Code) | | Set the attribute to the specified integer value.
Parameters: attribute - The attribute name. Parameters: value - The attribute value. |
setIntegers | protected void setIntegers(String attribute, int[] values)(Code) | | Set the attribute to the specified array of values,
or remove the attribute if the array is
null .
Parameters: attribute - The attribute name. Parameters: value - The attribute value. |
setString | protected void setString(String attribute, String value)(Code) | | Set the attribute to the specified value,
or remove the attribute if the value is null.
Every
set methods in this class except
MetadataAccessor.setUserObject setUserObject invoke this method last. Consequently, this method provides a single point for
overriding if subclasses want to process the attribute after formatting.
Parameters: attribute - The attribute name. Parameters: value - The attribute value. |
setWarningsEnabled | protected boolean setWarningsEnabled(boolean enabled)(Code) | | Enables or disables the warnings. Warnings are enabled by default. Subclasses way want
to temporarily disable the warnings when failures are expected as the normal behavior.
For example a subclass may invokes
MetadataAccessor.getInteger and fallbacks on
MetadataAccessor.getDouble if the former failed. In such case, the warnings should be disabled for the integer parsing,
but not for the floating point parsing.
Parameters: enabled - true for enabling warnings, or false for disabling. The previous state before this method has been invoked. |
toString | public String toString()(Code) | | Returns a string representation of metadata, mostly for debugging purpose.
|
trimFractionalPart | public static String trimFractionalPart(String value)(Code) | | Trims the factional part of the given string, provided that it doesn't change the value.
More specifically, this method removes the trailing
".0" characters if any. This
method is automatically invoked before to
or to
(for simplifying fractional seconds).
Parameters: value - The value to trim. The value without the trailing ".0" part. |
warning | final void warning(String method, int key, Object value)(Code) | | Convenience method for logging a warning. Do not allow overriding, because
it would not work for warnings emitted by the
MetadataAccessor.getDate method.
|
warningOccurred | protected void warningOccurred(LogRecord record)(Code) | | Invoked when a warning occured. This method is invoked when some inconsistency has
been detected in the geographic metadata. The default implementation delegates
to
GeographicMetadata.warningOccurred .
|
|
|