com.unitesk.atp.text.generation
Class BasicGenerator

java.lang.Object
  extended by com.unitesk.atp.text.generation.BasicGenerator
All Implemented Interfaces:
PatternFilter.ParameterProcessor, Generator
Direct Known Subclasses:
TextGeneratorServer

public class BasicGenerator
extends Object
implements Generator, PatternFilter.ParameterProcessor

The basic implementation of Generator interface. Processed text is passed to client text receiver.

Version:
$Id: BasicGenerator.java,v 1.2 2004/10/11 15:51:32 all-x Exp $
Author:
Alexey Demakov

Field Summary
protected  TextReceiver client
           
protected  Map name_to_func
           
protected  Map name_to_var
           
protected  PatternFilter pattern_filter
           
protected  Attributed variable_map
           
 
Fields inherited from interface com.unitesk.atp.text.generation.Generator
DEFAULT_NAME
 
Constructor Summary
BasicGenerator(TextReceiver client)
          Constructs generator with the specified client.
BasicGenerator(TextReceiver client, Function default_func, String par_start, String par_end)
          Constructs generator with the specified parameters.
 
Method Summary
 Function getFunction(String name)
          Returns function by name.
 Object getVariable(String name)
          Returns variable by name.
protected  void mustBeID(String id)
           
 void param(String param)
          Receives pattern parameter (without delimeters)
 Function setFunction(String name, Function func)
          Registers function for the usage in patterns.
 Object setVariable(String name, Object var)
          Registers variable for the usage in patterns.
 void txt(String str)
          Processes text pattern and generates text.
 void txtAsIs(String str)
          Print string as is, don't treat it as pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name_to_func

protected Map name_to_func

name_to_var

protected Map name_to_var

variable_map

protected Attributed variable_map

pattern_filter

protected PatternFilter pattern_filter

client

protected TextReceiver client
Constructor Detail

BasicGenerator

public BasicGenerator(TextReceiver client)
Constructs generator with the specified client.

Parameters:
client - The client text receiver.

BasicGenerator

public BasicGenerator(TextReceiver client,
                      Function default_func,
                      String par_start,
                      String par_end)
Constructs generator with the specified parameters.

Parameters:
client - The client text receiver.
default_func - The default function
par_start - The parameter start delimemter
Throws:
NullPointerException - If client == null
Method Detail

setFunction

public 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 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 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 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 void txt(String str)
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:
str - The specified pattern.
See Also:
Generator.getFunction(String), Generator.getVariable(String)

txtAsIs

public void txtAsIs(String str)
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:
str - The string to pass as is.

param

public void param(String param)
Receives pattern parameter (without delimeters)

Specified by:
param in interface PatternFilter.ParameterProcessor
Parameters:
param - the pattern parameters.

mustBeID

protected void mustBeID(String id)


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