Package org.esa.snap.core.metadata
Class GenericXmlMetadata
- java.lang.Object
-
- org.esa.snap.core.metadata.GenericXmlMetadata
-
- Direct Known Subclasses:
XmlMetadata
public abstract class GenericXmlMetadata extends Object
Base class that encapsulates metadata read from XML file.
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,List<MetadataAttribute>>attributeMapprotected intheightprotected Loggerloggerprotected static StringMISSING_ELEMENT_WARNINGprotected Stringnameprotected static StringNO_SUCH_PATH_WARNINGprotected intnumBandsprotected Pathpathprotected MetadataElementrootElementprotected intwidth
-
Constructor Summary
Constructors Constructor Description GenericXmlMetadata(String name)Constructs an instance of metadata class and assigns a name to the rootMetadataElement.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static voidCopyChildElements(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>
Tcreate(Class<T> clazz, File inputFile)static <T extends GenericXmlMetadata>
Tcreate(Class<T> clazz, String input)static <T extends GenericXmlMetadata>
Tcreate(Class<T> clazz, Path inputFile)Factory method for creating instances of classes that (at least) extendXmlMetadataclass.protected StringensureAttributeTagPresent(String path)StringgetAttributeSiblingValue(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.StringgetAttributeValue(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.StringgetAttributeValue(String attributePath, String defaultValue)Returns the value of the attribute (or the default value) specified by its XPath expression.String[]getAttributeValues(String attributePath)abstract StringgetFileName()Gets the name of the metadata file used to obtain this instance.abstract StringgetMetadataProfile()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.PathgetPath()Returns the path of the metadata file.MetadataElementgetRootElement()Returns the root node of this metadata file.voidindexAttribute(String parentElementPath, MetadataAttribute attribute)static <T extends GenericXmlMetadata>
TloadMetadata(Class<T> clazz, Path inputFile)voidsetFileName(String actualName)Sets the name of the file used to obtain this instance.voidsetName(String value)Sets the name of this metadata (and also the name of the root element).voidsetPath(Path value)Sets the path of the metadata file.protected voidwarn(String message, String argument)
-
-
-
Field Detail
-
MISSING_ELEMENT_WARNING
protected static final String MISSING_ELEMENT_WARNING
- See Also:
- Constant Field Values
-
NO_SUCH_PATH_WARNING
protected static final String NO_SUCH_PATH_WARNING
- See Also:
- Constant Field Values
-
rootElement
protected final MetadataElement rootElement
-
name
protected String name
-
width
protected int width
-
height
protected int height
-
numBands
protected int numBands
-
path
protected Path path
-
logger
protected Logger logger
-
attributeMap
protected Map<String,List<MetadataAttribute>> attributeMap
-
-
Constructor Detail
-
GenericXmlMetadata
public GenericXmlMetadata(String name)
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 Detail
-
CopyChildElements
public static void CopyChildElements(MetadataElement source, MetadataElement target)
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
public MetadataElement getRootElement()
Returns the root node of this metadata file.- Returns:
- The root metadata element
-
getFileName
public abstract String 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
public void setFileName(String actualName)
Sets the name of the file used to obtain this instance.- Parameters:
actualName- The name of the file
-
getMetadataProfile
public abstract String 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
public Path getPath()
Returns the path of the metadata file.- Returns:
- The path of the metadata file.
-
setPath
public void setPath(Path value)
Sets the path of the metadata file.- Parameters:
value- The path of the file.
-
setName
public void setName(String value)
Sets the name of this metadata (and also the name of the root element).- Parameters:
value- The name of the metadata file.
-
getAttributeValue
public String getAttributeValue(String attributePath, String defaultValue)
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 anullvalue- Returns:
- The attribute (or default) value
-
getAttributeValue
public String 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.- 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 anullvalue- Returns:
- The attribute (or default) value
-
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.
-
indexAttribute
public void indexAttribute(String parentElementPath, MetadataAttribute attribute)
-
create
public static <T extends GenericXmlMetadata> T create(Class<T> clazz, String input)
-
create
public static <T extends GenericXmlMetadata> T create(Class<T> clazz, File inputFile)
-
create
public static <T extends GenericXmlMetadata> T create(Class<T> clazz, Path inputFile)
Factory method for creating instances of classes that (at least) extendXmlMetadataclass.- Type Parameters:
T- Generic type of the metadata class.- Parameters:
clazz- The actual class of the metadata. It should extendXmlMetadata.inputFile- TheFileobject that points to the file to be parsed.- Returns:
- An instance of
Ttype.
-
loadMetadata
public static <T extends GenericXmlMetadata> T loadMetadata(Class<T> clazz, Path inputFile) throws IOException, InstantiationException, ParserConfigurationException, SAXException
-
-