Friday, February 11, 2022

Additional parameters in RunBaseBatch class extension

 Old good pack/unpack patterns with SysPackExtension call. Say, we need to augment RunBaseBatch based class <ClassName>.


/// <summary>
/// We are going to use a new additional parameter
/// </summary>
[ExtensionOf(classStr(<ClassName>))]
public final class My<ClassName>_Extension
{
    private boolean     myNewParm;   
    #define.CurrentVersion(1)
    #localmacro.CurrentList
        myNewParm
    #endmacro

    
    /// <summary>
    /// myNewParm access
    /// </summary>
    /// <param name = "_parm">boolean</param>
    /// <returns>boolean</returns>
    public boolean parmMyNewParm(boolean _parm = myNewParm)
{ myNewParm= _parm;
return myNewParm;
} /// <summary> /// Extends Pack /// </summary> /// <returns>container</returns> public container pack() { container packedClass = next pack(); return SysPackExtensions::appendExtension(packedClass, classStr(My<ClassName>_Extension), this.myPack());
} /// <summary> /// Extends Unpack /// </summary> /// <param name = "packedClass">container</param> /// <returns>boolean</returns> private boolean myUnpack(container packedClass) { Integer version = RunBase::getVersion(packedClass); switch (version) { case #CurrentVersion: [version, #currentList] = packedClass; break; default: return false; } return true; } /// <summary> /// Packs my locals /// </summary> /// <returns>container</returns> private container myPack() { return [#CurrentVersion, #CurrentList]; } /// <summary> /// Extends unpack /// </summary> /// <param name = "_packedClass">container</param> /// <returns>boolean</returns> public boolean unpack(container _packedClass) { boolean result = next unpack(_packedClass); if (result) { container myState = SysPackExtensions::findExtension(_packedClass, classStr(My<ClassName>_Extension));
//Also unpack the extension if (!this.myUnpack(myState)) { result = false; } } return result; } }

No comments: