net.sf.mmm.util.transformer.base
Class StringTransformerChain

java.lang.Object
  extended by net.sf.mmm.util.transformer.base.StringTransformerChain
All Implemented Interfaces:
Transformer<String>

public class StringTransformerChain
extends Object
implements Transformer<String>

This class represents a Transformer for Strings that is build out of a list of rules. It performs its transformation by passing the given value to the first rule and its result to the next rule and so on. If a rule matched, it can stop further proceeding via the stop-on-match flag and cause its result to be returned immediately. Otherwise the result of the last rule in the chain is returned (like a left associative operator).

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Nested Class Summary
protected static class StringTransformerChain.State
          This inner class contains the state of a transformation.
 
Field Summary
private  String id
           
private  StringTransformerChain parent
          The parent that is extended by this chain or null.
private  StringTransformerRule[] rules
          The rules of this chain.
 
Constructor Summary
StringTransformerChain()
          The non-arg constructor.
StringTransformerChain(String id, StringTransformerChain parent, StringTransformerRule... rules)
          The constructor.
StringTransformerChain(StringTransformerRule... rules)
          The constructor.
 
Method Summary
 StringTransformerChain extend(StringTransformerRule... additionalRules)
          This method extends this chain with additionalRules.
 String getId()
          This method gets the ID used to identify this chain.
 String transform(String original)
          This method transforms a given original value.
private  String transformRecursive(String original, StringTransformerChain.State state)
          This method implements transform(String) recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

private String id
See Also:
getId()

parent

private StringTransformerChain parent
The parent that is extended by this chain or null.


rules

private StringTransformerRule[] rules
The rules of this chain.

Constructor Detail

StringTransformerChain

public StringTransformerChain()
The non-arg constructor.
NOTE:
This constructor should not be called directly! It is only intended for reflective access (e.g. for JAXB).


StringTransformerChain

public StringTransformerChain(StringTransformerRule... rules)
The constructor.

Parameters:
rules - are the rules of this chain.

StringTransformerChain

public StringTransformerChain(String id,
                              StringTransformerChain parent,
                              StringTransformerRule... rules)
The constructor.

Parameters:
id - the ID of this chain.
parent - is the parent chain to extend or null for a root-chain.
rules - are the rules of this chain.
Method Detail

transform

public String transform(String original)
This method transforms a given original value. This value must NOT be modified by this method. To change the original value a new value has to be created and returned instead. If the value should NOT be changed, the original value (the exact same instance) should be returned.

Specified by:
transform in interface Transformer<String>
Parameters:
original - is the original value.
Returns:
the transformed value. May only be null if explicitly documented by the implementation. The receiver of a Transformer should also document if null is a legal result.

transformRecursive

private String transformRecursive(String original,
                                  StringTransformerChain.State state)
This method implements transform(String) recursively.

Parameters:
original - is the original value.
state - is the StringTransformerChain.State used to indicate if a rule causes the chain to StringTransformerChain.State.stop.
Returns:
the transformed result.

getId

public String getId()
This method gets the ID used to identify this chain.

Returns:
the ID or null if undefined.

extend

public StringTransformerChain extend(StringTransformerRule... additionalRules)
This method extends this chain with additionalRules.
ATTENTION:
If you want to be able to marshall the chain with JAXB, you have to use StringTransformerChain(String, StringTransformerChain, StringTransformerRule...) instead.

Parameters:
additionalRules - are the rules to add.
Returns:
the chain that also checks the additionalRules if none of this rules match.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.