Class MetadataElement

  • All Implemented Interfaces:
    Extensible
    Direct Known Subclasses:
    SampleCoding

    public class MetadataElement
    extends ProductNode
    A 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 MetadataElements.
    Version:
    $Revision: 6651 $ $Date: 2009-10-27 12:59:39 +0100 (Di, 27 Okt 2009) $
    • Constructor Detail

      • MetadataElement

        public MetadataElement​(String name)
        Constructs a new metadata element.
        Parameters:
        name - the element name
    • Method Detail

      • getElementGroup

        public ProductNodeGroup<MetadataElement> 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.
      • addElement

        public void addElement​(MetadataElement element)
        Adds the given element to this element.
        Parameters:
        element - the element to added, ignored if null
      • addElementAt

        public void addElementAt​(MetadataElement element,
                                 int index)
        Adds the given element to this element at index.
        Parameters:
        element - the element to added, ignored if null
        index - where to put it
      • removeElement

        public boolean removeElement​(MetadataElement element)
        Removes the given element from this element.
        Parameters:
        element - the element to be removed, ignored if null
        Returns:
        true, if so
      • getNumElements

        public int getNumElements()
        Returns:
        the number of elements contained in this element.
      • getElementAt

        public MetadataElement getElementAt​(int index)
        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

        public String[] 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

        public MetadataElement[] 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

        public MetadataElement getElement​(String name)
        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

        public boolean containsElement​(String name)
        Tests if a element with the given name is contained in this element.
        Parameters:
        name - the name, must not be null
        Returns:
        true if a element with the given name is contained in this element, false otherwise
      • getElementIndex

        public int getElementIndex​(MetadataElement element)
        Gets the index of the given element.
        Parameters:
        element - The element .
        Returns:
        The element's index, or -1.
        Since:
        BEAM 4.7
      • addAttribute

        public void addAttribute​(MetadataAttribute attribute)
        Adds an attribute to this node.
        Parameters:
        attribute - the attribute to be added, null is ignored
      • removeAttribute

        public boolean removeAttribute​(MetadataAttribute attribute)
        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

        public MetadataAttribute getAttributeAt​(int index)
        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

        public String[] getAttributeNames()
        Returns the names of all attributes of this node.
        Returns:
        the attribute name array, never null
      • getAttributes

        public MetadataAttribute[] 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

        public MetadataAttribute getAttribute​(String name)
        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

        public boolean containsAttribute​(String name)
        Checks whether this node has an element with the given name.
        Parameters:
        name - the attribute name
        Returns:
        true if so
      • getAttributeIndex

        public int getAttributeIndex​(MetadataAttribute attribute)
        Gets the index of the given attribute.
        Parameters:
        attribute - The attribute.
        Returns:
        The attribute's index, or -1.
        Since:
        BEAM 4.7
      • getAttributeDouble

        public double getAttributeDouble​(String name,
                                         double defaultValue)
        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 name
        defaultValue - 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

        public double getAttributeDouble​(String name)
        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 number
        IllegalArgumentException - if an attribute with the given name could not be found
      • getAttributeUTC

        public ProductData.UTC getAttributeUTC​(String name,
                                               ProductData.UTC defaultValue)
        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 name
        defaultValue - the default value
        Returns:
        the attribute value as UTC.
      • getAttributeUTC

        public ProductData.UTC getAttributeUTC​(String name)
        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

        public int getAttributeInt​(String name,
                                   int defaultValue)
        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 name
        defaultValue - 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

        public int getAttributeInt​(String name)
        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 number
        IllegalArgumentException - if an attribute with the given name could not be found
      • setAttributeInt

        public void setAttributeInt​(String name,
                                    int value)
        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 name
        value - the new value
      • setAttributeDouble

        public void setAttributeDouble​(String name,
                                       double value)
        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 name
        value - the new value
      • setAttributeUTC

        public void setAttributeUTC​(String name,
                                    ProductData.UTC value)
        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 name
        value - the new value
      • getAttributeString

        public String getAttributeString​(String name)
        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

        public String getAttributeString​(String name,
                                         String defaultValue)
        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 name
        defaultValue - the default value
        Returns:
        the attribute value as integer.
      • setAttributeString

        public void setAttributeString​(String name,
                                       String value)
        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 name
        value - the new value
      • acceptVisitor

        public void acceptVisitor​(ProductVisitor visitor)
        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 calls visitor.visit(this).

        Specified by:
        acceptVisitor in class ProductNode
        Parameters:
        visitor - the visitor
      • getRawStorageSize

        public long getRawStorageSize​(ProductSubsetDef subsetDef)
        Gets an estimated, raw storage size in bytes of this product node.
        Specified by:
        getRawStorageSize in class ProductNode
        Parameters:
        subsetDef - if not null the subset may limit the size returned
        Returns:
        the size in bytes.
      • 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 class ProductNode