org.apache.torque.generator.source.transform
Class AttributeTransformer

java.lang.Object
  extended by org.apache.torque.generator.source.transform.AttributeTransformer
All Implemented Interfaces:
SourceTransformer

public class AttributeTransformer
extends Object
implements SourceTransformer

Adds or replaces attributes in a SourceElement according to a definition file. An example for a line in the definition file would be:

${attribute(override):newAttribute}=prefix${attribute:oldAttribute}${option:suffix}

This would add the attribute newAttribute to the current sourceElement, and its content would be (in java notation) "prefix" + (currentElement.getAttribute("oldAttribute") == null ? "" : currentElement.getAttribute("oldAttribute")) + options.getOption("suffix")

On the left hand side, one can use attribute(override) (which replaces the attribute if its already there) and attribute(noOverride) which preserves the attribute if its already there. On the right hand side, you can use either plain text, ${attribute:attributeName} and ${option:optionName} in any combination. Escape character is the backslash. Lines starting with # and empty lines are disregarded.


Constructor Summary
AttributeTransformer(Reader transformDefinition)
          Constructor.
 
Method Summary
 SourceElement transform(SourceElement toTransform, ControllerState controllerState)
          Adds attributes to the sourceElement according to the transformDefinition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributeTransformer

public AttributeTransformer(Reader transformDefinition)
                     throws SourceTransformerException
Constructor.

Parameters:
transformDefinition - the Reader from which the transformDefinition is read. The Reader is closed after processing.
Throws:
SourceTransformerException - if an error occurs while reading or parsing the transformDefinition.
Method Detail

transform

public SourceElement transform(SourceElement toTransform,
                               ControllerState controllerState)
                        throws SourceTransformerException
Adds attributes to the sourceElement according to the transformDefinition.

Specified by:
transform in interface SourceTransformer
Parameters:
toTransform - the sourceElement to transform. Must implement EditableSourceElement.
controllerState - the current state of the controller, not null.
Returns:
the source element with the additional attributes added.
Throws:
SourceTransformerException - if an error occurs during transforming.


Copyright © 2000-2012 The Apache Software Foundation. All Rights Reserved.