org.extex.interpreter.max.context
Class ContextImpl

java.lang.Object
  extended by org.extex.interpreter.max.context.ContextImpl
All Implemented Interfaces:
java.io.Serializable, DocumentWriterOptions, Configurable, LogEnabled, Context, ContextCode, ContextCount, ContextDimen, ContextErrorCount, ContextFile, ContextFont, ContextGroup, ContextInteraction, ContextInternals, ContextMark, ContextTokens, CodeObservable, ConditionalObservable, CountObservable, DimenObservable, GlueObservable, GroupObservable, InteractionObservable, LoadedObservable, TokensObservable, LanguageManagerCarrier, Tokenizer, TokenStreamOptions, PageContext, TypesetterOptions
Direct Known Subclasses:
ContextExtensionImpl

public class ContextImpl
extends java.lang.Object
implements ContextInternals, CodeObservable, ConditionalObservable, CountObservable, DimenObservable, GlueObservable, GroupObservable, InteractionObservable, LoadedObservable, TokensObservable, Tokenizer, DocumentWriterOptions, TypesetterOptions, TokenStreamOptions, LogEnabled, Configurable, java.io.Serializable

This is a reference implementation for an interpreter context. The groups are implemented as a linked list of single groups. In contrast to the Knuthian implementation in TeX no undo stack is used.

Several operations have to be dealt with:

Version:
$Revision: 4770 $
Author:
Gerd Neugebauer, Michael Niedermair
See Also:
Serialized Form

Field Summary
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
ContextImpl()
          Creates a new object.
 
Method Summary
 void addUnit(UnitInfo info)
          Add a unit to the list of loaded units.
 void afterGroup(AfterGroupObserver observer)
          Register a observer to be called at the end of the group.
 void afterGroup(Token t)
          Add a token to the tokens inserted after the group has been closed.
 void clearSplitMarks()
          This method clears all split marks.
 void closeGroup(Typesetter typesetter, TokenSource source)
          Perform all actions required upon the closing of a group.
 void configure(Configuration configuration)
          Configure an object according to a given Configuration.
 void enableLogging(java.util.logging.Logger logger)
          Setter for the logger.
 java.lang.String esc(java.lang.String name)
          Attach the current escape character in front of a name and return the result.
 java.lang.String esc(Token token)
          This method is meant to produce a printable version of a control sequence for error messages.
 UnicodeChar escapechar()
          Return the current escape character or \0 if it is undefined.
 java.lang.Object get(java.lang.Object extension, java.lang.Object key)
          Getter for a value from an extended section of the context.
 Token getAfterassignment()
          Getter for the after assignment token.
 Tokens getBottomMark(java.lang.Object name)
          Getter for the bottom mark.
 Box getBox(java.lang.String name)
          Getter for the box register.
 Catcode getCatcode(UnicodeChar uc)
          Get the Catcode for a given Unicode character.
 Code getCode(CodeToken t)
          Convenience method to get the code assigned to a Token.
 Conditional getConditional()
          Getter for the currently active conditional.
 Count getCount(java.lang.String name)
          Getter for the count register.
 FixedCount getCountOption(java.lang.String name)
          Getter for a count register.
 MathDelimiter getDelcode(UnicodeChar c)
          Getter for the delimiter code mapping.
 Dimen getDimen(java.lang.String name)
          Get the current value of the dimen register with a given name.
 FixedDimen getDimenOption(java.lang.String name)
          Getter for a dimen register.
 int getErrorCount()
          Getter for the error count.
 Tokens getFirstMark(java.lang.Object name)
          Getter for the first mark.
 Font getFont(java.lang.String name)
          Getter for a current font register.
 CoreFontFactory getFontFactory()
          Getter for the font factory.
 Glue getGlue(java.lang.String name)
          Getter for a glue register.
 FixedGlue getGlueOption(java.lang.String name)
          Getter for a glue register.
protected  Group getGroup()
          Getter for group.
 GroupInfo[] getGroupInfos()
          Getter for the array of group information describing the currently open groups.
 long getGroupLevel()
          Getter for the group level.
 GroupType getGroupType()
          Getter for the group type.
 java.lang.String getId()
          Getter for the id string.
 long getIfLevel()
          Getter for the current if level.
 InFile getInFile(java.lang.String name)
          Getter for a input file register.
 Interaction getInteraction()
          Getter for the interaction.
 Language getLanguage(java.lang.String language)
          Getter for the hyphenation record for a given language.
 LanguageManager getLanguageManager()
          Getter for the language manager.
 UnicodeChar getLccode(UnicodeChar uc)
          Getter for the lccode mapping of upper case characters to their lower case equivalent.
protected  Localizer getLocalizer()
          Getter for localizer.
 long getMagnification()
          Getter for the magnification factor in per mille.
 MathCode getMathcode(UnicodeChar uc)
          Getter for the math code of a character.
 Muskip getMuskip(java.lang.String name)
          Getter for a muskip register.
 java.lang.String getNamespace()
          Getter for the current name space.
 OutFile getOutFile(java.lang.String name)
          Getter for an output file descriptor.
 ParagraphShape getParshape()
          Getter for the parshape.
 FixedCount getSfcode(UnicodeChar uc)
          Getter for the space factor code of a character.
 Tokens getSplitBottomMark(java.lang.Object name)
          Getter for the split bottom mark.
 Tokens getSplitFirstMark(java.lang.Object name)
          Getter for the split first mark.
 TokenStream getStandardTokenStream()
          Getter for standardTokenStream.
 TokenFactory getTokenFactory()
          Getter for the token factory.
 Tokenizer getTokenizer()
          Getter for the tokenizer.
 java.lang.String getTokensOption(java.lang.String name)
          Getter for a token register.
 Tokens getToks(java.lang.String name)
          Getter for the Tokens register.
 FixedTokens getToksOption(java.lang.String name)
          Getter for a tokens register.
 Tokens getToksOrNull(java.lang.String name)
          Getter for the toks register.
 Tokens getTopMark(java.lang.Object name)
          Getter for the top mark.
 TypesettingContext getTypesettingContext()
          Getter for the typesetting context.
 TypesettingContextFactory getTypesettingContextFactory()
          Getter for the typesetting context factory.
 UnicodeChar getUccode(UnicodeChar lc)
          Getter for the uccode mapping of lower case characters to their upper case equivalent.
 int incrementErrorCount()
          Increment the error count by 1.
 boolean isGlobalGroup()
          Test whether this group is the first one, which means that there is no group before and closing this group would fail.
 void openGroup(GroupType type, Locator locator, Token start)
          This method can be used to open another group.
 Conditional popConditional()
          Pop the management information for a conditional from the stack and return it.
 Direction popDirection()
          Pop a direction from the direction stack.
 void pushConditional(Locator locator, boolean isIfThenElse, Code primitive, long branch, boolean neg)
          Put a value onto the conditional stack.
 void pushDirection(Direction dir)
          Push a direction onto the direction stack.
 java.lang.Object readResolve()
          This method maps instances to their normal representations if required.
 void receiveLoad(TokenSource source, Typesetter typesetter)
          Receive a notification about a load event.
 void registerCodeChangeObserver(Token token, CodeObserver observer)
          Register an observer for code change events.
 void registerConditionalObserver(ConditionalObserver observer)
          Register an observer for conditional events.
 void registerCountObserver(java.lang.String name, CountObserver observer)
          Register an observer for count change events.
 void registerDimenObserver(java.lang.String name, DimenObserver observer)
          Register an observer for dimen change events.
 void registerGlueObserver(java.lang.String name, GlueObserver observer)
          Register an observer for glue change events.
 void registerGroupObserver(GroupObserver observer)
          Register an observer for group change events.
 void registerInteractionObserver(InteractionObserver observer)
          Register an observer for interaction mode change events.
 void registerLoadObserver(LoadedObserver observer)
          Register an observer for load events.
 void registerTokensObserver(java.lang.String name, TokensObserver observer)
          Register an observer for tokens change events.
 void set(Color color, boolean global)
          Setter for the color in the current typesetting context.
 void set(Direction direction, boolean global)
          Setter for the direction in the current typesetting context.
 void set(Font font, boolean global)
          Setter for the font in the current typesetting context.
 void set(Language language, boolean global)
          Setter for the language in the current typesetting context.
 void set(java.lang.Object extension, java.lang.Object key, java.lang.Object value, boolean global)
          Setter for a value from an extended section of the context.
 void set(TypesettingContext context, boolean global)
          Setter for the typesetting context in the specified groups.
 void setAfterassignment(Token token)
          Setter for the after assignment token.
 void setBox(java.lang.String name, Box value, boolean global)
          Setter for the box register in the current group.
 void setCatcode(UnicodeChar c, Catcode catcode, boolean global)
          Setter for the catcode of a character in the specified groups.
 void setCode(CodeToken t, Code code, boolean global)
          Setter for the code assigned to a Token.
 void setCount(java.lang.String name, long value, boolean global)
          Setter for the count register in all requested groups.
 void setCountOption(java.lang.String name, long value)
          Setter for a count register.
 void setDelcode(UnicodeChar c, MathDelimiter delimiter, boolean global)
          Setter for the delimiter code mapping.
 void setDimen(java.lang.String name, Dimen value, boolean global)
          Setter for the Dimen register in all requested groups.
 void setDimen(java.lang.String name, long value, boolean global)
          Setter for the Dimen register in all requested groups.
 void setFont(java.lang.String name, Font font, boolean global)
          Setter for font registers.
 void setFontFactory(CoreFontFactory factory)
          Setter for the font factory.
 void setGlue(java.lang.String name, Glue value, boolean global)
          Setter for a glue register.
 void setId(java.lang.String theId)
          Setter for the id string.
 void setInFile(java.lang.String name, InFile file, boolean global)
          Setter for the InFile register in all requested groups.
 void setInteraction(Interaction interaction)
          Setter for the interaction in all requested groups.
 void setLanguageManager(LanguageManager manager)
          Setter for the language manager.
 void setLccode(UnicodeChar uc, UnicodeChar lc, boolean global)
          Declare the translation from an upper case character to a lower case character.
 void setMagnification(long mag, boolean lock)
          Setter for the magnification.
 void setMark(java.lang.Object name, Tokens mark)
          Setter for a mark.
 void setMathcode(UnicodeChar uc, MathCode code, boolean global)
          Setter for the math code of a character
 void setMuskip(java.lang.String name, Muskip value, boolean global)
          Setter for a muskip register.
 void setNamespace(java.lang.String namespace, boolean global)
          Setter for the name space.
 void setOutFile(java.lang.String name, OutFile file, boolean global)
          Setter for a output file descriptor.
 void setParshape(ParagraphShape shape)
          Setter for the paragraph shape.
 void setSfcode(UnicodeChar uc, Count code, boolean global)
          Setter for the space factor code in the specified groups.
 void setSplitMark(java.lang.Object name, Tokens mark)
          Setter for a split mark.
 void setStandardTokenStream(TokenStream standardTokenStream)
          Setter for standardTokenStream.
 void setTokenFactory(TokenFactory factory)
          Setter for the token factory
 void setToks(java.lang.String name, Tokens toks, boolean global)
          Setter for the Tokens register in the specified groups.
 void setUccode(UnicodeChar lc, UnicodeChar uc, boolean global)
          Declare the translation from a lower case character to an upper case character.
 void startMarks()
          This method indicated that a new page is started.
 java.util.Iterator<UnitInfo> unitIterator()
          Get an iterator to enumerate all unit infos.
 void unregisterCodeChangeObserver(Token name, CodeObserver observer)
          Remove a registered observer for code change events.
 void unregisterConditionalObserver(ConditionalObserver observer)
          Remove a registered observer for conditional events.
 void unregisterCountObserver(java.lang.String name, CountObserver observer)
          Remove a registered observer for count change events.
 void unregisterDimenObserver(java.lang.String name, DimenObserver observer)
          Remove a registered observer for dimen change events.
 void unregisterGlueObserver(java.lang.String name, GlueObserver observer)
          Remove a registered observer for glue change events.
 void unregisterGroupObserver(GroupObserver observer)
          Remove a registered observer for group change events.
 void unregisterInteractionObserver(InteractionObserver observer)
          Remove a registered observer for interaction mode change events.
 void unregisterLoadObserver(LoadedObserver observer)
          Remove a registered observer for load events.
 void unregisterTokensChangeObserver(java.lang.String name, TokensObserver observer)
          Remove a registered observer for tokens change events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values
Constructor Detail

ContextImpl

public ContextImpl()
Creates a new object.

Method Detail

addUnit

public void addUnit(UnitInfo info)
Add a unit to the list of loaded units. The units can be notified when the context is loaded from a format.

Specified by:
addUnit in interface Context
Parameters:
info - the info of the unit loaded
See Also:
unitIterator(), Context.addUnit( org.extex.interpreter.unit.UnitInfo)

afterGroup

public void afterGroup(AfterGroupObserver observer)
Register a observer to be called at the end of the group. The end of the group is reached when the group is closed.

Specified by:
afterGroup in interface ContextGroup
Parameters:
observer - the observer to register
See Also:
ContextGroup.afterGroup( AfterGroupObserver)

afterGroup

public void afterGroup(Token t)
Add a token to the tokens inserted after the group has been closed.

Specified by:
afterGroup in interface ContextGroup
Parameters:
t - the token to add
See Also:
ContextGroup.afterGroup( org.extex.scanner.type.token.Token)

clearSplitMarks

public void clearSplitMarks()
This method clears all split marks.

Specified by:
clearSplitMarks in interface ContextMark
See Also:
ContextMark.clearSplitMarks()

closeGroup

public void closeGroup(Typesetter typesetter,
                       TokenSource source)
                throws HelpingException
Perform all actions required upon the closing of a group.

Specified by:
closeGroup in interface ContextGroup
Parameters:
typesetter - the typesetter to invoke if needed
source - the source to get Tokens from if needed
Throws:
HelpingException - in case of an error
See Also:
ContextGroup.closeGroup( org.extex.typesetter.Typesetter, org.extex.interpreter.TokenSource)

configure

public void configure(Configuration configuration)
Configure an object according to a given Configuration.

Specified by:
configure in interface Configurable
Parameters:
configuration - the configuration object to consider
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configurable.configure( org.extex.framework.configuration.Configuration)

enableLogging

public void enableLogging(java.util.logging.Logger logger)
Setter for the logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
logger - the logger to use
See Also:
LogEnabled.enableLogging( java.util.logging.Logger)

esc

public java.lang.String esc(java.lang.String name)
Attach the current escape character in front of a name and return the result. If the escape character is not set then the argument is returned unchanged.

This method is meant to produce a printable version of a control sequence for error messages.

Specified by:
esc in interface Context
Parameters:
name - the name of the macro
Returns:
the control sequence including the escape character
See Also:
Context.esc(java.lang.String)

esc

public java.lang.String esc(Token token)
This method is meant to produce a printable version of a control sequence for error messages.

Specified by:
esc in interface Context
Parameters:
token - the token
Returns:
the control sequence including the escape character
See Also:
Context.esc( org.extex.scanner.type.token.Token)

escapechar

public UnicodeChar escapechar()
Return the current escape character or \0 if it is undefined. The escape character is retrieved from the count register \escapechar.

Specified by:
escapechar in interface Context
Returns:
the escape character
See Also:
Context.escapechar()

get

public java.lang.Object get(java.lang.Object extension,
                            java.lang.Object key)
Description copied from interface: Context
Getter for a value from an extended section of the context.

Specified by:
get in interface Context
Parameters:
extension - the name of the extension
key - the key for the value
Returns:
the value stored
See Also:
Context.get( java.lang.Object, java.lang.Object)

getAfterassignment

public Token getAfterassignment()
Getter for the after assignment token.

Specified by:
getAfterassignment in interface Context
Returns:
the after assignment token
See Also:
Context.getAfterassignment()

getBottomMark

public Tokens getBottomMark(java.lang.Object name)
Getter for the bottom mark.

Specified by:
getBottomMark in interface ContextMark
Parameters:
name - the name of the mark
Returns:
the bottom mark
See Also:
ContextMark.getBottomMark( java.lang.Object)

getBox

public Box getBox(java.lang.String name)
Getter for the box register. Count registers are named, either with a number or an arbitrary string.

Specified by:
getBox in interface Context
Parameters:
name - the name or number of the count register
Returns:
the count register or null if it is void
See Also:
Context.getBox(java.lang.String)

getCatcode

public Catcode getCatcode(UnicodeChar uc)
Get the Catcode for a given Unicode character.

Specified by:
getCatcode in interface Tokenizer
Parameters:
uc - the Unicode character to get the catcode for.
Returns:
the catcode for the character
See Also:
Tokenizer.getCatcode(org.extex.core.UnicodeChar)

getCode

public Code getCode(CodeToken t)
             throws HelpingException
Convenience method to get the code assigned to a Token. If the Token is a ControlSequenceToken then the macro is returned. If the Token is a ActiveCharacterToken then the active value is returned.

Specified by:
getCode in interface ContextCode
Parameters:
t - the Token to differentiate on
Returns:
the code for the token
Throws:
HelpingException - in case of an error
See Also:
ContextCode.getCode( org.extex.scanner.type.token.CodeToken)

getConditional

public Conditional getConditional()
Getter for the currently active conditional.

Specified by:
getConditional in interface Context
Returns:
the currently active conditional or null if none
See Also:
Context.getConditional()

getCount

public Count getCount(java.lang.String name)
Getter for the count register. Count registers are named, either with a number or an arbitrary string.

The return value is guaranteed to be a valid object. null will never be returned.

Specified by:
getCount in interface ContextCount
Parameters:
name - the name or number of the count register
Returns:
the count register or null if it is not defined
See Also:
ContextCount.getCount( java.lang.String)

getCountOption

public FixedCount getCountOption(java.lang.String name)
Getter for a count register.

Specified by:
getCountOption in interface DocumentWriterOptions
Specified by:
getCountOption in interface TokenStreamOptions
Specified by:
getCountOption in interface PageContext
Specified by:
getCountOption in interface TypesetterOptions
Parameters:
name - the name of the register
Returns:
the content of the count register
See Also:
TypesetterOptions.getCountOption( java.lang.String)

getDelcode

public MathDelimiter getDelcode(UnicodeChar c)
Getter for the delimiter code mapping.

Specified by:
getDelcode in interface Context
Parameters:
c - the character to which the delimiter code is assigned
Returns:
the delimiter code for the given character
See Also:
Context.getDelcode( org.extex.core.UnicodeChar)

getDimen

public Dimen getDimen(java.lang.String name)
Get the current value of the dimen register with a given name.

Specified by:
getDimen in interface ContextDimen
Parameters:
name - the name or the number of the register
Returns:
the dimen register for the given name
See Also:
ContextDimen.getDimen( java.lang.String)

getDimenOption

public FixedDimen getDimenOption(java.lang.String name)
Getter for a dimen register.

Specified by:
getDimenOption in interface DocumentWriterOptions
Specified by:
getDimenOption in interface PageContext
Specified by:
getDimenOption in interface TypesetterOptions
Parameters:
name - the name of the register
Returns:
the content of the dimen register
See Also:
TypesetterOptions.getDimenOption( java.lang.String)

getErrorCount

public int getErrorCount()
Description copied from interface: ContextErrorCount
Getter for the error count.

Specified by:
getErrorCount in interface ContextErrorCount
Returns:
the current value of the number of errors
See Also:
ContextErrorCount.getErrorCount()

getFirstMark

public Tokens getFirstMark(java.lang.Object name)
Description copied from interface: ContextMark
Getter for the first mark.

Specified by:
getFirstMark in interface ContextMark
Parameters:
name - the name of the mark
Returns:
the first mark
See Also:
ContextMark.getFirstMark( java.lang.Object)

getFont

public Font getFont(java.lang.String name)
Description copied from interface: ContextFont
Getter for a current font register.

Specified by:
getFont in interface ContextFont
Specified by:
getFont in interface PageContext
Specified by:
getFont in interface TypesetterOptions
Parameters:
name - the name or the number of the register
Returns:
the named font register or null if none is set
See Also:
ContextFont.getFont(java.lang.String)

getFontFactory

public CoreFontFactory getFontFactory()
Description copied from interface: ContextFont
Getter for the font factory.

Specified by:
getFontFactory in interface ContextFont
Returns:
the fontFactory.
See Also:
ContextFont.getFontFactory()

getGlue

public Glue getGlue(java.lang.String name)
Description copied from interface: Context
Getter for a glue register.

Specified by:
getGlue in interface Context
Parameters:
name - the name of the glue register to acquire.
Returns:
the value of the named glue register or null if none is set
See Also:
Context.getGlue(java.lang.String)

getGlueOption

public FixedGlue getGlueOption(java.lang.String name)
Description copied from interface: PageContext
Getter for a glue register.

Specified by:
getGlueOption in interface PageContext
Specified by:
getGlueOption in interface TypesetterOptions
Parameters:
name - the name of the register
Returns:
the content of the glue register
See Also:
TypesetterOptions.getGlueOption(java.lang.String)

getGroup

protected Group getGroup()
Getter for group.

Returns:
the group.

getGroupInfos

public GroupInfo[] getGroupInfos()
Getter for the array of group information describing the currently open groups. The elements represent the groups in ascending order. Thus the element 0 always represents the global group. This one is guaranteed to be present. This means that the arras has always at least one element.

Specified by:
getGroupInfos in interface ContextGroup
Returns:
the array of group infos
See Also:
ContextGroup.getGroupInfos()

getGroupLevel

public long getGroupLevel()
Getter for the group level. The group level is the number of groups which are currently open. Thus this number of groups can be closed.

Specified by:
getGroupLevel in interface ContextGroup
Returns:
the group level
See Also:
ContextGroup.getGroupLevel()

getGroupType

public GroupType getGroupType()
Getter for the group type.

Specified by:
getGroupType in interface ContextGroup
Returns:
the group type
See Also:
ContextGroup.getGroupType()

getId

public java.lang.String getId()
Getter for the id string. The id string is the classification of the original source as given in the format file. The id string can be null if not known yet.

Specified by:
getId in interface Context
Returns:
the id string
See Also:
Context.getId()

getIfLevel

public long getIfLevel()
Getter for the current if level.

Specified by:
getIfLevel in interface Context
Returns:
the current if level
See Also:
Context.getIfLevel()

getInFile

public InFile getInFile(java.lang.String name)
Getter for a input file register. In the case that the named descriptor doe not exist yet a new one is returned. Especially if the name is null then the default input stream is used.

Specified by:
getInF