org.writersforge.catalan.transform
Class GroupProcessor

java.lang.Object
  extended byorg.writersforge.catalan.transform.BaseNodeProcessor
      extended byorg.writersforge.catalan.transform.GroupProcessor
All Implemented Interfaces:
org.writersforge.bellows.traverse.NodeProcessor

public class GroupProcessor
extends BaseNodeProcessor

Composite NodeProcessor which can combine multiple processors into a single easily referenced one. When used with Datum trees, can optionally select a subset of the current tree with a Bellows path, and only operate on that subset. This is useful for applying operations to specific nodes.

Author:
jsheets

Constructor Summary
GroupProcessor(org.writersforge.bellows.Datum xml, ProcessorRegistry registry)
          Creates a new instance of GroupProcessor from the XML spec.
GroupProcessor(org.writersforge.bellows.traverse.NodeProcessor[] processors, java.lang.Integer start, java.lang.Integer end, java.lang.String regexp, java.lang.Class filterClass)
          Creates a new instance of GroupProcessor to operate on a given range of input elements.
 
Method Summary
 void end(java.util.List nodes)
          Ends the current traversal.
 java.util.List processNode(java.lang.Object node)
          Process a single node.
 
Methods inherited from class org.writersforge.catalan.transform.BaseNodeProcessor
addLeftover, getLeftovers, getNodes, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupProcessor

public GroupProcessor(org.writersforge.bellows.Datum xml,
                      ProcessorRegistry registry)
Creates a new instance of GroupProcessor from the XML spec.

Parameters:
xml - XML initializing spec
registry - mapping registry for resolving embedded processors

GroupProcessor

public GroupProcessor(org.writersforge.bellows.traverse.NodeProcessor[] processors,
                      java.lang.Integer start,
                      java.lang.Integer end,
                      java.lang.String regexp,
                      java.lang.Class filterClass)
Creates a new instance of GroupProcessor to operate on a given range of input elements. The processors parameter is required but all others are optional and can be null. A start of null defaults to the first input node; an end of null defaults to the end of the list. The regexp and filterClass filter parameters are ignored if null. The results of the transform(s) will always be replaced into the same area of the input node list that the original nodes resided. Any nodes that were excluded will remain before or after the affected range. However, the nodes inside the range might be shuffled or resized according to the processing. When a filter is declared, the nodes that do not match the filter will be shuffled to the end of the range.

For example, given the node list [ "zero", "one", "two", new Integer (3), new Integer (4), "five, "six" ] with a range of 1 to 6 and a class filter of java.lang.String and the Concatenator processor, the output would be [ "zero", "onetwofive", 4, 5, "six" ]. The transform affects nodes "one" through "five", and only concatenates String nodes. The filtered-out Integer nodes are shuffled to the end of the range, but not to the end of the larger input node list.

Parameters:
processors - processors to wrap
start - index of first node to process
end - index of last node to process
regexp - optional regular expression filter, can be null
filterClass - optional class filter, can be null
Method Detail

processNode

public java.util.List processNode(java.lang.Object node)
Process a single node. The processing action can be any arbitrary task, such as text replacement, data restructuring, or even statistical gathering. The processor should return a processed version of the node; this can be the same object untouched, or the same object modified, or a new set of objects.

Parameters:
node - the node to process
Returns:
a List of processing results (can be empty)

end

public void end(java.util.List nodes)
Ends the current traversal. Any post-processing on the post-traversal nodes should be done here, for example removing duplicate nodes. This method should also clean up any temporary states created during a traversal. After end(), the processor should be ready for the next new traversal.

Specified by:
end in interface org.writersforge.bellows.traverse.NodeProcessor
Overrides:
end in class BaseNodeProcessor
Parameters:
nodes - the list of nodes that has just been traversed