public class MetadataElement extends ProductNode
MetadataElement
is a data node used to store metadata. Metadata elements can have any number of
metadata attributes of the type MetadataAttribute
and any number of inner MetadataElement
s.PROPERTY_NAME_DESCRIPTION, PROPERTY_NAME_NAME
Constructor and Description |
---|
MetadataElement(String name)
Constructs a new metadata element.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptVisitor(ProductVisitor visitor)
Accepts the given visitor.
|
void |
addAttribute(MetadataAttribute attribute)
Adds an attribute to this node.
|
void |
addElement(MetadataElement element)
Adds the given element to this element.
|
void |
addElementAt(MetadataElement element,
int index)
Adds the given element to this element at index.
|
boolean |
containsAttribute(String name)
Checks whether this node has an element with the given name.
|
boolean |
containsElement(String name)
Tests if a element with the given name is contained in this element.
|
MetadataElement |
createDeepClone() |
void |
dispose()
Releases all of the resources used by this object instance and all of its owned children.
|
MetadataAttribute |
getAttribute(String name)
Returns the attribute with the given name.
|
MetadataAttribute |
getAttributeAt(int index)
Returns the attribute at the given index.
|
double |
getAttributeDouble(String name)
Returns the double value of the attribute with the given name.
|
double |
getAttributeDouble(String name,
double defaultValue)
Returns the double value of the attribute with the given name.
|
int |
getAttributeIndex(MetadataAttribute attribute)
Gets the index of the given attribute.
|
int |
getAttributeInt(String name)
Returns the integer value of the attribute with the given name.
|
int |
getAttributeInt(String name,
int defaultValue)
Returns the integer value of the attribute with the given name.
|
String[] |
getAttributeNames()
Returns the names of all attributes of this node.
|
MetadataAttribute[] |
getAttributes()
Returns an array of attributes contained in this element.
|
String |
getAttributeString(String name)
Returns the string value of the attribute with the given name.
|
String |
getAttributeString(String name,
String defaultValue)
Returns the string value of the attribute with the given name.
|
ProductData.UTC |
getAttributeUTC(String name)
Returns the UTC value of the attribute with the given name.
|
ProductData.UTC |
getAttributeUTC(String name,
ProductData.UTC defaultValue)
Returns the UTC value of the attribute with the given name.
|
MetadataElement |
getElement(String name)
Returns the element with the given name.
|
MetadataElement |
getElementAt(int index)
Returns the element at the given index.
|
ProductNodeGroup<MetadataElement> |
getElementGroup()
Gets the group of child elements.
|
int |
getElementIndex(MetadataElement element)
Gets the index of the given element.
|
String[] |
getElementNames()
Returns a string array containing the names of the groups contained in this element
|
MetadataElement[] |
getElements()
Returns an array of elements contained in this element.
|
int |
getNumAttributes()
Returns the number of attributes attached to this node.
|
int |
getNumElements() |
MetadataElement |
getParentElement() |
long |
getRawStorageSize(ProductSubsetDef subsetDef)
Gets an estimated, raw storage size in bytes of this product node.
|
boolean |
removeAttribute(MetadataAttribute attribute)
Removes the given attribute from this annotation.
|
boolean |
removeElement(MetadataElement element)
Removes the given element from this element.
|
void |
setAttributeDouble(String name,
double value)
Sets the attribute with the given name to the given double value.
|
void |
setAttributeInt(String name,
int value)
Sets the attribute with the given name to the given integer value.
|
void |
setAttributeString(String name,
String value)
Sets the attribute with the given name to the given string value.
|
void |
setAttributeUTC(String name,
ProductData.UTC value)
Sets the attribute with the given name to the given utc value.
|
void |
setModified(boolean modified)
Sets this node's modified flag.
|
fireProductNodeChanged, fireProductNodeChanged, getDescription, getDisplayName, getName, getOwner, getProduct, getProductReader, getProductReaderSafe, getProductRefString, getProductSafe, getProductWriter, getProductWriterSafe, getRawStorageSize, isModified, isPartOfSubset, isValidNodeName, removeFromFile, setDescription, setName, setOwner, toString, updateExpression
getExtension
public MetadataElement(String name)
name
- the element namepublic ProductNodeGroup<MetadataElement> getElementGroup()
public MetadataElement getParentElement()
public void addElement(MetadataElement element)
element
- the element to added, ignored if null
public void addElementAt(MetadataElement element, int index)
element
- the element to added, ignored if null
index
- where to put itpublic boolean removeElement(MetadataElement element)
element
- the element to be removed, ignored if null
public int getNumElements()
public MetadataElement getElementAt(int index)
index
- the element indexIndexOutOfBoundsException
- if the index is out of boundspublic String[] getElementNames()
public MetadataElement[] getElements()
public MetadataElement getElement(String name)
name
- the element namenull
if a element with the given name is not contained in
this element.public boolean containsElement(String name)
name
- the name, must not be null
true
if a element with the given name is contained in this element, false
otherwisepublic int getElementIndex(MetadataElement element)
element
- The element .public void addAttribute(MetadataAttribute attribute)
attribute
- the attribute to be added, null
is ignoredpublic boolean removeAttribute(MetadataAttribute attribute)
attribute
- the attribute to be removed, null
is ignoredtrue
if it was removedpublic int getNumAttributes()
public MetadataAttribute getAttributeAt(int index)
index
- the attribute indexnull
if this node does not contain attributesIndexOutOfBoundsException
public String[] getAttributeNames()
null
public MetadataAttribute[] getAttributes()
public MetadataAttribute getAttribute(String name)
name
- the attribute namenull
if it could not be foundpublic boolean containsAttribute(String name)
name
- the attribute nametrue
if sopublic int getAttributeIndex(MetadataAttribute attribute)
attribute
- The attribute.public double getAttributeDouble(String name, double defaultValue)
The given default value is returned if an attribute with the given name could not be found in this node.
name
- the attribute namedefaultValue
- the default valueNumberFormatException
- if the attribute type is ASCII but cannot be converted to a numberpublic double getAttributeDouble(String name)
An Exception is thrown if an attribute with the given name could not be found in this node.
name
- the attribute nameNumberFormatException
- if the attribute type is ASCII but cannot be converted to a numberIllegalArgumentException
- if an attribute with the given name could not be foundpublic ProductData.UTC getAttributeUTC(String name, ProductData.UTC defaultValue)
The given default value is returned if an attribute with the given name could not be found in this node.
name
- the attribute namedefaultValue
- the default valuepublic ProductData.UTC getAttributeUTC(String name)
name
- the attribute nameIllegalArgumentException
- if an attribute with the given name could not be foundpublic int getAttributeInt(String name, int defaultValue)
The given default value is returned if an attribute with the given name could not be found in this node.
name
- the attribute namedefaultValue
- the default valueNumberFormatException
- if the attribute type is ASCII but cannot be converted to a numberpublic int getAttributeInt(String name)
An Exception is thrown if an attribute with the given name could not be found in this node.
name
- the attribute nameNumberFormatException
- if the attribute type is ASCII but cannot be converted to a numberIllegalArgumentException
- if an attribute with the given name could not be foundpublic void setAttributeInt(String name, int value)
A new attribute with
ProductData.TYPE_INT32
is added to this node if an attribute with the given name could not be found
in this node.
name
- the attribute namevalue
- the new valuepublic void setAttributeDouble(String name, double value)
A new attribute with
ProductData.TYPE_FLOAT64
is added to this node if an attribute with the given name could not be found
in this node.
name
- the attribute namevalue
- the new valuepublic void setAttributeUTC(String name, ProductData.UTC value)
A new attribute with
ProductData.UTC
is added to this node if an attribute with the given name could not be found
in this node.
name
- the attribute namevalue
- the new valuepublic String getAttributeString(String name)
An Exception is thrown if an attribute with the given name could not be found in this node.
name
- the attribute nameIllegalArgumentException
- if an attribute with the given name could not be foundpublic String getAttributeString(String name, String defaultValue)
The given default value is returned if an attribute with the given name could not be found in this node.
name
- the attribute namedefaultValue
- the default valuepublic void setAttributeString(String name, String value)
A new attribute with
ProductData.TYPE_ASCII
is added to this node if an attribute with the given name could not be found
in this node.
name
- the attribute namevalue
- the new valuepublic void setModified(boolean modified)
ProductNode
If the modified flag changes to true and this node has an owner, the owner's modified flag is also set to true.
setModified
in class ProductNode
modified
- whether or not this node is beeing marked as modified.Product.fireNodeChanged(org.esa.snap.core.datamodel.ProductNode, java.lang.String, java.lang.Object, java.lang.Object)
public void acceptVisitor(ProductVisitor visitor)
The method first visits (calls acceptVisitor
for) all elements contained in this element and then
visits all attributes. Finally the method calls visitor.visit(this)
.
acceptVisitor
in class ProductNode
visitor
- the visitorpublic long getRawStorageSize(ProductSubsetDef subsetDef)
getRawStorageSize
in class ProductNode
subsetDef
- if not null
the subset may limit the size returnedpublic MetadataElement createDeepClone()
public void dispose()
This method should be called only if it is for sure that this object instance will never be used again. The
results of referencing an instance of this class after a call to dispose()
are undefined.
Overrides of this method should always call super.dispose();
after disposing this instance.
dispose
in class ProductNode
Copyright © 2014–2015 European Space Agency (ESA). All rights reserved.