pmp
Class MacroList

java.lang.Object
  extended by pmp.Macroprocessor.Component
      extended by pmp.MacroList

public class MacroList
extends Macroprocessor.Component

Maintains list of macros.

Title: PMP: Macroprocessor

Description: Java macroprocessor

Copyright: Copyright (c) 2005

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

Field Summary
protected  java.util.Map<java.lang.String,MacroListItem> macros
          list of macros
protected  java.util.List<MacroListModifyListener> modifyListeners
          list of listeners for macro changes
 
Constructor Summary
MacroList(Macroprocessor mp)
           
 
Method Summary
 boolean addAll(java.util.Map<java.lang.String,AbstractMacro> m)
          Add all macros from given Map to this MacroList.
 void addModifyListener(MacroListModifyListener listener)
          Adds new listener for macro list modification events.
 void clear(boolean all)
          Removes all macro definitions.
 boolean copyMacro(java.lang.String srcName, java.lang.String destName)
          Copies macro.
 java.lang.String forName(java.lang.String var)
          Returns name of configuration directive for given name.
 java.lang.String forName(java.lang.String var, java.lang.String id)
          Returns name of configuration directive for given template and id.
 java.util.Map<java.lang.String,AbstractMacro> getAll()
          Returns map with all defined macros.
 boolean getBool(java.lang.String directive)
          Returns boolean value associated with given directive name.
 boolean getBool(java.lang.String template, java.lang.String id)
          Returns boolean value associated with given directive name.
 java.lang.String[] getIDsByMask(java.lang.String mask)
          Returns array of indices for given mask.
 int getInt(java.lang.String directive)
          Returns integer value associated with given directive name.
 int getInt(java.lang.String template, java.lang.String id)
          Returns integer value associated with given directive name.
 AbstractMacro getMacro(java.lang.String macroName)
          Returns macro object assicated with given name.
 AbstractMacro getMacroCI(java.lang.String macroName)
          Returns macro object assicated with given name.
 java.lang.String[] getMacroNames()
          Returns array of macro names.
 java.lang.String getString(java.lang.String directive)
          Returns configuration directive as string value.
 java.lang.String getString(java.lang.String directive_template, java.lang.String id)
          Returns configuration directive as string value.
 java.lang.String getStringL(java.lang.String directive)
          Returns result of getString(String) after being converted to lower-case.
 java.lang.String getStringL(java.lang.String directive_template, java.lang.String id)
          Returns result of getString(String) after being converted to lower-case.
 boolean isDefined(java.lang.String macroName)
          Returns true if macro with specified name exists.
 boolean isDirectiveDefined(java.lang.String directive)
          Returns true when specified directive is defined.
 boolean isDirectiveDefined(java.lang.String template, java.lang.String id)
          Returns true when specified directive is defined.
 boolean isReadOnly(java.lang.String macroName)
          Returns true if macro is marked as read-only.
 java.util.Iterator<java.lang.String> macroIterator()
          Returns read-only iterator over macro names.
 AbstractMacro popMacro(java.lang.String macroName)
          Restores previous macro definition and returns previous one.
 void pushMacro(java.lang.String macroName, AbstractMacro macro)
          Replaces current macro definition with new one and stores previous one to definition stack.
 void removeModifyListeners()
          Removes all listeners.
 AbstractMacro setMacro(java.lang.String macroName, AbstractMacro macro)
          Defines macro.
 AbstractMacro setMacro(java.lang.String macroName, java.lang.String macro)
          Adds new user-defined macro.
 AbstractMacro setMacroForName(java.lang.String directive, AbstractMacro macro)
          Defines macro.
 AbstractMacro setMacroForName(java.lang.String directive, java.lang.String macro)
          Defines macro.
 AbstractMacro unsetMacro(java.lang.String macroName)
          Removes macro definition by calling setMacro(String,AbstractMacro) for given macroName with null as macro definition.
 
Methods inherited from class pmp.Macroprocessor.Component
error, getMP, getMPAnalyzer, getMPIO, getMPIQ, getMPMacros, notice, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

macros

protected java.util.Map<java.lang.String,MacroListItem> macros
list of macros


modifyListeners

protected java.util.List<MacroListModifyListener> modifyListeners
list of listeners for macro changes

Constructor Detail

MacroList

public MacroList(Macroprocessor mp)
Method Detail

addModifyListener

public void addModifyListener(MacroListModifyListener listener)
Adds new listener for macro list modification events.

Parameters:
listener - new listener

removeModifyListeners

public void removeModifyListeners()
Removes all listeners.


getMacro

public AbstractMacro getMacro(java.lang.String macroName)
Returns macro object assicated with given name.

Parameters:
macroName - name of macro
Returns:
macro object

getMacroCI

public AbstractMacro getMacroCI(java.lang.String macroName)
Returns macro object assicated with given name. This method performs case-insensitive search, which takes much more, so it should be used only when absolutely necessary.

Parameters:
macroName - name of macro
Returns:
macro object

clear

public void clear(boolean all)
Removes all macro definitions.

Parameters:
all - if true read-only macros will be removed as well

unsetMacro

public AbstractMacro unsetMacro(java.lang.String macroName)
Removes macro definition by calling setMacro(String,AbstractMacro) for given macroName with null as macro definition.

Parameters:
macroName - name of macro to be removed
Returns:
last definition of macro

copyMacro

public boolean copyMacro(java.lang.String srcName,
                         java.lang.String destName)
Copies macro. New macro is identical and independent from the original one.

Prints warning on failure (read-only macro or missing source macro).

Parameters:
srcName - source macro
destName - destination name
Returns:
true if everything is ok

setMacro

public AbstractMacro setMacro(java.lang.String macroName,
                              java.lang.String macro)
Adds new user-defined macro. Replaces old definition with new one and clears definition stack. This method creates new DefinedMacro class and calls setMacro(String,AbstractMacro)

Parameters:
macroName - name of macro
macro - definition of macro
Returns:
returns previous definition
See Also:
setMacro(String,AbstractMacro)

setMacro

public AbstractMacro setMacro(java.lang.String macroName,
                              AbstractMacro macro)
Defines macro. Replaces old definition with new one and clears definition stack.

Parameters:
macroName - name of macro
macro - definition of macro
Returns:
returns previous definition

addAll

public boolean addAll(java.util.Map<java.lang.String,AbstractMacro> m)
Add all macros from given Map to this MacroList.

Parameters:
m - Map with macro definitions
Returns:
always true

getAll

public java.util.Map<java.lang.String,AbstractMacro> getAll()
Returns map with all defined macros.

Returns:
Map with macros

pushMacro

public void pushMacro(java.lang.String macroName,
                      AbstractMacro macro)
Replaces current macro definition with new one and stores previous one to definition stack.

Parameters:
macroName - name of macro
macro - new definition

popMacro

public AbstractMacro popMacro(java.lang.String macroName)
Restores previous macro definition and returns previous one.

Parameters:
macroName - name of macro
Returns:
previous macro definition

isDirectiveDefined

public boolean isDirectiveDefined(java.lang.String directive)
Returns true when specified directive is defined.

Parameters:
directive - name of directive (without prefix)
Returns:
true if is defined

isDirectiveDefined

public boolean isDirectiveDefined(java.lang.String template,
                                  java.lang.String id)
Returns true when specified directive is defined.

Parameters:
template - template for name of directive (without prefix)
id - identifier of directive
Returns:
true if is defined

isDefined

public boolean isDefined(java.lang.String macroName)
Returns true if macro with specified name exists.

Parameters:
macroName - nema of macro
Returns:
true if macro exists

isReadOnly

public boolean isReadOnly(java.lang.String macroName)
Returns true if macro is marked as read-only. If macro doesn't exists, false is returned.

Parameters:
macroName - name of macro
Returns:
true if macro exists and is marked as read-only.

forName

public java.lang.String forName(java.lang.String var)
Returns name of configuration directive for given name.

Parameters:
var - name of directive name (typicaly obained from static field of ConfigDirectives class)
Returns:
full directive name (including prefix)

forName

public java.lang.String forName(java.lang.String var,
                                java.lang.String id)
Returns name of configuration directive for given template and id.

Parameters:
var - template for directive name (typically obained from static field of ConfigDirectives class)
id - identifier
Returns:
full directive name (including prefix) after replacing "*" with id

setMacroForName

public AbstractMacro setMacroForName(java.lang.String directive,
                                     AbstractMacro macro)
Defines macro. Its name is created from directive with prependef prefix.

Parameters:
directive - Name of configuration directive
macro - macro object
Returns:
previous macro definition as returned by setMacro(String, AbstractMacro)
See Also:
setMacro(String, String), forName(String)

setMacroForName

public AbstractMacro setMacroForName(java.lang.String directive,
                                     java.lang.String macro)
Defines macro. Its name is created from directive with prependef prefix.

Parameters:
directive - Name of configuration directive
macro - macro definition
Returns:
previous macro definition as returned by setMacro(String, String)
See Also:
setMacro(String, String), forName(String)

getString

public java.lang.String getString(java.lang.String directive)
Returns configuration directive as string value. This method prepends prefix using forName(String).

Return value is obtained by calling macro's toString method

Returns "" when given directive is not defined.

Parameters:
directive - name of configuration directive
Returns:
value of configuration directive
See Also:
AbstractMacro.toString()

getString

public java.lang.String getString(java.lang.String directive_template,
                                  java.lang.String id)
Returns configuration directive as string value. This method prepends prefix using forName(String,String).

Returns "" when given directive is not defined.

Parameters:
directive_template - template for name of configuration directive
id - identifier part of configuration directive
Returns:
value of configuration directive

getStringL

public java.lang.String getStringL(java.lang.String directive)
Returns result of getString(String) after being converted to lower-case.

Parameters:
directive - name of configuration directive
Returns:
lower-cased value of configuration directive

getStringL

public java.lang.String getStringL(java.lang.String directive_template,
                                   java.lang.String id)
Returns result of getString(String) after being converted to lower-case.

Parameters:
directive_template - temlate for name of configuration directive
id - identifier of configuration directive
Returns:
lower-cased value of configuration directive

getBool

public boolean getBool(java.lang.String directive)
Returns boolean value associated with given directive name. Any non-empty string is considered as true except strings: "off", "false", "no", "0" (case-insensitively)

Parameters:
directive - name of configuration directive
Returns:
boolean value of given directive

getBool

public boolean getBool(java.lang.String template,
                       java.lang.String id)
Returns boolean value associated with given directive name. Any non-empty string is considered as true except strings: "off", "false", "no", "0" (case-insensitively)

Parameters:
template - tempate for name of configuration directive
id - identifier of directive
Returns:
boolean value of given directive
See Also:
forName(String,String)

getInt

public int getInt(java.lang.String directive)
Returns integer value associated with given directive name. If macro doesn't conatain integer value, zero is returned.

Parameters:
directive - name of configuration directive
Returns:
integer value of given directive

getInt

public int getInt(java.lang.String template,
                  java.lang.String id)
Returns integer value associated with given directive name. If macro doesn't conatain integer value, zero is returned.

Parameters:
template - tempate for name of configuration directive
id - identifier of directive
Returns:
integer value of given directive

getIDsByMask

public java.lang.String[] getIDsByMask(java.lang.String mask)
Returns array of indices for given mask. PMP prefix is automaticaly prepended.

Note: Identifier containing character '.' (\u002e) will not be found.

Parameters:
mask - mask (without prefix)
Returns:
array of indices

getMacroNames

public java.lang.String[] getMacroNames()
Returns array of macro names.

Returns:
iterator object

macroIterator

public java.util.Iterator<java.lang.String> macroIterator()
Returns read-only iterator over macro names.

Returns:
iterator object