de.dante.extex.scanner.type.token
Class TokenFactoryImpl

java.lang.Object
  extended byde.dante.extex.scanner.type.token.TokenFactoryImpl
All Implemented Interfaces:
CatcodeVisitor, TokenFactory

public class TokenFactoryImpl
extends java.lang.Object
implements TokenFactory, CatcodeVisitor

This is a implementation of a token factory. This means that the factory pattern is applied here. This pattern opens the possibility to cache the instances for Tokens to reduce the number of objects present in the system.

The Visitor Pattern

In addition the visitor pattern is used to select the appropriate instantiation method. The visit methods are not meant to be used externally. They are purely internal. Despite their general definition the visit methods are in fact used in the following way:

  Token visit*(String value, UnicodeChar character) throws CatcodeException
 

This means that they are expected to return the new token. The first argument is the value, which is mainly meaningful for control sequence tokens. The third argument contains the Unicode character for single letter tokens.

Version:
$Revision: 1.5 $
Author:
Gerd Neugebauer

Constructor Summary
TokenFactoryImpl()
          Creates a new object.
 
Method Summary
 Token createToken(Catcode code, int c, java.lang.String namespace)
          Create a new Token of the appropriate kind.
 Token createToken(Catcode code, UnicodeChar c, java.lang.String namespace)
          Get an instance of a token with a given Catcode and Unicode character value.
 Token createToken(Catcode code, UnicodeChar esc, java.lang.String value, java.lang.String namespace)
          Get an instance of a token with a given Catcode and value.
 java.lang.Object visitActive(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object oNamespace)
          Active characters are cached.
 java.lang.Object visitComment(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          Comments are ignored thus null is returned in any case.
 java.lang.Object visitCr(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          There is only one CrToken.
 java.lang.Object visitEscape(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object oNamespace)
          This visit method is invoked on an escape token.
 java.lang.Object visitIgnore(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          Ignored characters are simply ignored;-)
 java.lang.Object visitInvalid(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          Invalid characters are ignored; even without any error message.
 java.lang.Object visitLeftBrace(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          A left brace token is expected to take a single character only.
 java.lang.Object visitLetter(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          A letter token is expected to take a single character only.
 java.lang.Object visitMacroParam(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          This visit method is invoked on a macro parameter token.
 java.lang.Object visitMathShift(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          This visit method is invoked on a math shift token.
 java.lang.Object visitOther(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          This visit method is invoked on an other token.
 java.lang.Object visitRightBrace(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          This visit method is invoked on a right brace token.
 java.lang.Object visitSpace(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          There is only one space token.
 java.lang.Object visitSubMark(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          This visit method is invoked on a sub mark token.
 java.lang.Object visitSupMark(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          This visit method is invoked on a sup mark token.
 java.lang.Object visitTabMark(java.lang.Object oValue, java.lang.Object oChar, java.lang.Object ignore)
          This visit method is invoked on a tab mark token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TokenFactoryImpl

public TokenFactoryImpl()
Creates a new object.

Method Detail

createToken

public Token createToken(Catcode code,
                         int c,
                         java.lang.String namespace)
                  throws CatcodeException
Description copied from interface: TokenFactory
Create a new Token of the appropriate kind. Tokens are immutable (no setters) thus the factory pattern can be applied.

Specified by:
createToken in interface TokenFactory
Parameters:
code - the category code
c - the character value
namespace - the name space to use
Returns:
the new token
Throws:
CatcodeException - in case of an error
See Also:
TokenFactory.createToken( de.dante.extex.scanner.type.Catcode, int, java.lang.String)

createToken

public Token createToken(Catcode code,
                         UnicodeChar esc,
                         java.lang.String value,
                         java.lang.String namespace)
                  throws CatcodeException
Description copied from interface: TokenFactory
Get an instance of a token with a given Catcode and value.

Specified by:
createToken in interface TokenFactory
Parameters:
code - the catcode
esc - the Unicode character value of the escape character
value - the value
namespace - the name space for the token. This is relevant for ACTIVE and ESCAPE catcodes only.
Returns:
the appropriate token
Throws:
CatcodeException - in case of an error
See Also:
TokenFactory.createToken( de.dante.extex.scanner.type.Catcode, de.dante.util.UnicodeChar, java.lang.String, java.lang.String)

createToken

public Token createToken(Catcode code,
                         UnicodeChar c,
                         java.lang.String namespace)
                  throws CatcodeException
Description copied from interface: TokenFactory
Get an instance of a token with a given Catcode and Unicode character value.

Specified by:
createToken in interface TokenFactory
Parameters:
code - the catcode
c - the Unicode character value
namespace - the name space for the token. This is relevant for ACTIVE and ESCAPE catcodes only.
Returns:
the appropriate token
Throws:
CatcodeException - in case of an error
See Also:
TokenFactory.createToken( de.dante.extex.scanner.type.Catcode, de.dante.util.UnicodeChar, java.lang.String)

visitActive

public java.lang.Object visitActive(java.lang.Object oValue,
                                    java.lang.Object oChar,
                                    java.lang.Object oNamespace)
                             throws CatcodeException
Active characters are cached. Thus a lookup in the cache precedes the creation of a new token.

Specified by:
visitActive in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
oNamespace - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitActive( java.lang.Object, java.lang.Object, java.lang.Object)

visitComment

public java.lang.Object visitComment(java.lang.Object oValue,
                                     java.lang.Object oChar,
                                     java.lang.Object ignore)
Comments are ignored thus null is returned in any case.

Specified by:
visitComment in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
See Also:
CatcodeVisitor.visitComment( java.lang.Object, java.lang.Object, java.lang.Object)

visitCr

public java.lang.Object visitCr(java.lang.Object oValue,
                                java.lang.Object oChar,
                                java.lang.Object ignore)
There is only one CrToken.

Specified by:
visitCr in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
See Also:
CatcodeVisitor.visitCr(java.lang.Object, java.lang.Object, java.lang.Object)

visitEscape

public java.lang.Object visitEscape(java.lang.Object oValue,
                                    java.lang.Object oChar,
                                    java.lang.Object oNamespace)
                             throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on an escape token. In TeX this normally means a control sequence.

Specified by:
visitEscape in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
oNamespace - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitEscape( java.lang.Object, java.lang.Object, java.lang.Object)

visitIgnore

public java.lang.Object visitIgnore(java.lang.Object oValue,
                                    java.lang.Object oChar,
                                    java.lang.Object ignore)
Ignored characters are simply ignored;-)

Specified by:
visitIgnore in interface CatcodeVisitor
Parameters:
oValue - the string value token or null
oChar - the requested character code
ignore - the third argument is ignored
Returns:
null
See Also:
CatcodeVisitor.visitIgnore( java.lang.Object, java.lang.Object, java.lang.Object)

visitInvalid

public java.lang.Object visitInvalid(java.lang.Object oValue,
                                     java.lang.Object oChar,
                                     java.lang.Object ignore)
Invalid characters are ignored; even without any error message.

Specified by:
visitInvalid in interface CatcodeVisitor
Parameters:
oValue - the string value token or null
oChar - the requested character code
ignore - the third argument is ignored
Returns:
null
See Also:
CatcodeVisitor.visitInvalid( java.lang.Object, java.lang.Object, java.lang.Object)

visitLeftBrace

public java.lang.Object visitLeftBrace(java.lang.Object oValue,
                                       java.lang.Object oChar,
                                       java.lang.Object ignore)
                                throws CatcodeException
A left brace token is expected to take a single character only.

Specified by:
visitLeftBrace in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitLeftBrace( java.lang.Object, java.lang.Object, java.lang.Object)

visitLetter

public java.lang.Object visitLetter(java.lang.Object oValue,
                                    java.lang.Object oChar,
                                    java.lang.Object ignore)
                             throws CatcodeException
A letter token is expected to take a single character only.

Specified by:
visitLetter in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitLetter( java.lang.Object, java.lang.Object, java.lang.Object)

visitMacroParam

public java.lang.Object visitMacroParam(java.lang.Object oValue,
                                        java.lang.Object oChar,
                                        java.lang.Object ignore)
                                 throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on a macro parameter token. In TeX this normally is a #.

Specified by:
visitMacroParam in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitMacroParam( java.lang.Object, java.lang.Object, java.lang.Object)

visitMathShift

public java.lang.Object visitMathShift(java.lang.Object oValue,
                                       java.lang.Object oChar,
                                       java.lang.Object ignore)
                                throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on a math shift token. In TeX this normally is a $.

Specified by:
visitMathShift in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitMathShift( java.lang.Object, java.lang.Object, java.lang.Object)

visitOther

public java.lang.Object visitOther(java.lang.Object oValue,
                                   java.lang.Object oChar,
                                   java.lang.Object ignore)
                            throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on an other token.

Specified by:
visitOther in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitOther( java.lang.Object, java.lang.Object, java.lang.Object)

visitRightBrace

public java.lang.Object visitRightBrace(java.lang.Object oValue,
                                        java.lang.Object oChar,
                                        java.lang.Object ignore)
                                 throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on a right brace token.

Specified by:
visitRightBrace in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitRightBrace( java.lang.Object, java.lang.Object, java.lang.Object)

visitSpace

public java.lang.Object visitSpace(java.lang.Object oValue,
                                   java.lang.Object oChar,
                                   java.lang.Object ignore)
There is only one space token. It has the character code 32.

Specified by:
visitSpace in interface CatcodeVisitor
Parameters:
oValue - the string value token or null
oChar - the requested character code
ignore - the third argument is ignored
Returns:
the space token.
See Also:
CatcodeVisitor.visitSpace( java.lang.Object, java.lang.Object, java.lang.Object), "The TeXbook [Chapter 8, p. 47]"

visitSubMark

public java.lang.Object visitSubMark(java.lang.Object oValue,
                                     java.lang.Object oChar,
                                     java.lang.Object ignore)
                              throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on a sub mark token. In TeX this normally is a _.

Specified by:
visitSubMark in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitSubMark( java.lang.Object, java.lang.Object, java.lang.Object)

visitSupMark

public java.lang.Object visitSupMark(java.lang.Object oValue,
                                     java.lang.Object oChar,
                                     java.lang.Object ignore)
                              throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on a sup mark token. In TeX this normally is a ^.

Specified by:
visitSupMark in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitSupMark( java.lang.Object, java.lang.Object, java.lang.Object)

visitTabMark

public java.lang.Object visitTabMark(java.lang.Object oValue,
                                     java.lang.Object oChar,
                                     java.lang.Object ignore)
                              throws CatcodeException
Description copied from interface: CatcodeVisitor
This visit method is invoked on a tab mark token. In TeX this normally is a &.

Specified by:
visitTabMark in interface CatcodeVisitor
Parameters:
oValue - the first argument to pass
oChar - the second argument to pass
ignore - the third argument to pass
Returns:
some value
Throws:
CatcodeException
See Also:
CatcodeVisitor.visitTabMark( java.lang.Object, java.lang.Object, java.lang.Object)