com.unitesk.atp.tree.generation
Class TextGeneratorClient

java.lang.Object
  extended by com.unitesk.atp.tree.generation.TextGeneratorClient
All Implemented Interfaces:
Function, Generator, TextGenerator
Direct Known Subclasses:
TextGeneratorVisitor

public abstract class TextGeneratorClient
extends Object
implements TextGenerator, Function

The base client implementing interface of text generation. Delegates all text generation processing to underlying TextGeneratorServer that can be shared between several clients. Abstract visit(Node) method should be overridden by inheritors to implement node processing.

Since:
3.5
Version:
$Id: TextGeneratorClient.java,v 1.1 2005/07/17 19:35:16 all-x Exp $
Author:
Alexey Demakov

Field Summary
protected  TextGeneratorServer server
           
 
Fields inherited from interface com.unitesk.atp.tree.generation.TextGenerator
endl
 
Fields inherited from interface com.unitesk.atp.text.generation.Generator
DEFAULT_NAME
 
Constructor Summary
TextGeneratorClient()
           
 
Method Summary
 void decIndent()
          Decreases indent level at one indent step.
 Function getFunction(String name)
          Returns function by name.
 int getIndent()
          Returns the current indent level.
 Node getNode()
          Returns current node.
 Object getVariable(String name)
          Returns variable by name.
 void incIndent()
          Increases indent level at one indent step.
 void list(String index, int start, int end, String str, String separator)
          Prints list of strings.
 void nl()
          Starts a new line of text.
 void popIndent()
          Restores previous indent level.
 void popNode()
          Restore previous node.
 void process(Object arg)
          Processes the specified object.
 void pushIndent(int indent)
          Makes indent current indent level.
 void pushNode(Node node)
          Sets default node for all operations with attributes.
 Function setFunction(String name, Function func)
          Registers function for the usage in patterns.
 void setGenerator(Generator generator)
          Associates or deassociates this function with text generator.
 Object setVariable(String name, Object var)
          Registers variable for the usage in patterns.
 void txt(String t)
          Processes text pattern and generates text.
 void txtAsIs(String t)
          Print string as is, don't treat it as pattern.
 void txtif(boolean condition, String t)
          if condition is true calls txt(t)
 void txtif(boolean condition, String t, String f)
          if condition is true calls txt(t) else txt(f)
 void txtif(Object object, String t)
          if object is not null calls txt(t)
 void txtif(Object object, String t, String f)
          if object is not null calls txt(t) else txt(f)
abstract  void visit(Node node)
          Process node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

protected TextGeneratorServer server
Constructor Detail

TextGeneratorClient

public TextGeneratorClient()
Method Detail

setGenerator

public void setGenerator(Generator generator)
Associates or deassociates this function with text generator.

Specified by:
setGenerator in interface Function
Parameters:
generator - The specified text generator. If it is not null - associate function with this text generator, otherwise deassociate.

visit

public abstract void visit(Node node)
Process node.

Parameters:
node -

process

public void process(Object arg)
Processes the specified object.

Specified by:
process in interface Function
Parameters:
arg - The specified object.

setFunction

public final Function setFunction(String name,
                                  Function func)
Registers function for the usage in patterns.

Specified by:
setFunction in interface Generator
Parameters:
name - The name of function. Must be valid identifier or empty string.
func - The implementation of function.
Returns:
If function with this name was registered already - return it. Otherwise return null.

getFunction

public final Function getFunction(String name)
Returns function by name.

Specified by:
getFunction in interface Generator
Parameters:
name - The name of function.
Returns:
If function with this name is registered - return it. Otherwise return null.

setVariable

public final Object setVariable(String name,
                                Object var)
Registers variable for the usage in patterns.

Specified by:
setVariable in interface Generator
Parameters:
name - The name of variable. Must be valid identifier or empty string.
var - The value of variable.
Returns:
If variable with this name was registered already - return it. Otherwise return null.

getVariable

public final Object getVariable(String name)
Returns variable by name.

Specified by:
getVariable in interface Generator
Parameters:
name - The name of variable.
Returns:
If variable with this name is registered - return it. Otherwise return null.

txt

public final void txt(String t)
Processes text pattern and generates text. The pattern has parameters of the following form:

pattern ::= "${" ( <func:ID> ":" )? ( "." )? path "}" ;
path ::= attribute ( "." attribute )* ;
attribute ::= <attr_name:ID> ( "[" index "]" )? ;
index ::= <index_var:ID> | number ;
number ::= ( "-" )? ( <digit> )+ ;
The parameter of pattern is processed in the following way:

Specified by:
txt in interface Generator
Parameters:
t - The specified pattern.
See Also:
Generator.getFunction(String), Generator.getVariable(String)

txtAsIs

public final void txtAsIs(String t)
Print string as is, don't treat it as pattern. This method is used for printing values of parameters.

Specified by:
txtAsIs in interface Generator
Parameters:
t - The string to pass as is.

pushNode

public final void pushNode(Node node)
Sets default node for all operations with attributes.

Specified by:
pushNode in interface TextGenerator
Parameters:
node - The new default node.

getNode

public final Node getNode()
Returns current node.

Specified by:
getNode in interface TextGenerator
Returns:
The current node.

popNode

public final void popNode()
Restore previous node.

Specified by:
popNode in interface TextGenerator

pushIndent

public final void pushIndent(int indent)
Makes indent current indent level. The previous indent level can be restored by TextGenerator.popIndent()

Specified by:
pushIndent in interface TextGenerator
Parameters:
indent - the new indent level

getIndent

public final int getIndent()
Returns the current indent level.

Specified by:
getIndent in interface TextGenerator
Returns:
The current indent level.

incIndent

public final void incIndent()
Increases indent level at one indent step. The previous indent level can be restored by TextGenerator.popIndent()

Specified by:
incIndent in interface TextGenerator

decIndent

public final void decIndent()
Decreases indent level at one indent step. The previous indent level can be restored by TextGenerator.popIndent()

Specified by:
decIndent in interface TextGenerator

popIndent

public final void popIndent()
Restores previous indent level.

Specified by:
popIndent in interface TextGenerator
See Also:
TextGenerator.pushIndent(int), TextGenerator.incIndent(), TextGenerator.decIndent()

list

public final void list(String index,
                       int start,
                       int end,
                       String str,
                       String separator)
Prints list of strings.

Specified by:
list in interface TextGenerator
Parameters:
index - The variable name to store current index of list element.
start - The starting value of an index
end - if start < end then
  index is increased by 1 from start to end - 1
if start > end then
  index is decreased by 1 from start - 1 to end
if start == end then
  no actions
str - The string to print for each list element using txt( str )
separator - The separator to print between strings for list elements using txt( str )

nl

public final void nl()
Starts a new line of text.

Specified by:
nl in interface TextGenerator

txtif

public final void txtif(boolean condition,
                        String t)
if condition is true calls txt(t)

Throws:
NullPointerException - if t is null

txtif

public final void txtif(boolean condition,
                        String t,
                        String f)
if condition is true calls txt(t) else txt(f)

Throws:
NullPointerException - if t or f is null

txtif

public final void txtif(Object object,
                        String t)
if object is not null calls txt(t)

Throws:
NullPointerException - if t is null

txtif

public final void txtif(Object object,
                        String t,
                        String f)
if object is not null calls txt(t) else txt(f)

Throws:
NullPointerException - if t is null


Copyright © 2001-2006 ISP RAS, RedVerst Group. All Rights Reserved.