org.modeshape.jcr
Class JcrTools

java.lang.Object
  extended by org.modeshape.jcr.JcrTools

public class JcrTools
extends Object

Utility methods for working with JCR nodes.


Constructor Summary
JcrTools()
           
 
Method Summary
 Node findOrCreateChild(Node parent, String name)
          Get or create a node with the specified node under the specified parent node.
 Node findOrCreateChild(Node parent, String name, String nodeType)
          Get or create a node with the specified node and node type under the specified parent node.
 Node findOrCreateNode(Node parentNode, String path, String defaultNodeType, String finalNodeType)
          Get or create a node at the specified path.
 Node findOrCreateNode(Session session, String path)
          Get or create a node at the specified path.
 Node findOrCreateNode(Session session, String path, String nodeType)
          Get or create a node at the specified path and node type.
 Node findOrCreateNode(Session session, String path, String defaultNodeType, String finalNodeType)
          Get or create a node at the specified path.
 Node getNode(Node node, String relativePath, boolean required)
          Get the node under a specified node at a location defined by the specified relative path.
 String getReadable(Node node)
          Get the readable string form for a specified node.
 int removeAllChildren(Node node)
          Remove all children from the specified node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JcrTools

public JcrTools()
Method Detail

removeAllChildren

public int removeAllChildren(Node node)
                      throws RepositoryException
Remove all children from the specified node

Parameters:
node -
Returns:
the number of children removed.
Throws:
RepositoryException
IllegalArgumentException - if the node argument is null

getNode

public Node getNode(Node node,
                    String relativePath,
                    boolean required)
             throws RepositoryException
Get the node under a specified node at a location defined by the specified relative path. If node is required, then a problem is created and added to the Problems list.

Parameters:
node - a parent node from which to obtain a node relative to. may not be null
relativePath - the path of the desired node. may not be null
required - true if node is required to exist under the given node.
Returns:
the node located relative the the input node
Throws:
RepositoryException
IllegalArgumentException - if the node, relativePath or problems argument is null

getReadable

public String getReadable(Node node)
Get the readable string form for a specified node.

Parameters:
node - the node to obtain the readable string form. may be null
Returns:
the readable string form for a specified node.

findOrCreateNode

public Node findOrCreateNode(Session session,
                             String path)
                      throws RepositoryException
Get or create a node at the specified path.

Parameters:
session - the JCR session. may not be null
path - the path of the desired node to be found or created. may not be null
Returns:
the existing or newly created node
Throws:
RepositoryException
IllegalArgumentException - if either the session or path argument is null

findOrCreateNode

public Node findOrCreateNode(Session session,
                             String path,
                             String nodeType)
                      throws RepositoryException
Get or create a node at the specified path and node type.

Parameters:
session - the JCR session. may not be null
path - the path of the desired node to be found or created. may not be null
nodeType - the node type. may be null
Returns:
the existing or newly created node
Throws:
RepositoryException
IllegalArgumentException - if either the session or path argument is null

findOrCreateNode

public Node findOrCreateNode(Session session,
                             String path,
                             String defaultNodeType,
                             String finalNodeType)
                      throws RepositoryException
Get or create a node at the specified path.

Parameters:
session - the JCR session. may not be null
path - the path of the desired node to be found or created. may not be null
defaultNodeType - the default node type. may be null
finalNodeType - the optional final node type. may be null
Returns:
the existing or newly created node
Throws:
RepositoryException
IllegalArgumentException - if either the session or path argument is null

findOrCreateNode

public Node findOrCreateNode(Node parentNode,
                             String path,
                             String defaultNodeType,
                             String finalNodeType)
                      throws RepositoryException
Get or create a node at the specified path.

Parameters:
parentNode - the parent node. may not be null
path - the path of the desired child node. may not be null
defaultNodeType - the default node type. may be null
finalNodeType - the optional final node type. may be null
Returns:
the existing or newly created node
Throws:
RepositoryException
IllegalArgumentException - if either the parentNode or path argument is null

findOrCreateChild

public Node findOrCreateChild(Node parent,
                              String name)
                       throws RepositoryException
Get or create a node with the specified node under the specified parent node.

Parameters:
parent - the parent node. may not be null
name - the name of the child node. may not be null
Returns:
the existing or newly created child node
Throws:
RepositoryException
IllegalArgumentException - if either the parent or name argument is null

findOrCreateChild

public Node findOrCreateChild(Node parent,
                              String name,
                              String nodeType)
                       throws RepositoryException
Get or create a node with the specified node and node type under the specified parent node.

Parameters:
parent - the parent node. may not be null
name - the name of the child node. may not be null
nodeType - the node type. may be null
Returns:
the existing or newly created child node
Throws:
RepositoryException


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.