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>>
attributeMap
protected int
height
protected Logger
logger
protected static String
MISSING_ELEMENT_WARNING
protected String
name
protected static String
NO_SUCH_PATH_WARNING
protected int
numBands
protected Path
path
protected MetadataElement
rootElement
protected int
width
-
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 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>
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) extendXmlMetadata
class.protected String
ensureAttributeTagPresent(String path)
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.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.String
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
getFileName()
Gets the name of the metadata file used to obtain this instance.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.Path
getPath()
Returns the path of the metadata file.MetadataElement
getRootElement()
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
setName(String value)
Sets the name of this metadata (and also the name of the root element).void
setPath(Path value)
Sets the path of the metadata file.protected void
warn(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 anull
value- 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 anull
value- 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) 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
-
-