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 Details

  • Constructor Details

    • GenericXmlMetadata

      public GenericXmlMetadata(String name)
      Constructs an instance of metadata class and assigns a name to the root MetadataElement.
      Parameters:
      name - The name of this instance, and also the initial name of the root element.
  • Method Details

    • 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 copied
      target - 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 attribute
      defaultValue - the default value if the attribute is not found or has a null 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 attribute
      attributeIndex - the index of the attribute in the attribute array
      defaultValue - the default value if the attribute is not found or has a null value
      Returns:
      The attribute (or default) value
    • getAttributeValues

      public String[] getAttributeValues(String attributePath)
    • 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 tested
      attributeValue - The test value
      siblingPath - The path of the attribute whose value we want to retrieve
      defaultSiblingValue - 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

      protected void warn(String message, String argument)
    • indexAttribute

      public void indexAttribute(String parentElementPath, MetadataAttribute attribute)
    • ensureAttributeTagPresent

      protected String ensureAttributeTagPresent(String path)
    • 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) extend XmlMetadata class.
      Type Parameters:
      T - Generic type of the metadata class.
      Parameters:
      clazz - The actual class of the metadata. It should extend XmlMetadata.
      inputFile - The File 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
      Throws:
      IOException
      InstantiationException
      ParserConfigurationException
      SAXException