com.objectwave.templateMerge
Class InformationToken

java.lang.Object
  |
  +--com.objectwave.templateMerge.InformationToken
All Implemented Interfaces:
java.io.Serializable

public class InformationToken
extends java.lang.Object
implements java.io.Serializable

Generic class for creating the ability to allow a developer to define a token and how to get the data to replace the values in that token. These are very specific to the application at hand.

Version:
2.0
Author:
Dave Hoag
See Also:
MergeTemplate, Serialized Form

Constructor Summary
InformationToken(java.lang.String tok, InformationRetrieval ir, java.lang.String desc)
          There are 3 mandatory elements of a token.
 
Method Summary
 java.lang.String compareData(java.lang.String message, int[] skip)
          Allow the user to require data to be of a certain type.
protected  int endIndex(java.lang.String init, int start, int open)
          Find the matching end to the open.
 boolean equals(java.lang.Object obj)
          Equality check: check for "nullness", then for class types, then for token and description strings.
 java.lang.String getDescription()
          A user friendly description
 InformationRetrieval getInfoReader()
          A special object that will be able to extract data from a specific object.
 java.lang.String getTokenString()
          A token that will be replaced with the data from the InfoReader
 java.lang.String insertData(java.lang.String data, java.lang.String message)
          Replace the tokens in the message with the value of data.
 java.lang.String insertField(java.lang.Object ci, java.lang.String message)
          Using the provided object, get the necessary data that we will insert into the generated code.
 java.lang.String insertField(java.lang.Object ci, java.lang.String message, java.lang.String defaultData)
          Using the provided object, get the necessary data that we will insert into the generated code.
 boolean isCollection()
          A collection will create multiple versions of a template.
 boolean isIterator()
          An interator is similar to a data element, except that it can be multiple data elements seperated via a ','.
 boolean isTree()
          A tree will create multiple versions of a template, just like a collection, but elements in the collection will be used to merge subtemplates (as opposed to one object used to merge all subtemplates).
protected  java.lang.String optEnd()
          No need to include the token in the 'end' since optional tags MUST have both a begin and an end.
protected  java.lang.String optStart()
          Some tokens merely specify that the text between two tags is optional.
 java.lang.String removeOptionalTags(java.lang.String message, java.lang.String comparisonValue)
          We can add tags to a template definition that indicate optional data.
 java.lang.String removeOptionalText(java.lang.String message, java.lang.String compare)
          Remove the text that has been tagged in the template definition as optional.
 void setCollection(boolean aValue)
           
 void setDescription(java.lang.String desc)
           
 void setInfoReader(InformationRetrieval ir)
           
 void setIterator(boolean aValue)
           
 void setTokenString(java.lang.String st)
           
 void setTree(boolean aValue)
           
 java.lang.String toString()
          The token value + the description.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InformationToken

public InformationToken(java.lang.String tok,
                        InformationRetrieval ir,
                        java.lang.String desc)
There are 3 mandatory elements of a token. First is the String representation of that token. Second the InformationRetrieval class that will provide the data to the token. Third, a Description of what this token represents.

Method Detail

equals

public boolean equals(java.lang.Object obj)
Equality check: check for "nullness", then for class types, then for token and description strings.

Overrides:
equals in class java.lang.Object

getDescription

public java.lang.String getDescription()
A user friendly description


getInfoReader

public InformationRetrieval getInfoReader()
A special object that will be able to extract data from a specific object.


getTokenString

public java.lang.String getTokenString()
A token that will be replaced with the data from the InfoReader


compareData

public java.lang.String compareData(java.lang.String message,
                                    int[] skip)
Allow the user to require data to be of a certain type. Works with optional tags.


insertData

public java.lang.String insertData(java.lang.String data,
                                   java.lang.String message)
Replace the tokens in the message with the value of data.

Parameters:
data - The data with which to replace all instances of 'tokenstring'.
message - The template for which we are insterting data.
Returns:
The modified version of the template.

insertField

public java.lang.String insertField(java.lang.Object ci,
                                    java.lang.String message)
Using the provided object, get the necessary data that we will insert into the generated code.

See Also:
insertData(java.lang.String, java.lang.String)

insertField

public java.lang.String insertField(java.lang.Object ci,
                                    java.lang.String message,
                                    java.lang.String defaultData)
Using the provided object, get the necessary data that we will insert into the generated code. If this token is either an Iterator or a Collection token, the data value will be all of the elements in the Enumeration separated by a ','.

Parameters:
defaultData - Will be the string used if the parameter value is null.
See Also:
insertData(java.lang.String, java.lang.String)

isCollection

public boolean isCollection()
A collection will create multiple versions of a template. One version for each element in the collection. For examples, accessor methods for a variable.


isIterator

public boolean isIterator()
An interator is similar to a data element, except that it can be multiple data elements seperated via a ','.


isTree

public boolean isTree()
A tree will create multiple versions of a template, just like a collection, but elements in the collection will be used to merge subtemplates (as opposed to one object used to merge all subtemplates).


optEnd

protected java.lang.String optEnd()
No need to include the token in the 'end' since optional tags MUST have both a begin and an end. Additionally, it works like '('. Inner matches must be resolved first.


optStart

protected java.lang.String optStart()
Some tokens merely specify that the text between two tags is optional. The text will be removed if the token value is null or "". %tokenname%{-}TEXT TO BE REMOVED OR KEPT}-{ It is possible to specify that the text must be a specific value. %tokenname%{-}{"TOKENVALUE"}TEXT TO BE REMOVED OR KEPT}-{ The above woult require the token 'tokenname' to have a value of "TOKENVALUE". If this was true, the corresponding text would be printed, otherwise it is removed.


removeOptionalTags

public java.lang.String removeOptionalTags(java.lang.String message,
                                           java.lang.String comparisonValue)
We can add tags to a template definition that indicate optional data. This method will remove those tags, but leave the text.


removeOptionalText

public java.lang.String removeOptionalText(java.lang.String message,
                                           java.lang.String compare)
Remove the text that has been tagged in the template definition as optional. The 'optional text' corresponds to tokens that match the optStart and the optEnd strings. If a token is blank, optional text will be removed.

Parameters:
compare - An additional parameter to the optional tag.
message - The original template.
Returns:
A modified version of the templates with all of the data between the optional tags removed.

endIndex

protected int endIndex(java.lang.String init,
                       int start,
                       int open)
Find the matching end to the open. Similar to finding the matching paren in "(( ) () )".


setCollection

public void setCollection(boolean aValue)

setDescription

public void setDescription(java.lang.String desc)

setInfoReader

public void setInfoReader(InformationRetrieval ir)

setIterator

public void setIterator(boolean aValue)

setTokenString

public void setTokenString(java.lang.String st)

setTree

public void setTree(boolean aValue)

toString

public java.lang.String toString()
The token value + the description.

Overrides:
toString in class java.lang.Object