Class MetadataElement
- All Implemented Interfaces:
Extensible
- Direct Known Subclasses:
SampleCoding
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.- Version:
- $Revision: 6651 $ $Date: 2009-10-27 12:59:39 +0100 (Di, 27 Okt 2009) $
-
Field Summary
Fields inherited from class org.esa.snap.core.datamodel.ProductNode
PROPERTY_NAME_DESCRIPTION, PROPERTY_NAME_NAME
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.void
dispose()
Releases all of the resources used by this object instance and all of its owned children.getAttribute
(String name) Returns the attribute with the given name.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[]
Returns the names of all attributes of this node.Returns an array of attributes contained in this element.getAttributeString
(String name) Returns the string value of the attribute with the given name.getAttributeString
(String name, String defaultValue) Returns the string value of the attribute with the given name.getAttributeUTC
(String name) Returns the UTC value of the attribute with the given name.getAttributeUTC
(String name, ProductData.UTC defaultValue) Returns the UTC value of the attribute with the given name.getElement
(String name) Returns the element with the given name.getElementAt
(int index) Returns the element at the given index.Gets the group of child elements.int
getElementIndex
(MetadataElement element) Gets the index of the given element.String[]
Returns a string array containing the names of the groups contained in this elementReturns an array of elements contained in this element.int
Returns the number of attributes attached to this node.int
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.Methods inherited from class org.esa.snap.core.datamodel.ProductNode
fireProductNodeChanged, fireProductNodeChanged, getDescription, getDisplayName, getName, getOwner, getProduct, getProductReader, getProductReaderSafe, getProductRefString, getProductSafe, getProductWriter, getProductWriterSafe, getRawStorageSize, isModified, isPartOfSubset, isValidNodeName, removeFromFile, setDescription, setName, setNodeName, setOwner, toString, updateExpression
Methods inherited from class com.bc.ceres.core.ExtensibleObject
getExtension
-
Constructor Details
-
MetadataElement
Constructs a new metadata element.- Parameters:
name
- the element name
-
-
Method Details
-
getElementGroup
Gets the group of child elements. The method returns null, if this element has no children.- Returns:
- The child element group, may be null.
-
getParentElement
-
addElement
Adds the given element to this element.- Parameters:
element
- the element to added, ignored ifnull
-
addElementAt
Adds the given element to this element at index.- Parameters:
element
- the element to added, ignored ifnull
index
- where to put it
-
removeElement
Removes the given element from this element.- Parameters:
element
- the element to be removed, ignored ifnull
- Returns:
- true, if so
-
getNumElements
public int getNumElements()- Returns:
- the number of elements contained in this element.
-
getElementAt
Returns the element at the given index.- Parameters:
index
- the element index- Returns:
- the element at the given index
- Throws:
IndexOutOfBoundsException
- if the index is out of bounds
-
getElementNames
Returns a string array containing the names of the groups contained in this element- Returns:
- a string array containing the names of the groups contained in this element. If this element has no groups a zero-length-array is returned.
-
getElements
Returns an array of elements contained in this element.- Returns:
- an array of elements contained in this product. If this element has no elements a zero-length-array is returned.
-
getElement
Returns the element with the given name.- Parameters:
name
- the element name- Returns:
- the element with the given name or
null
if a element with the given name is not contained in this element.
-
containsElement
Tests if a element with the given name is contained in this element.- Parameters:
name
- the name, must not benull
- Returns:
true
if a element with the given name is contained in this element,false
otherwise
-
getElementIndex
Gets the index of the given element.- Parameters:
element
- The element .- Returns:
- The element's index, or -1.
- Since:
- BEAM 4.7
-
addAttribute
Adds an attribute to this node.- Parameters:
attribute
- the attribute to be added,null
is ignored
-
removeAttribute
Removes the given attribute from this annotation. If an attribute with the same name already exists, the method does nothing.- Parameters:
attribute
- the attribute to be removed,null
is ignored- Returns:
true
if it was removed
-
getNumAttributes
public int getNumAttributes()Returns the number of attributes attached to this node.- Returns:
- the number of attributes
-
getAttributeAt
Returns the attribute at the given index.- Parameters:
index
- the attribute index- Returns:
- the attribute, or
null
if this node does not contain attributes - Throws:
IndexOutOfBoundsException
-
getAttributeNames
Returns the names of all attributes of this node.- Returns:
- the attribute name array, never
null
-
getAttributes
Returns an array of attributes contained in this element.- Returns:
- an array of attributes contained in this product. If this element has no attributes a zero-length-array is returned.
-
getAttribute
Returns the attribute with the given name.- Parameters:
name
- the attribute name- Returns:
- the attribute with the given name or
null
if it could not be found
-
containsAttribute
Checks whether this node has an element with the given name.- Parameters:
name
- the attribute name- Returns:
true
if so
-
getAttributeIndex
Gets the index of the given attribute.- Parameters:
attribute
- The attribute.- Returns:
- The attribute's index, or -1.
- Since:
- BEAM 4.7
-
getAttributeDouble
Returns the double value of the attribute with the given name.The given default value is returned if an attribute with the given name could not be found in this node.
- Parameters:
name
- the attribute namedefaultValue
- the default value- Returns:
- the attribute value as double.
- Throws:
NumberFormatException
- if the attribute type is ASCII but cannot be converted to a number
-
getAttributeDouble
Returns the double value of the attribute with the given name.An Exception is thrown if an attribute with the given name could not be found in this node.
- Parameters:
name
- the attribute name- Returns:
- the attribute value as double.
- Throws:
NumberFormatException
- if the attribute type is ASCII but cannot be converted to a numberIllegalArgumentException
- if an attribute with the given name could not be found
-
getAttributeUTC
Returns the UTC value of the attribute with the given name.The given default value is returned if an attribute with the given name could not be found in this node.
- Parameters:
name
- the attribute namedefaultValue
- the default value- Returns:
- the attribute value as UTC.
-
getAttributeUTC
Returns the UTC value of the attribute with the given name.- Parameters:
name
- the attribute name- Returns:
- the attribute value as UTC.
- Throws:
IllegalArgumentException
- if an attribute with the given name could not be found
-
getAttributeInt
Returns the integer value of the attribute with the given name.The given default value is returned if an attribute with the given name could not be found in this node.
- Parameters:
name
- the attribute namedefaultValue
- the default value- Returns:
- the attribute value as integer.
- Throws:
NumberFormatException
- if the attribute type is ASCII but cannot be converted to a number
-
getAttributeInt
Returns the integer value of the attribute with the given name.An Exception is thrown if an attribute with the given name could not be found in this node.
- Parameters:
name
- the attribute name- Returns:
- the attribute value as integer.
- Throws:
NumberFormatException
- if the attribute type is ASCII but cannot be converted to a numberIllegalArgumentException
- if an attribute with the given name could not be found
-
setAttributeInt
Sets the attribute with the given name to the given integer 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.- Parameters:
name
- the attribute namevalue
- the new value
-
setAttributeDouble
Sets the attribute with the given name to the given 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.- Parameters:
name
- the attribute namevalue
- the new value
-
setAttributeUTC
Sets the attribute with the given name to the given 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.- Parameters:
name
- the attribute namevalue
- the new value
-
getAttributeString
Returns the string value of the attribute with the given name.An Exception is thrown if an attribute with the given name could not be found in this node.
- Parameters:
name
- the attribute name- Returns:
- the attribute value as integer.
- Throws:
IllegalArgumentException
- if an attribute with the given name could not be found
-
getAttributeString
Returns the string value of the attribute with the given name.The given default value is returned if an attribute with the given name could not be found in this node.
- Parameters:
name
- the attribute namedefaultValue
- the default value- Returns:
- the attribute value as integer.
-
setAttributeString
Sets the attribute with the given name to the given 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.- Parameters:
name
- the attribute namevalue
- the new value
-
setModified
public void setModified(boolean modified) Description copied from class:ProductNode
Sets this node's modified flag.If the modified flag changes to true and this node has an owner, the owner's modified flag is also set to true.
- Overrides:
setModified
in classProductNode
- Parameters:
modified
- whether or not this node is beeing marked as modified.- See Also:
-
acceptVisitor
Accepts the given visitor. This method implements the well known 'Visitor' design pattern of the gang-of-four. The visitor pattern allows to define new operations on the product data model without the need to add more code to it. The new operation is implemented by the visitor.The method first visits (calls
acceptVisitor
for) all elements contained in this element and then visits all attributes. Finally the method callsvisitor.visit(this)
.- Specified by:
acceptVisitor
in classProductNode
- Parameters:
visitor
- the visitor
-
getRawStorageSize
Gets an estimated, raw storage size in bytes of this product node.- Specified by:
getRawStorageSize
in classProductNode
- Parameters:
subsetDef
- if notnull
the subset may limit the size returned- Returns:
- the size in bytes.
-
createDeepClone
-
dispose
public void dispose()Releases all of the resources used by this object instance and all of its owned children. Its primary use is to allow the garbage collector to perform a vanilla job.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.- Overrides:
dispose
in classProductNode
-