Package org.esa.snap.core.metadata
Class GenericXmlMetadata
java.lang.Object
org.esa.snap.core.metadata.GenericXmlMetadata
- Direct Known Subclasses:
XmlMetadata
Base class that encapsulates metadata read from XML file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Map
<String, List<MetadataAttribute>> protected int
protected Logger
protected static final String
protected String
protected static final String
protected int
protected Path
protected final MetadataElement
protected int
-
Constructor Summary
ConstructorsConstructorDescriptionGenericXmlMetadata
(String name) Constructs an instance of metadata class and assigns a name to the rootMetadataElement
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
CopyChildElements
(MetadataElement source, MetadataElement target) Helper method that copies the child nodes of a metadata element as child nodes of another metadata element.static <T extends GenericXmlMetadata>
Tstatic <T extends GenericXmlMetadata>
Tstatic <T extends GenericXmlMetadata>
TFactory method for creating instances of classes that (at least) extendXmlMetadata
class.protected String
getAttributeSiblingValue
(String attributePath, String attributeValue, String siblingPath, String defaultSiblingValue) Returns the value of the attribute (or the default value) specified by its XPath expression, and whose sibling value is equal to a certain value.getAttributeValue
(String attributePath, int attributeIndex, String defaultValue) Returns the value of the attribute (or the default value) specified by its XPath expression and the given index, when multiple such attributes are present at the same XPath location.getAttributeValue
(String attributePath, String defaultValue) Returns the value of the attribute (or the default value) specified by its XPath expression.String[]
getAttributeValues
(String attributePath) abstract String
Gets the name of the metadata file used to obtain this instance.abstract String
Returns the metadata profile (for example: L1A, etc.) This getter should be overridden in all derived classes because each metadata type may have a different hierarchy of nodes for getting this value.getPath()
Returns the path of the metadata file.Returns the root node of this metadata file.void
indexAttribute
(String parentElementPath, MetadataAttribute attribute) static <T extends GenericXmlMetadata>
TloadMetadata
(Class<T> clazz, Path inputFile) void
setFileName
(String actualName) Sets the name of the file used to obtain this instance.void
Sets the name of this metadata (and also the name of the root element).void
Sets the path of the metadata file.protected void
-
Field Details
-
MISSING_ELEMENT_WARNING
- See Also:
-
NO_SUCH_PATH_WARNING
- See Also:
-
rootElement
-
name
-
width
protected int width -
height
protected int height -
numBands
protected int numBands -
path
-
logger
-
attributeMap
-
-
Constructor Details
-
GenericXmlMetadata
Constructs an instance of metadata class and assigns a name to the rootMetadataElement
.- Parameters:
name
- The name of this instance, and also the initial name of the root element.
-
-
Method Details
-
CopyChildElements
Helper method that copies the child nodes of a metadata element as child nodes of another metadata element.- Parameters:
source
- The metadata element holding the nodes to be copiedtarget
- The destination metadata element
-
getRootElement
Returns the root node of this metadata file.- Returns:
- The root metadata element
-
getFileName
Gets the name of the metadata file used to obtain this instance.- Returns:
- A string representing the name of the file used to obtain the instance.
-
setFileName
Sets the name of the file used to obtain this instance.- Parameters:
actualName
- The name of the file
-
getMetadataProfile
Returns the metadata profile (for example: L1A, etc.) This getter should be overridden in all derived classes because each metadata type may have a different hierarchy of nodes for getting this value.- Returns:
- The metadata profile
-
getPath
Returns the path of the metadata file.- Returns:
- The path of the metadata file.
-
setPath
Sets the path of the metadata file.- Parameters:
value
- The path of the file.
-
setName
Sets the name of this metadata (and also the name of the root element).- Parameters:
value
- The name of the metadata file.
-
getAttributeValue
Returns the value of the attribute (or the default value) specified by its XPath expression.- Parameters:
attributePath
- the XPath location of the attributedefaultValue
- the default value if the attribute is not found or has anull
value- Returns:
- The attribute (or default) value
-
getAttributeValue
Returns the value of the attribute (or the default value) specified by its XPath expression and the given index, when multiple such attributes are present at the same XPath location.- Parameters:
attributePath
- the XPath location of the attributeattributeIndex
- the index of the attribute in the attribute arraydefaultValue
- the default value if the attribute is not found or has anull
value- Returns:
- The attribute (or default) value
-
getAttributeValues
-
getAttributeSiblingValue
public String getAttributeSiblingValue(String attributePath, String attributeValue, String siblingPath, String defaultSiblingValue) Returns the value of the attribute (or the default value) specified by its XPath expression, and whose sibling value is equal to a certain value.- Parameters:
attributePath
- The path of the attribute to be testedattributeValue
- The test valuesiblingPath
- The path of the attribute whose value we want to retrievedefaultSiblingValue
- The default value if the attribute does not exist or the condition of the sibling value is not met.- Returns:
- The attribute (or default) value.
-
warn
-
indexAttribute
-
ensureAttributeTagPresent
-
create
-
create
-
create
Factory method for creating instances of classes that (at least) extendXmlMetadata
class.- Type Parameters:
T
- Generic type of the metadata class.- Parameters:
clazz
- The actual class of the metadata. It should extendXmlMetadata
.inputFile
- TheFile
object that points to the file to be parsed.- Returns:
- An instance of
T
type.
-
loadMetadata
public static <T extends GenericXmlMetadata> T loadMetadata(Class<T> clazz, Path inputFile) throws IOException, InstantiationException, ParserConfigurationException, SAXException
-