pmp
Class AbstractMacro

java.lang.Object
  extended by pmp.AbstractMacro
Direct Known Subclasses:
Adler32, Builtin, Call, Cast, CEncoder, CEscDecoder, Compare, Const, Construct, Copydef, CRC32, Dec, Define, DefinedMacro, Defn, Echo, Error, Eval, Exec, Field, GetProperty, Halt, HTMLEntityDecoder, HTMLSpecialChars, Chr, IfElse, IfNotZero, Inc, Include, InstanceOf, Invoke, IsBuiltin, IsDefined, IsNumber, IsSet, JavaEncoder, JavaEscDecoder, Length, Locate, LowerCase, MacroChain, MacroTable, Match, Max, MD5, Min, New, NewString, Ord, Output, Pause, Popdef, Pushdef, Random, Repeat, Replace, Reverse, Rot13, SetProperty, Shift, SilentExec, StrTok, SubStr, SubstrCount, ToClassName, ToString, Trim, Undefine, UpperCase, UUID, Version, Warning

public abstract class AbstractMacro
extends java.lang.Object

Abstract superclass for all macros.

Title: PMP: Macroprocessor

Description: Java macroprocessor

Copyright: Copyright (c) 2005

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

Field Summary
protected  int PARAMS_REQUIRED
          Number of required parameters.
 
Constructor Summary
AbstractMacro()
          Instances of macros are instantiated using nullary constructors.
 
Method Summary
 int getRequiredParams()
           Number of required parameters.
abstract  java.lang.String run(Macroprocessor mp, java.lang.String[] args)
          Main method of macro.
 java.lang.String toString()
           Returns string representation of macro.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PARAMS_REQUIRED

protected int PARAMS_REQUIRED
Number of required parameters. This field is filled by constructor and contains the same value as filed with the same name declared in subclass.

Constructor Detail

AbstractMacro

public AbstractMacro()
Instances of macros are instantiated using nullary constructors.

Method Detail

run

public abstract java.lang.String run(Macroprocessor mp,
                                     java.lang.String[] args)
Main method of macro. This method is called when this macro is invoked. All subclasses must imlement this method

Parameters:
mp - reference to Macroprocessor
args - parameters of macro. In args[0] is stored name of macro. Subclasses are free to modify this array.
Returns:
result of the macro as String

getRequiredParams

public final int getRequiredParams()

Number of required parameters. Before invoking run method, macroprocessor checks the number of passed parameters and appends empty strings ("") to the end of args array if necessary.

This method obtains number of parameters from field PARAMS_REQUIRED.

Value is number of formal parameters of macro. I.e.: it doesn't include name of macro, which is passed as parameter with index 0. So if your macro requires two parameters, this field should be set to 2, like this:

public static final int PARAMS_REQUIRED = 2;

This field allows you to omit length-checking of args array in run(Macroprocessor,String[]) method. (But you still have to perform test for empty string if your macro requires non-empty parameters.

Returns:
number of parameters to be pased to this macro

toString

public java.lang.String toString()

Returns string representation of macro. This method is used by defn macro. If you want reimplement this method, you must make sure it will not return null.

For user-defined macros it should return definition and for builtin ones empty string unless it has some meaning.

Overrides:
toString in class java.lang.Object
Returns:
empty String
See Also:
Defn