pmp
Class Macroprocessor

java.lang.Object
  extended by pmp.Macroprocessor
All Implemented Interfaces:
java.util.EventListener, MacroListModifyListener

public class Macroprocessor
extends java.lang.Object
implements MacroListModifyListener

Main class of Macroprocessor.

Title: PMP: Macroprocessor

Description: Java macroprocessor

Copyright: Copyright (c) 2005

Version:
1.0
Author:
Luděk Hlaváček

Nested Class Summary
 class Macroprocessor.Component
           
 
Field Summary
protected  java.util.Locale currentLoc
           
protected  java.lang.String currentLocStr
           
static int DEBUG_EVERY_TOKEN
          Debug level: Print every processed token
static int DEBUG_MACRO_CALLS
          Debug level: Print macro calls
static int DEBUG_MACRO_RESULTS
          Debug level: Print macro call results
static int DEBUG_NODEBUG
          Debug level: No debugging
static int DEBUG_NOTICES
          Debug level: Print notice messages
static java.lang.String DEFAULT_PREFIX
           
protected  MacroList macros
           
protected  Analyzer mpan
           
protected  InputOutput mpio
           
protected  InputQueue mpiq
           
protected  java.lang.String pmpprefix
           
protected  java.util.ArrayList<java.net.URL> urls
          List of libraries with macro class files.
 
Constructor Summary
Macroprocessor()
           
 
Method Summary
 void assignIO(InputOutput io)
          Assigns InputOutput class to macroprocessor.
 void debug(java.lang.Object message, int level)
           
 void error(java.lang.String msg)
          Produces fatal error.
 int getDebugLevel()
          Get current level of debugging output.
 java.util.Locale getLocale()
           
 Macroprocessor getMP()
           
 Analyzer getMPAnalyzer()
           
 InputOutput getMPIO()
           
 InputQueue getMPIQ()
           
 MacroList getMPMacros()
           
 java.lang.String getPrefix()
          Returns prefix of configuration directives.
 void importLibrary(java.lang.String name)
          Adds given library to library list.
 boolean isReady()
          Returns true if macroprocessor is ready.
 AbstractMacro loadFromClass(java.lang.String className)
          Loads macro class.
 void macroListModified(MacroListModifyEvent event)
          Method invoked on event.
 void notice(java.lang.String msg)
          Produces notice message.
 void parse()
          Starts macroprocessor.
 void reset()
          Resets macroprocessor.
 java.lang.String runMacro(CallStackItem item)
          Invokes macro's AbstractMacro.run(Macroprocessor,String[]) method and returns result.
 void setDebugLevel(int level)
          Sets new debugging level.
 boolean setDebugLevel(java.lang.String level)
          Sets debugging level according to given string.
 java.lang.String setPrefix(java.lang.String newprefix)
          Changes prefix of configuration directives.
 void warning(java.lang.String msg)
          Produces warning message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

macros

protected MacroList macros

mpio

protected InputOutput mpio

mpiq

protected InputQueue mpiq

mpan

protected Analyzer mpan

DEFAULT_PREFIX

public static final java.lang.String DEFAULT_PREFIX
See Also:
Constant Field Values

pmpprefix

protected java.lang.String pmpprefix

DEBUG_NODEBUG

public static final int DEBUG_NODEBUG
Debug level: No debugging

See Also:
Constant Field Values

DEBUG_NOTICES

public static final int DEBUG_NOTICES
Debug level: Print notice messages

See Also:
Constant Field Values

DEBUG_MACRO_CALLS

public static final int DEBUG_MACRO_CALLS
Debug level: Print macro calls

See Also:
Constant Field Values

DEBUG_MACRO_RESULTS

public static final int DEBUG_MACRO_RESULTS
Debug level: Print macro call results

See Also:
Constant Field Values

DEBUG_EVERY_TOKEN

public static final int DEBUG_EVERY_TOKEN
Debug level: Print every processed token

See Also:
Constant Field Values

currentLoc

protected java.util.Locale currentLoc

currentLocStr

protected java.lang.String currentLocStr

urls

protected java.util.ArrayList<java.net.URL> urls
List of libraries with macro class files.

Constructor Detail

Macroprocessor

public Macroprocessor()
Method Detail

macroListModified

public void macroListModified(MacroListModifyEvent event)
Description copied from interface: MacroListModifyListener
Method invoked on event.

Specified by:
macroListModified in interface MacroListModifyListener

assignIO

public void assignIO(InputOutput io)
Assigns InputOutput class to macroprocessor.

This should be done as soon as possible since it is the only way MP can provide any feedback.

Parameters:
io - InputOutput class

isReady

public boolean isReady()
Returns true if macroprocessor is ready. This method doesn't check whether InputQueue is not empty.

Returns:
true if it is safe to call parse().

reset

public void reset()
Resets macroprocessor.


parse

public void parse()
           throws FatalParserException,
                  InternalMPError
Starts macroprocessor.

Throws:
FatalParserException - when something fails and it is impossible to continue
InternalMPError - when internal error has occured
FatalParserException - when parsing error has occurs

getMP

public final Macroprocessor getMP()

getMPIO

public final InputOutput getMPIO()

getMPIQ

public final InputQueue getMPIQ()

getMPAnalyzer

public final Analyzer getMPAnalyzer()

getMPMacros

public final MacroList getMPMacros()

getPrefix

public final java.lang.String getPrefix()
Returns prefix of configuration directives.

Returns:
current prefix of configuration directives
See Also:
ConfigDirectives

setPrefix

public final java.lang.String setPrefix(java.lang.String newprefix)
Changes prefix of configuration directives.

Parameters:
newprefix - new prefix for configuration directives
Returns:
previous prefix
See Also:
ConfigDirectives

getDebugLevel

public final int getDebugLevel()
Get current level of debugging output.

Returns:
debug level

setDebugLevel

public final void setDebugLevel(int level)
Sets new debugging level.

Parameters:
level - level of debugging

setDebugLevel

public final boolean setDebugLevel(java.lang.String level)
Sets debugging level according to given string. This mathod accepts names of constants and decimal integer values.

Parameters:
level - desired level as String
Returns:
true if level parameter contains valid value

debug

public void debug(java.lang.Object message,
                  int level)

getLocale

public java.util.Locale getLocale()

runMacro

public java.lang.String runMacro(CallStackItem item)
Invokes macro's AbstractMacro.run(Macroprocessor,String[]) method and returns result.

Parameters:
item - object describing macro-call
Returns:
result of macro execution

importLibrary

public void importLibrary(java.lang.String name)
Adds given library to library list.

Parameters:
name - name of library

loadFromClass

public AbstractMacro loadFromClass(java.lang.String className)
Loads macro class. Given class name must be subclass of AbstractMacro. If something fails, warning is produced.

Parameters:
className - name of class
Returns:
null if loading fails, otherwise instance of loaded class.
See Also:
warning(String)

error

public final void error(java.lang.String msg)
Produces fatal error. Config directive ConfigDirectives.LAST_ERROR is updated and given message is sent to InputOutput object of this macroprocessor. This method terminates macroprocessor by throwing FatalParserException.

Parameters:
msg - message text
See Also:
InputOutput.errorHandler(String)

warning

public final void warning(java.lang.String msg)
Produces warning message. Config directive ConfigDirectives.LAST_WARNING is updated and given message is sent to InputOutput object of this macroprocessor.

Parameters:
msg - message text
See Also:
InputOutput.warningHandler(String)

notice

public final void notice(java.lang.String msg)
Produces notice message. Config directive ConfigDirectives.LAST_NOTICE is updated and given message is sent to InputOutput object of this macroprocessor.

Parameters:
msg - message text
See Also:
InputOutput.noticeHandler(String)