org.ujac.util.template
Class TemplateToken

java.lang.Object
  extended by org.ujac.util.template.TemplateToken
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AssertToken, CallprocToken, DefineToken, ExpressionToken, LogToken, StaticToken, TemplateTokenContainer

public abstract class TemplateToken
extends Object
implements Serializable, Cloneable

Name: TemplateToken
Description: A base class for template tokens.

Author:
lauerc
See Also:
Serialized Form

Field Summary
protected  BaseTemplateInterpreter interpreter
          The template interpreter.
protected  int nextLegalAncestor
          The next legal ancestor idx.
protected  TemplateTokenContainer parent
          The parent token.
protected  int position
          The position of the statement token in the expression.
protected  char[] source
          The source code.
 
Constructor Summary
TemplateToken()
          Constructs a TemplateToken instance with no specific attributes.
TemplateToken(char[] source, int position, int length)
          Constructs a TemplateToken instance with specific attributes.
 
Method Summary
 boolean checkContainer(TemplateTokenContainer container)
          Checks whether this token is valid for the given container.
protected abstract  TemplateToken cloneToken(BaseTemplateInterpreter interpreter, TemplateTokenContainer parent)
          Clones the token for caching reasons.
abstract  void execute(Writer writer, TemplateContext ctx)
          Excecutes the statement token.
 TokenAncestor[] getAncestorRules()
          Gets the ancestor rules for this template.
protected  String getArgumentsAsString()
          Gets the argument list as string.
 int getEndPosition()
          Gets the end position of the statement token in the expression.
protected  String getIndention()
          Gets the indention for prettier output.
 int getLength()
          Gets the length of the statement token.
 int getLevel()
          Getter method for the the property level.
 TemplateTokenContainer getParent()
          Getter method for the the property parent.
 int getPosition()
          Gets the position of the statement token in the expression.
 char[] getSource()
          Gets the source code.
 String getTokenName()
          Gets the token name.
 void initialize(BaseTemplateInterpreter interpreter, char[] source, int position, int length)
          Initializes the token.
 boolean isBodyToken()
          Tells whether or this token has a body.
 boolean isLegalAncestor(String token)
          Tells whether or the given token is a legal ancestor.
 boolean isLegalAncestor(TemplateToken token)
          Tells whether or the given token is a legal ancestor.
 int parseArguments()
          Parses the arguments of the token.
protected  int parseArguments(int offset)
          Parses the arguments of the token.
abstract  void setArgument(Operand argument, int idx)
          Sets an argument.
protected  void setLength(int length)
          Setter method for the the property length.
 void setLevel(int level)
          Setter method for the the property level.
 void setParent(TemplateTokenContainer parent)
          Setter method for the the property parent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

interpreter

protected BaseTemplateInterpreter interpreter
The template interpreter.


parent

protected TemplateTokenContainer parent
The parent token.


source

protected char[] source
The source code.


position

protected int position
The position of the statement token in the expression.


nextLegalAncestor

protected int nextLegalAncestor
The next legal ancestor idx.

Constructor Detail

TemplateToken

public TemplateToken()
Constructs a TemplateToken instance with no specific attributes.


TemplateToken

public TemplateToken(char[] source,
                     int position,
                     int length)
Constructs a TemplateToken instance with specific attributes.

Parameters:
source - The source code.
position - The statement's position in the source code.
length - The statement length.
Method Detail

getTokenName

public String getTokenName()
Gets the token name.

Returns:
The token name.

getAncestorRules

public TokenAncestor[] getAncestorRules()
Gets the ancestor rules for this template.

Returns:
An array of template ancestors.

checkContainer

public boolean checkContainer(TemplateTokenContainer container)
Checks whether this token is valid for the given container.

Parameters:
container - The container that wants to add the token.
Returns:
true if the token may be added to the container, else false.

getParent

public TemplateTokenContainer getParent()
Getter method for the the property parent.

Returns:
The current value of property parent.

setParent

public void setParent(TemplateTokenContainer parent)
Setter method for the the property parent.

Parameters:
parent - The value to set for the property parent.

getLevel

public int getLevel()
Getter method for the the property level.

Returns:
The current value of property level.

setLevel

public void setLevel(int level)
Setter method for the the property level.

Parameters:
level - The value to set for the property level.

isBodyToken

public boolean isBodyToken()
Tells whether or this token has a body.

Returns:
true if the token has a body, else false.

isLegalAncestor

public boolean isLegalAncestor(String token)
Tells whether or the given token is a legal ancestor.

Parameters:
token - The token to test.
Returns:
true if the token is a legal ancestor, else false.

isLegalAncestor

public boolean isLegalAncestor(TemplateToken token)
Tells whether or the given token is a legal ancestor.

Parameters:
token - The token to test.
Returns:
true if the token is a legal ancestor, else false.

parseArguments

public int parseArguments()
                   throws ExpressionException
Parses the arguments of the token.

Returns:
The position after the argument list.
Throws:
ExpressionException - In case the argument parsing failed.

parseArguments

protected int parseArguments(int offset)
                      throws ExpressionException
Parses the arguments of the token.

Parameters:
offset - The position fron which to parse the source.
Returns:
The position after the argument list.
Throws:
ExpressionException - In case the argument parsing failed.

initialize

public void initialize(BaseTemplateInterpreter interpreter,
                       char[] source,
                       int position,
                       int length)
                throws TemplateException
Initializes the token.

Parameters:
interpreter - The template interpreter.
source - The source code.
position - The start position.
length - The length of the interresting area.
Throws:
TemplateException - In case the initialization failed.

getSource

public char[] getSource()
Gets the source code.

Returns:
The source code.

getLength

public int getLength()
Gets the length of the statement token.

Returns:
The length of the statement token.

setLength

protected void setLength(int length)
Setter method for the the property length.

Parameters:
length - The value to set for the property length.

getPosition

public int getPosition()
Gets the position of the statement token in the expression.

Returns:
The position of the statement token.

getEndPosition

public int getEndPosition()
Gets the end position of the statement token in the expression.

Returns:
The end position of the statement token.

execute

public abstract void execute(Writer writer,
                             TemplateContext ctx)
                      throws TemplateException,
                             IOException
Excecutes the statement token.

Parameters:
writer - The writer to write to.
ctx - The template context.
Throws:
TemplateException - If the token could not be successfuly executed.
IOException - In case an output failure occurred.

setArgument

public abstract void setArgument(Operand argument,
                                 int idx)
                          throws StatementException
Sets an argument.

Parameters:
argument - The argument to set.
idx - The argument index.
Throws:
StatementException - In case the given argument is not valid.

getIndention

protected String getIndention()
Gets the indention for prettier output.

Returns:
The indention text.

getArgumentsAsString

protected String getArgumentsAsString()
Gets the argument list as string.

Returns:
The arguements as a comma separated text.

cloneToken

protected abstract TemplateToken cloneToken(BaseTemplateInterpreter interpreter,
                                            TemplateTokenContainer parent)
Clones the token for caching reasons.

Parameters:
interpreter - The interpreter to use.
parent - The actual parent in the cloned object tree.
Returns:
The clone.


Copyright © 2003-2004 UJAC.org. All Rights Reserved.