org.writersforge.catalan.transform.rule
Class CopyRule

java.lang.Object
  |
  +--org.writersforge.catalan.transform.rule.QueryRule
        |
        +--org.writersforge.catalan.transform.rule.CopyRule
All Implemented Interfaces:
Rule

public class CopyRule
extends QueryRule

A query-based Rule for duplicating elements or attributes to other parts of a Datum tree. The CopyRule can also be used to delete content by not providing a destination, or move content by instructing the Rule to remove the original.

Author:
jsheets

Method Summary
 java.lang.String getDestination()
          Getter for property destination, the Bellows query defining where to move to.
 boolean isMove()
          Getter for property move, whether or not to keep the original selection.
static CopyRule newCopyDatumRule(java.lang.String query, java.lang.String destination)
          Creates a new instance of CopyRule for copying Datum objects.
static CopyRule newCopyPropertyRule(java.lang.String query, java.lang.String destination, java.lang.String propertyName)
          Creates a new instance of CopyRule for copying Datum properties.
static CopyRule newDeleteDatumRule(java.lang.String query)
          Creates a new instance of CopyRule for deleting Datum objects.
static CopyRule newDeletePropertyRule(java.lang.String query, java.lang.String propertyName)
          Creates a new instance of CopyRule for deleting Datum properties.
static CopyRule newMoveDatumRule(java.lang.String query, java.lang.String destination)
          Creates a new instance of CopyRule for moving Datum objects.
static CopyRule newMovePropertyRule(java.lang.String query, java.lang.String destination, java.lang.String propertyName)
          Creates a new instance of CopyRule for moving Datum properties.
protected  void postProcessTargets(org.writersforge.bellows.Datum[] targets)
          Performs any cleanup or deletion on the source Datum objects after all normal processing is finished.
protected  org.writersforge.bellows.Datum processDatum(org.writersforge.bellows.Datum content, org.writersforge.bellows.Datum target)
          Applies changes to Datum objects in the supplied content.
protected  org.writersforge.bellows.Datum processProperty(org.writersforge.bellows.Datum content, org.writersforge.bellows.Datum target)
          Applies changes to Datum properties in the supplied content.
 
Methods inherited from class org.writersforge.catalan.transform.rule.QueryRule
getPropertyName, getQuery, isPropertyRule, process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newCopyDatumRule

public static CopyRule newCopyDatumRule(java.lang.String query,
                                        java.lang.String destination)
Creates a new instance of CopyRule for copying Datum objects. Uses the selection query to establish the Datum objects to copy, and the destination query to determine where to place copies of the originals.

Parameters:
query - the Bellows query to select target content
destination - the Bellows query to copy Datum objects to
Returns:
a Rule object which implements the requested operation

newCopyPropertyRule

public static CopyRule newCopyPropertyRule(java.lang.String query,
                                           java.lang.String destination,
                                           java.lang.String propertyName)
Creates a new instance of CopyRule for copying Datum properties. Uses the selection query to establish the Datum properties to copy, and the destination query to determine where to place copies of the originals.

If a Datum property already exists in a destination Datum, the Rule will implicitly rename the attribute with an appended number. This might happen if the property existed in the destination before the transform, or if the selection query hit more than one source Datum. Thus, an attempt to copy the 'attr' property from three source Datum objects into a destination Datum with the 'attr' property already defined would result in the following properties in the destination: 'attr', 'attr1', 'attr2', and 'attr3'. The copy Rule will do its best to not overwrite any existing properties, so if the destintation already has an 'attr2', the Rule will create a 1, 3, and 4 copy.

Parameters:
query - the Bellows query to select target content
destination - the Bellows query to copy Datum properties to
propertyName - the name of the Datum property to transform
Returns:
a Rule object which implements the requested operation

newMoveDatumRule

public static CopyRule newMoveDatumRule(java.lang.String query,
                                        java.lang.String destination)
Creates a new instance of CopyRule for moving Datum objects. Uses the selection query to establish the Datum objects to copy, and the destination query to determine where to place copies of the originals. The Rule will delete all the original Datum objects in the selection query after the copy operation.

Parameters:
query - the Bellows query to select target content
destination - the Bellows query to move Datum objects to
Returns:
a Rule object which implements the requested operation

newMovePropertyRule

public static CopyRule newMovePropertyRule(java.lang.String query,
                                           java.lang.String destination,
                                           java.lang.String propertyName)
Creates a new instance of CopyRule for moving Datum properties. Uses the selection query to establish the Datum properties to copy, and the destination query to determine where to place copies of the originals. The Rule will delete all the original Datum propertyName properties in the selection query after the copy operation. See newCopyPropertyRule(java.lang.String, java.lang.String, java.lang.String) for semantics on property copying.

Parameters:
query - the Bellows query to select target content
destination - the Bellows query to move Datum objects to
propertyName - the name of the Datum property to transform
Returns:
a Rule object which implements the requested operation

newDeleteDatumRule

public static CopyRule newDeleteDatumRule(java.lang.String query)
Creates a new instance of CopyRule for deleting Datum objects. Uses the selection query to establish the Datum objects to delete.

Parameters:
query - the Bellows query to select target content
Returns:
a Rule object which implements the requested operation

newDeletePropertyRule

public static CopyRule newDeletePropertyRule(java.lang.String query,
                                             java.lang.String propertyName)
Creates a new instance of CopyRule for deleting Datum properties. Uses the selection query to establish the Datum properties to delete.

Parameters:
query - the Bellows query to select target content
propertyName - the name of the Datum property to delete
Returns:
a Rule object which implements the requested operation

getDestination

public java.lang.String getDestination()
Getter for property destination, the Bellows query defining where to move to. If the destination query is null or produces zero results, the Move operation will be equivalent to a Delete (or a no-op if this is a Copy operation). If the destination query produces more than one result, the selected content will be duplicated at each location.

Returns:
Value of property destination.

isMove

public boolean isMove()
Getter for property move, whether or not to keep the original selection. If move is false, this Rule will leave the original selection in place; if move is true, this Rule will delete the original selection.

Returns:
Value of property move.

processDatum

protected org.writersforge.bellows.Datum processDatum(org.writersforge.bellows.Datum content,
                                                      org.writersforge.bellows.Datum target)
Applies changes to Datum objects in the supplied content. If the Rule decides not to make any changes, it can return the original content, untouched.

Specified by:
processDatum in class QueryRule
Parameters:
content - the root of the processing tree
target - a Datum object to apply the Rule to
Returns:
the transformed content

processProperty

protected org.writersforge.bellows.Datum processProperty(org.writersforge.bellows.Datum content,
                                                         org.writersforge.bellows.Datum target)
Applies changes to Datum properties in the supplied content. If the Rule decides not to make any changes, it can return the original content, untouched.

Specified by:
processProperty in class QueryRule
Parameters:
content - the root of the processing tree
target - a Datum object to apply the Rule to
Returns:
the transformed content

postProcessTargets

protected void postProcessTargets(org.writersforge.bellows.Datum[] targets)
Performs any cleanup or deletion on the source Datum objects after all normal processing is finished.

Overrides:
postProcessTargets in class QueryRule
Parameters:
targets - an array of individual Datum objects to post-process