info.magnolia.module.delta
Class NodeVisitorTask

java.lang.Object
  extended by info.magnolia.module.delta.AbstractTask
      extended by info.magnolia.module.delta.AbstractRepositoryTask
          extended by info.magnolia.module.delta.NodeVisitorTask
All Implemented Interfaces:
Task

public abstract class NodeVisitorTask
extends AbstractRepositoryTask

The NodeVisitorTask helps traversing a repository, match nodes and execute changes on them.

This is intended to replace QueryTask for most cases, since query results may not account for pending changes in the session (e.g. coming from earlier deltas).


Field Summary
 
Fields inherited from class info.magnolia.module.delta.AbstractTask
DO_NOTHING, log
 
Constructor Summary
NodeVisitorTask(String name, String description, String workspace, String absPath)
           
 
Method Summary
protected  void doExecute(InstallContext installContext)
           
protected  org.apache.jackrabbit.commons.predicate.Predicate getFilteringPredicate()
          Override this method to specify a Predicate where we should stop visiting the hierarchy, e.g.
protected abstract  boolean nodeMatches(javax.jcr.Node node)
          Implement this method to define which nodes should subsequently be operated upon.
protected abstract  void operateOnNode(InstallContext installContext, javax.jcr.Node node)
          Implement this method to apply changes to each of the nodes that are matched by nodeMatches(Node).
 
Methods inherited from class info.magnolia.module.delta.AbstractRepositoryTask
execute
 
Methods inherited from class info.magnolia.module.delta.AbstractTask
getDescription, getName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NodeVisitorTask

public NodeVisitorTask(String name,
                       String description,
                       String workspace,
                       String absPath)
Method Detail

doExecute

protected void doExecute(InstallContext installContext)
                  throws javax.jcr.RepositoryException,
                         TaskExecutionException
Specified by:
doExecute in class AbstractRepositoryTask
Throws:
javax.jcr.RepositoryException
TaskExecutionException

nodeMatches

protected abstract boolean nodeMatches(javax.jcr.Node node)
Implement this method to define which nodes should subsequently be operated upon.

This will be called for every visited node in that task, and serves a similar purpose as a JCR query statement.

Parameters:
node - the JCR node that is currently being visited
Returns:
true if the node should be operated upon, false otherwise
See Also:
operateOnNode(InstallContext, Node)

operateOnNode

protected abstract void operateOnNode(InstallContext installContext,
                                      javax.jcr.Node node)
Implement this method to apply changes to each of the nodes that are matched by nodeMatches(Node).

This is typically where the update logic goes, in a similar fashion as the QueryTask.

Parameters:
installContext - the current install context
node - the JCR node that should be operated upon
See Also:
QueryTask#operateOnNode(InstallContext, Node)}

getFilteringPredicate

protected org.apache.jackrabbit.commons.predicate.Predicate getFilteringPredicate()
Override this method to specify a Predicate where we should stop visiting the hierarchy, e.g. to restrict node-types.

Mind that whatever the predicate, the starting node is always visited by NodeUtil, even if it doesn't match the predicate.

Returns:
by default, the constant predicate that returns true for all objects.


Copyright © 2003-2014 Magnolia International Ltd.. All Rights Reserved.