org.umber.catalan.transform.xform
Class MoveProcessor

java.lang.Object
  extended byorg.umber.catalan.transform.BaseNodeProcessor
      extended byorg.umber.catalan.transform.xform.XFormProcessor
          extended byorg.umber.catalan.transform.xform.MoveProcessor
All Implemented Interfaces:
INodeProcessor

public class MoveProcessor
extends XFormProcessor

A Datum-only NodeProcessor for moving existing XML content to other parts of the same XML tree. Works on element content or on attributes.

Author:
jsheets

Constructor Summary
MoveProcessor(Datum xml)
          Creates a new instance of MoveProcessor from the XML spec.
MoveProcessor(java.lang.String query, java.lang.String destination, java.lang.String attribute, int position)
          Creates a new instance of MoveProcessor.
 
Method Summary
protected  Datum[] getDestinationNodes(Datum datum)
          Finds the Datum nodes to perform the transformation on.
 void start(java.util.List nodes)
          Starts a new traversal.
protected  Datum transformNode(Datum node, Datum root)
          Performs an in-place transformation on the supplied Datum tree.
 
Methods inherited from class org.umber.catalan.transform.xform.XFormProcessor
getQuery, getQueryNodes, processNode
 
Methods inherited from class org.umber.catalan.transform.BaseNodeProcessor
addLeftover, end, getLeftovers, getNodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MoveProcessor

public MoveProcessor(Datum xml)
Creates a new instance of MoveProcessor from the XML spec.

Parameters:
xml - XML initializing spec

MoveProcessor

public MoveProcessor(java.lang.String query,
                     java.lang.String destination,
                     java.lang.String attribute,
                     int position)
Creates a new instance of MoveProcessor. If attribute is null, the processor will move (recursively) at the element level. If attribute is set, the processor will move only matching attributes.

Parameters:
query - Bellows query path to select the source node(s)
destination - Bellows query path to select the destination node(s)
attribute - optional attribute name
position - the index position to insert nodes, or -1 to insert at end of list
Method Detail

start

public void start(java.util.List nodes)
Starts a new traversal. This method initializes the processor for a new traversal over a set of nodes. The nodes are not actually traversed or processed at this point, but the processor is allowed to perform any pre-traversal calculations, for example storing the total number of nodes for index calculations.

Specified by:
start in interface INodeProcessor
Overrides:
start in class BaseNodeProcessor
Parameters:
nodes - the list of nodes that will later be traversed

getDestinationNodes

protected Datum[] getDestinationNodes(Datum datum)
Finds the Datum nodes to perform the transformation on.

Parameters:
datum - the input datum tree to select nodes from
Returns:
the nodes to operate on

transformNode

protected Datum transformNode(Datum node,
                              Datum root)
Performs an in-place transformation on the supplied Datum tree.

Specified by:
transformNode in class XFormProcessor
Parameters:
node - the current node to operate upon
root - the root of the entire XML tree
Returns:
the new root Datum object (usually the same one)