org.gcube.contentmanagement.contentmanager.stubs.model.trees
Class Node

java.lang.Object
  extended by org.gcube.contentmanagement.contentmanager.stubs.model.trees.Node
Direct Known Subclasses:
InnerNode, Leaf

public abstract class Node
extends java.lang.Object

Base class for document nodes.

Author:
Fabio Simeoni (University of Strathclyde)

Nested Class Summary
static class Node.State
          Enumerates the state of the node with respect to remote storage.
 
Constructor Summary
Node()
          Creates an instance.
 
Method Summary
 java.util.List<InnerNode> ancestors()
          Returns the ancestors of the node.
 java.util.List<Node> ancestorsAndSelf()
          Returns the ancestors of the node along with the node itself.
 java.lang.String attribute(javax.xml.namespace.QName name)
          Returns the value of an attribute with a given name.
 java.lang.String attribute(java.lang.String name)
          Returns the value of an attribute with a given name.
 java.lang.String attribute(java.lang.String ns, java.lang.String name)
          Returns the value of an attribute with a given name.
 java.util.Map<javax.xml.namespace.QName,java.lang.String> attributes()
          Returns (a copy of) the node attributes.
 boolean equals(java.lang.Object obj)
          
 boolean hasAttribute(javax.xml.namespace.QName name)
          Indicates whether the node has an attribute with a given name.
 boolean hasAttribute(java.lang.String name)
          Indicates whether the node has an attribute with a given name.
 boolean hasAttribute(java.lang.String ns, java.lang.String name)
          Indicates whether the node has an attribute with a given name.
 int hashCode()
          
 java.lang.String id()
          Returns the node identifier.
 InnerNode parent()
          Returns the parent of the node.
 java.lang.String removeAttribute(javax.xml.namespace.QName name)
          Removes an attribute from the node, if it exists.
 java.lang.String removeAttribute(java.lang.String name)
          Removes an attribute from the node, if it exists.
 java.lang.String removeAttribute(java.lang.String ns, java.lang.String name)
          Removes an attribute from the node, if it exists.
 java.lang.String setAttribute(javax.xml.namespace.QName name, java.lang.String value)
          Sets the value of a given node attribute, or adds the attribute if it does not exist already.
 java.lang.String setAttribute(java.lang.String name, java.lang.String value)
          Sets the value of a given node attribute, or adds the attribute if it does not exist already.
 java.lang.String setAttribute(java.lang.String ns, java.lang.String name, java.lang.String value)
          Sets the value of a given node attribute, or adds the attribute if it does not exist already.
 Node.State state()
          Returns the node state.
 java.net.URI uri()
          Returns the content URI of the node.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Node

public Node()
Creates an instance.

Method Detail

id

public java.lang.String id()
Returns the node identifier.

Returns:
the identifier.

attributes

public java.util.Map<javax.xml.namespace.QName,java.lang.String> attributes()
Returns (a copy of) the node attributes.

Returns:
the attributes.

setAttribute

public java.lang.String setAttribute(javax.xml.namespace.QName name,
                                     java.lang.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 java.lang.String setAttribute(java.lang.String ns,
                                     java.lang.String name,
                                     java.lang.String value)
                              throws java.lang.IllegalArgumentException
Sets the value of a given node attribute, or adds the attribute if it does not exist already.

Parameters:
ns - the namespace of the attribute.
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:
java.lang.IllegalArgumentException - if the local name of the attribute is null.

setAttribute

public java.lang.String setAttribute(java.lang.String name,
                                     java.lang.String value)
                              throws java.lang.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:
java.lang.IllegalArgumentException - if the local name of the attribute is null.

removeAttribute

public java.lang.String removeAttribute(javax.xml.namespace.QName name)
                                 throws java.lang.IllegalStateException
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:
java.lang.IllegalStateException - if the nodes does not have an attribute with the given name.

removeAttribute

public java.lang.String removeAttribute(java.lang.String name)
                                 throws java.lang.IllegalStateException,
                                        java.lang.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:
java.lang.IllegalStateException - if the nodes does not have an attribute with the given name.
java.lang.IllegalArgumentException - if the local name of the attribute is null.

removeAttribute

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

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

attribute

public java.lang.String attribute(javax.xml.namespace.QName name)
                           throws java.lang.IllegalStateException
Returns the value of an attribute with a given name.

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

attribute

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

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

attribute

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

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

hasAttribute

public boolean hasAttribute(javax.xml.namespace.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(java.lang.String name)
                     throws java.lang.IllegalArgumentException
Indicates whether the node has an attribute with a given name.

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

hasAttribute

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

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

state

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

Returns:
the state.

parent

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

Returns:
the parent.

ancestors

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

Returns:
the ancestors.

ancestorsAndSelf

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

Returns:
the ancestors.

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

uri

public java.net.URI uri()
                 throws java.lang.IllegalStateException
Returns the content URI of the node.

cms://id0/id1/.../idN

where

Returns:
the URI.
Throws:
java.lang.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 collection identifier.