org.apache.jackrabbit.commons
Class AbstractNode

java.lang.Object
  extended by org.apache.jackrabbit.commons.AbstractItem
      extended by org.apache.jackrabbit.commons.AbstractNode
All Implemented Interfaces:
Item, Node

public abstract class AbstractNode
extends AbstractItem
implements Node

Abstract base class for implementing the JCR Node interface.

Item methods without a default implementation:

Node methods without a default implementation:


Field Summary
 
Fields inherited from interface javax.jcr.Node
JCR_CHILD_NODE_DEFINITION, JCR_CONTENT, JCR_FROZEN_NODE, JCR_PROPERTY_DEFINITION, JCR_ROOT_VERSION, JCR_VERSION_LABELS
 
Constructor Summary
AbstractNode()
           
 
Method Summary
 void accept(ItemVisitor visitor)
          Accepts the given item visitor.
 NodeType[] getMixinNodeTypes()
          Returns the declared mixin node types of this node.
 String getPath()
          Returns the path of this node.
 NodeType getPrimaryNodeType()
          Returns the primary node type of this node.
 Property getProperty(String relPath)
          Returns the property at the given relative path from this node.
 String getUUID()
          Returns the UUID of this node.
 VersionHistory getVersionHistory()
          Returns the version history of this node.
 boolean hasNode(String relPath)
          Checks whether a node at the given relative path exists.
 boolean hasNodes()
          Checks if this node has one or more properties.
 boolean hasProperties()
          Checks if this node has one or more properties.
 boolean hasProperty(String relPath)
          Checks whether a property at the given relative path exists.
 boolean holdsLock()
          Checks if this node holds a lock.
 boolean isCheckedOut()
          Checks whether this node is checked out.
 boolean isLocked()
          Checks if this node is locked.
 boolean isNode()
          Returns true.
 boolean isNodeType(String name)
          Checks whether this node is of the given type.
 void restore(String versionName, boolean removeExisting)
          Restores this node to the version with the given name.
 void restore(Version version, boolean removeExisting)
          Restores this node to the given version.
 void restoreByLabel(String versionLabel, boolean removeExisting)
          Restores this node to the version with the given label.
 Property setProperty(String name, boolean value)
          Sets the value of the named property.
 Property setProperty(String name, Calendar value)
          Sets the value of the named property.
 Property setProperty(String name, double value)
          Sets the value of the named property.
 Property setProperty(String name, InputStream value)
          Sets the value of the named property.
 Property setProperty(String name, long value)
          Sets the value of the named property.
 Property setProperty(String name, Node value)
          Sets the value of the named property.
 Property setProperty(String name, String value)
          Sets the value of the named property.
 Property setProperty(String name, String[] strings)
          Sets the value of the named property.
 Property setProperty(String name, String[] strings, int type)
          Sets the value of the named property.
 Property setProperty(String name, String value, int type)
          Sets the value of the named property.
 Property setProperty(String name, Value[] values, int type)
          Sets the value of the named property.
 Property setProperty(String name, Value value, int type)
          Sets the value of the named property.
 
Methods inherited from class org.apache.jackrabbit.commons.AbstractItem
getAncestor, getDepth, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.jcr.Node
addMixin, addNode, addNode, canAddMixin, cancelMerge, checkin, checkout, doneMerge, followLifecycleTransition, getAllowedLifecycleTransistions, getBaseVersion, getCorrespondingNodePath, getDefinition, getIdentifier, getIndex, getLock, getNode, getNodes, getNodes, getNodes, getPrimaryItem, getProperties, getProperties, getProperties, getReferences, getReferences, getSharedSet, getWeakReferences, getWeakReferences, lock, merge, orderBefore, removeMixin, removeShare, removeSharedSet, restore, setPrimaryType, setProperty, setProperty, setProperty, setProperty, unlock, update
 
Methods inherited from interface javax.jcr.Item
getAncestor, getDepth, getName, getParent, getSession, isModified, isNew, isSame, refresh, remove, save
 

Constructor Detail

AbstractNode

public AbstractNode()
Method Detail

accept

public void accept(ItemVisitor visitor)
            throws RepositoryException
Accepts the given item visitor.

The default implementation calls ItemVisitor.visit(Node) on the given visitor with this node as the argument.

Specified by:
accept in interface Item
Parameters:
visitor - item visitor
Throws:
RepositoryException - if an error occurs

getPath

public String getPath()
               throws RepositoryException
Returns the path of this node.

The default implementation recursively calls this method on the parent node and appends the name and optionally the index of this node to construct the full path. Returns "/" if the parent node is not available (i.e. this is the root node).

Specified by:
getPath in interface Item
Returns:
node path
Throws:
RepositoryException - if an error occurs

isNode

public boolean isNode()
Returns true.

Specified by:
isNode in interface Item
Returns:
true

getMixinNodeTypes

public NodeType[] getMixinNodeTypes()
                             throws RepositoryException
Returns the declared mixin node types of this node.

The default implementation uses the values of the jcr:mixinTypes property to look up the mixin node types from the NodeTypeManager of the current workspace.

Specified by:
getMixinNodeTypes in interface Node
Returns:
mixin node types
Throws:
RepositoryException - if an error occurs

getPrimaryNodeType

public NodeType getPrimaryNodeType()
                            throws RepositoryException
Returns the primary node type of this node.

The default implementation uses the value of the jcr:primaryType property to look up the primary node type from the NodeTypeManager of the current workspace.

Specified by:
getPrimaryNodeType in interface Node
Returns:
primary node type
Throws:
RepositoryException - if an error occurs

getProperty

public Property getProperty(String relPath)
                     throws PathNotFoundException,
                            RepositoryException
Returns the property at the given relative path from this node.

The default implementation looks up the parent node of the given relative path and iterates through the properties of that node to find and return the identified property.

Specified by:
getProperty in interface Node
Parameters:
relPath - relative path of the property
Returns:
property
Throws:
PathNotFoundException - if the property is not found
RepositoryException - if an error occurs

getUUID

public String getUUID()
               throws UnsupportedRepositoryOperationException,
                      RepositoryException
Returns the UUID of this node.

The default implementation checks if this node is referenceable (i.e. of type mix:referenceable) and returns the contents of the jcr:uuid property if it is.

Specified by:
getUUID in interface Node
Returns:
node UUID
Throws:
UnsupportedRepositoryOperationException - if this node is not referenceable
RepositoryException - if an error occurs

getVersionHistory

public VersionHistory getVersionHistory()
                                 throws RepositoryException
Returns the version history of this node.

The default implementation returns the containing version history of the base version of this node.

Specified by:
getVersionHistory in interface Node
Returns:
version history
Throws:
RepositoryException - if an error occurs

hasNode

public boolean hasNode(String relPath)
                throws RepositoryException
Checks whether a node at the given relative path exists.

The default implementation looks up the node using Node.getNode(String) and returns true if a PathNotFoundException is not thrown.

Specified by:
hasNode in interface Node
Parameters:
relPath - relative path
Returns:
true if a node exists at the given path, false otherwise
Throws:
RepositoryException - if an error occurs

hasNodes

public boolean hasNodes()
                 throws RepositoryException
Checks if this node has one or more properties.

The default implementation calls Node.getNodes() and returns true iff returned iterator has at least one element.

Specified by:
hasNodes in interface Node
Returns:
true if this node has child nodes, false otherwise
Throws:
RepositoryException - if an error occurs

hasProperties

public boolean hasProperties()
                      throws RepositoryException
Checks if this node has one or more properties.

The default implementation calls Node.getProperties() and returns true iff returned iterator has at least one element.

Note that in normal circumstances (i.e. no weird access controls) this method will always return true since all nodes always have at least the jcr:primaryType property.

Specified by:
hasProperties in interface Node
Returns:
true if this node has properties, false otherwise
Throws:
RepositoryException - if an error occurs

hasProperty

public boolean hasProperty(String relPath)
                    throws RepositoryException
Checks whether a property at the given relative path exists.

The default implementation looks up the property using Node.getProperty(String) and returns true if a PathNotFoundException is not thrown.

Specified by:
hasProperty in interface Node
Parameters:
relPath - relative path
Returns:
true if a property exists at the given path, false otherwise
Throws:
RepositoryException - if an error occurs

holdsLock

public boolean holdsLock()
                  throws RepositoryException
Checks if this node holds a lock.

The default implementation calls Node.getLock() and returns true iff the holding node of the lock is the same as this node.

Specified by:
holdsLock in interface Node
Returns:
true if this node holds a lock, false otherwise
Throws:
RepositoryException - if an error occurs

isCheckedOut

public boolean isCheckedOut()
                     throws RepositoryException
Checks whether this node is checked out.

The default implementation checks the jcr:isCheckedOut property if this node is versionable, and recursively calls this method on the parent node if this node is not versionable. A non-versionable root node always returns true from this method.

Specified by:
isCheckedOut in interface Node
Returns:
true if this node is checked out, false otherwise
Throws:
RepositoryException - if an error occurs

isLocked

public boolean isLocked()
                 throws RepositoryException
Checks if this node is locked.

The default implementation calls Node.getLock() and returns true iff a LockException is not thrown.

Specified by:
isLocked in interface Node
Returns:
true if this node is locked, false otherwise
Throws:
RepositoryException - if an error occurs

isNodeType

public boolean isNodeType(String name)
                   throws RepositoryException
Checks whether this node is of the given type.

The default implementation iterates through the primary and mixin types and all the supertypes of this node, returning true if a type with the given name is encountered. Returns false if none of the types matches.

Specified by:
isNodeType in interface Node
Parameters:
name - type name
Returns:
true if this node is of the given type, false otherwise
Throws:
RepositoryException - if an error occurs

restore

public void restore(String versionName,
                    boolean removeExisting)
             throws RepositoryException
Restores this node to the version with the given name.

The default implement retrieves the named Version from the associated VersionHistory and forwards the call to the Node.restore(Version, boolean) method.

Specified by:
restore in interface Node
Parameters:
versionName - version name
removeExisting - passed through
Throws:
RepositoryException - if an error occurs

restore

public void restore(Version version,
                    boolean removeExisting)
             throws RepositoryException
Restores this node to the given version.

The default implementation forwards the call to the Node.restore(Version, String, boolean) method using the relative path ".".

Specified by:
restore in interface Node
Parameters:
version - passed through
removeExisting - passed through
Throws:
RepositoryException - if an error occurs

restoreByLabel

public void restoreByLabel(String versionLabel,
                           boolean removeExisting)
                    throws RepositoryException
Restores this node to the version with the given label.

The default implement retrieves the labeled Version from the associated VersionHistory and forwards the call to the Node.restore(Version, boolean) method.

Specified by:
restoreByLabel in interface Node
Parameters:
versionLabel - version label
removeExisting - passed through
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            String[] strings)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instances from the given string values and forwards the call to the Node.setProperty(String, Value[]) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
strings - string values
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            String value)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance from the given string value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - string value
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            InputStream value)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance from the given binary value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - binary value
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            boolean value)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance from the given boolean value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - boolean value
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            double value)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance from the given double value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - double value
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            long value)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance from the given long value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - long value
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            Calendar value)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance from the given date value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - date value
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            Node value)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance from the given reference value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - reference value
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            Value value,
                            int type)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to convert the given value to the given type and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - property value
type - property type
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            Value[] values,
                            int type)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to convert the given values to the given type and forwards the call to the Node.setProperty(String, Value[]) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
values - property values
type - property type
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            String[] strings,
                            int type)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create Value instances of the given type from the given string values and forwards the call to the Node.setProperty(String, Value[]) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
strings - string values
type - property type
Returns:
modified property
Throws:
RepositoryException - if an error occurs

setProperty

public Property setProperty(String name,
                            String value,
                            int type)
                     throws RepositoryException
Sets the value of the named property.

The default implementation uses the ValueFactory of the current Session to create a Value instance of the given type from the given string value and forwards the call to the Node.setProperty(String, Value) method.

Specified by:
setProperty in interface Node
Parameters:
name - property name
value - string value
type - property type
Returns:
modified property
Throws:
RepositoryException - if an error occurs


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.