org.gcube.data.trees.data
Class Node

java.lang.Object
  extended by org.gcube.data.trees.data.Node
Direct Known Subclasses:
InnerNode, Leaf

public abstract class Node
extends Object

A tree node.

Author:
Fabio Simeoni

Nested Class Summary
static class Node.State
          Enumerates the state of the node with respect to remote storage.
 
Constructor Summary
  Node()
          Creates an instance.
protected Node(String id)
           
protected Node(String i, Node.State s, Map<QName,String> as)
           
 
Method Summary
 List<InnerNode> ancestors()
          Returns the ancestors of the node.
 List<Node> ancestorsAndSelf()
          Returns the ancestors of the node along with the node itself.
 String attribute(QName name)
          Returns the value of an attribute with a given name.
 String attribute(String name)
          Returns the value of an attribute with a given name.
 Map<QName,String> attributes()
          Returns (a copy of) the node attributes.
 void delete()
          Marks the node as Node.State.DELETED, removing all its attributes.
protected  Node delta(Node future)
          Returns a node that reflects the delta between this node and a given input node.
 boolean equals(Object obj)
          
 boolean hasAttribute(QName name)
          Indicates whether the node has an attribute with a given name.
 boolean hasAttribute(String name)
          Indicates whether the node has an attribute with a given name.
 int hashCode()
          
 String id()
          Returns the node identifier.
 InnerNode parent()
          Returns the parent of the node.
 String removeAttribute(QName name)
          Removes an attribute from the node, if it exists.
 String removeAttribute(String name)
          Removes an attribute from the node, if it exists.
 String setAttribute(QName name, String value)
          Sets the value of a given node attribute, or adds the attribute if it does not exist already.
 String setAttribute(String name, String value)
          Sets the value of a given node attribute, or adds the attribute if it does not exist already.
protected  void setParent(InnerNode p)
          Sets the parent of the node.
abstract  long size()
          Returns the size of the tree rooted in this node, in bytes.
 Node.State state()
          Returns the node state.
protected  void state(Node.State s)
           
 void update(Node delta)
          Applies the changes captured by the delta node in input..
 URI uri()
          Returns a Http URL for the node which is resolvable in the current scope.
 URI uri(org.gcube.common.uri.Mint mint)
          Returns a Http URL for the node which is resolvable in the current scope.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Node

public Node()
Creates an instance.


Node

protected Node(String id)

Node

protected Node(String i,
               Node.State s,
               Map<QName,String> as)
Method Detail

size

public abstract long size()
Returns the size of the tree rooted in this node, in bytes.

Returns:
the size.

id

public String id()
Returns the node identifier.

Returns:
the identifier.

attributes

public Map<QName,String> attributes()
Returns (a copy of) the node attributes.

Returns:
the attributes.

setAttribute

public String setAttribute(QName name,
                           String value)
Sets the value of a given node attribute, or adds the attribute if it does not exist already.

Parameters:
name - the name of the attribute.
value - the value of the attribute.
Returns:
the previous value of the attribute, or null if the attribute does not exist already.

setAttribute

public String setAttribute(String name,
                           String value)
                    throws IllegalArgumentException
Sets the value of a given node attribute, or adds the attribute if it does not exist already.

Parameters:
name - the local name of the attribute.
value - the value of the attribute.
Returns:
the previous value of the attribute, or null if the attribute does not exist already.
Throws:
IllegalArgumentException - if the local name of the attribute is null.

removeAttribute

public String removeAttribute(QName name)
Removes an attribute from the node, if it exists.

Parameters:
name - the name of the attribute.
Returns:
the value of the attribute, or null if the attribute does not exist.
Throws:
IllegalStateException - if the nodes does not have an attribute with the given name.

removeAttribute

public String removeAttribute(String name)
                       throws IllegalStateException,
                              IllegalArgumentException
Removes an attribute from the node, if it exists.

Parameters:
name - the local name of the attribute.
Returns:
the value of the attribute, or null if the attribute does not exist.
Throws:
IllegalStateException - if the nodes does not have an attribute with the given name.
IllegalArgumentException - if the local name of the attribute is null.

attribute

public String attribute(QName name)
                 throws IllegalStateException
Returns the value of an attribute with a given name.

Parameters:
name - the name.
Returns:
the value.
Throws:
IllegalStateException - if an attribute with the given name does not exist.

attribute

public String attribute(String name)
                 throws IllegalStateException,
                        IllegalArgumentException
Returns the value of an attribute with a given name.

Parameters:
name - the local name of the attribute.
Returns:
the value.
Throws:
IllegalStateException - if an attribute with the given name does not exist.
IllegalArgumentException - if the local name of the attribute is null.

hasAttribute

public boolean hasAttribute(QName name)
Indicates whether the node has an attribute with a given name.

Parameters:
name - the name.
Returns:
true if it does, false otherwise.

hasAttribute

public boolean hasAttribute(String name)
                     throws IllegalArgumentException
Indicates whether the node has an attribute with a given name.

Parameters:
name - the name.
Returns:
true if it does, false otherwise.
Throws:
IllegalArgumentException - if the local name of the attribute is null.

state

public Node.State state()
Returns the node state.

Returns:
the state.

state

protected void state(Node.State s)

delete

public void delete()
Marks the node as Node.State.DELETED, removing all its attributes.


update

public void update(Node delta)
            throws IllegalStateException,
                   IllegalArgumentException
Applies the changes captured by the delta node in input..

This operation acts as the inverse of delta(Node). In particular:

  • removes all the attributes of the delta node with a value of null;
  • adds all the attributes of the delta node with a non-null value which do no exist in this node;
  • modifies all the attributes of the delta node that differ in value from those in this node;

    Parameters:
    delta - the delta node
    Throws:
    IllegalStateException - if this node has no identifier
    IllegalArgumentException - if the delta node has an unexpected state, or its identifier differs form this node's, or more generally its attributes do not relate to those of this node as expected

  • delta

    protected Node delta(Node future)
                  throws IllegalStateException,
                         IllegalArgumentException
    Returns a node that reflects the delta between this node and a given input node.

    The delta node can only be computed if the input node has the same identifier as this node. For all purposes, in fact, the input node is expected to be (or simply look like) a future version of this node, as if it was originally cloned from this node and had evolved since.

    Under this assumption, the delta node has:

  • all the attributes that no longer exist in the input node, but with a null value;
  • all the attributes of the input node that do not exist in this node;
  • all the attributes of the input node that differ in value from those in this node;
  • a state of Node.State.MODIFIED if the attributes of the two nodes are not identical.

    Subclasses that extend the comparison to additional pieces of state, must:

    • invoke this method via super;
    • extend them to the additional pieces of state.

    Parameters:
    future - the input node.
    Throws:
    IllegalStateException - if this node has no identifier.
    IllegalArgumentException - if this node has no identifier, or a different identifier's from the input node.

  • setParent

    protected void setParent(InnerNode p)
    Sets the parent of the node.

    Parameters:
    p - the parent.

    parent

    public InnerNode parent()
    Returns the parent of the node.

    Returns:
    the parent.

    ancestors

    public List<InnerNode> ancestors()
    Returns the ancestors of the node.

    Returns:
    the ancestors.

    ancestorsAndSelf

    public List<Node> ancestorsAndSelf()
    Returns the ancestors of the node along with the node itself.

    Returns:
    the ancestors.

    uri

    public URI uri()
            throws IllegalStateException
    Returns a Http URL for the node which is resolvable in the current scope.

    Returns:
    the URI
    Throws:
    IllegalStateException - if the node or one of its ancestors does not have an identifier, or if the root of the document does not specify a source identifier

    uri

    public URI uri(org.gcube.common.uri.Mint mint)
            throws IllegalStateException
    Returns a Http URL for the node which is resolvable in the current scope.

    Parameters:
    mint - a specific Mint for URL generation
    Returns:
    the URL
    Throws:
    IllegalStateException - if the node or one of its ancestors does not have an identifier, or if the root of the document does not specify a source identifier

    equals

    public boolean equals(Object obj)

    Overrides:
    equals in class Object

    hashCode

    public int hashCode()

    Overrides:
    hashCode in class Object


    Copyright © 2012. All Rights Reserved.