Class ISOBasePackager

java.lang.Object
org.jpos.iso.ISOBasePackager
All Implemented Interfaces:
ISOPackager, LogSource
Direct Known Subclasses:
Base1Packager, Base1Packager.F127Packager, Base1SubFieldPackager, BASE24Packager, EuroPackager, EuroSubFieldPackager, GenericPackager, ISO87APackager, ISO87APackagerBBitmap, ISO87BPackager, ISO93APackager, ISO93BPackager, ISOBaseValidatingPackager, PostPackager, PostPackager.PostPrivatePackager, VAPSMSPackager, VAPVIPPackager, VAPVIPPackager.F127Packager, X92Packager

public abstract class ISOBasePackager extends Object implements ISOPackager, LogSource
provides base functionality for the actual packagers
  • Field Details

    • fld

      protected ISOFieldPackager[] fld
      Per-field packagers indexed by field number.
    • thirdBitmapField

      protected int thirdBitmapField
      Field number that carries the tertiary bitmap as a Data Element, or -999 if not used.
    • logger

      protected Logger logger
      Logger used to record pack/unpack diagnostics; null disables logging.
    • logFieldName

      protected boolean logFieldName
      When true, field descriptions are emitted as XML comments in unpack logs.
    • realm

      protected String realm
      Logger realm associated with this packager.
    • headerLength

      protected int headerLength
      Number of leading bytes treated as the ISO header during unpack.
  • Constructor Details

    • ISOBasePackager

      protected ISOBasePackager()
      Default constructor; no instance state to initialise.
  • Method Details

    • setFieldPackager

      public void setFieldPackager(ISOFieldPackager[] fld)
      Replaces the per-field packager array.
      Parameters:
      fld - new array of field packagers indexed by field number
    • setThirdBitmapField

      public void setThirdBitmapField(int f) throws ISOException
      Configures the Data Element field that holds the tertiary bitmap.
      Parameters:
      f - field number in the range [0, 128]
      Throws:
      ISOException - if f is outside the valid range
    • getThirdBitmapField

      public int getThirdBitmapField()
      Returns the field number carrying the tertiary bitmap as a Data Element.
      Returns:
      the configured third-bitmap field number, or -999 if not set
    • emitBitMap

      protected boolean emitBitMap()
      Indicates whether a primary bitmap is emitted on pack.
      Returns:
      true if the field-1 packager is an ISOBitMapPackager
    • getFirstField

      protected int getFirstField()
      usually 2 for normal fields, 1 for bitmap-less or ANSI X9.2
      Returns:
      first valid field
    • pack

      public byte[] pack(ISOComponent m) throws ISOException
      pack method that works in conjunction with unpack(ISOComponent, byte[]).

      Handles a tertiary bitmap possibly appearing in Data Element thirdBitmapField.

      Specified by:
      pack in interface ISOPackager
      Parameters:
      m - the Component to pack
      Returns:
      Message image
      Throws:
      ISOException - if the component cannot be packed
    • unpack

      public int unpack(ISOComponent m, byte[] b) throws ISOException
      Description copied from interface: ISOPackager
      Unpacks an ISO-8583 byte array into the given message container.
      Specified by:
      unpack in interface ISOPackager
      Parameters:
      m - the Container of this message
      b - ISO message image
      Returns:
      consumed bytes
      Throws:
      ISOException - if the message image cannot be unpacked
    • unpack

      public void unpack(ISOComponent m, InputStream in) throws IOException, ISOException
      Description copied from interface: ISOPackager
      Unpacks an ISO-8583 message from an input stream into the given container.
      Specified by:
      unpack in interface ISOPackager
      Parameters:
      m - the container
      in - the input stream
      Throws:
      IOException - on I/O failure
      ISOException - on unpacking error
    • fieldUnpackLogger

      protected static void fieldUnpackLogger(LogEvent evt, int fldno, ISOComponent c, ISOFieldPackager fld, boolean logFieldName) throws ISOException
      Internal helper logging function. Assumes evt is not null.
      Parameters:
      evt - the log event to append messages to (must not be null)
      fldno - the field number being unpacked
      c - the unpacked component carrying the field value
      fld - the field packager that produced c
      logFieldName - when true, emits the field description as an XML comment
      Throws:
      ISOException - if the value cannot be rendered for logging
    • getFieldDescription

      public String getFieldDescription(ISOComponent m, int fldNumber)
      Returns the human-readable description of a field as defined by its packager.
      Specified by:
      getFieldDescription in interface ISOPackager
      Parameters:
      m - the Container (i.e. an ISOMsg)
      fldNumber - the Field Number
      Returns:
      Field Description
    • getFieldPackager

      public ISOFieldPackager getFieldPackager(int fldNumber)
      Returns the field packager registered for the given field number.
      Parameters:
      fldNumber - the Field Number
      Returns:
      Field Packager for this field
    • setFieldPackager

      public void setFieldPackager(int fldNumber, ISOFieldPackager fieldPackager)
      Replaces the packager registered for a single field.
      Parameters:
      fldNumber - the Field Number
      fieldPackager - the Field Packager
    • createISOMsg

      public ISOMsg createISOMsg()
      Factory hook returning the ISOMsg subclass produced during unpack.
      Specified by:
      createISOMsg in interface ISOPackager
      Returns:
      a new ISOMsg instance
    • getMaxValidField

      protected int getMaxValidField()
      Returns the highest valid field number for this packager.
      Returns:
      128 for ISO-8583, should return 64 for ANSI X9.2
    • getBitMapfieldPackager

      Returns the field packager used for the primary bitmap.
      Returns:
      suitable ISOFieldPackager for Bitmap
    • setLogger

      public void setLogger(Logger logger, String realm)
      Description copied from interface: LogSource
      Attaches a Logger and realm to this log source.
      Specified by:
      setLogger in interface LogSource
      Parameters:
      logger - the logger to use
      realm - the log realm (diagnostic label)
    • getRealm

      public String getRealm()
      Description copied from interface: LogSource
      Returns the log realm associated with this source.
      Specified by:
      getRealm in interface LogSource
      Returns:
      log realm
    • getLogger

      public Logger getLogger()
      Description copied from interface: LogSource
      Returns the Logger associated with this source.
      Specified by:
      getLogger in interface LogSource
      Returns:
      the Logger
    • getHeaderLength

      public int getHeaderLength()
      Returns the configured ISO header length in bytes.
      Returns:
      number of leading bytes treated as the ISO header during unpack
    • setHeaderLength

      public void setHeaderLength(int len)
      Sets the ISO header length in bytes.
      Parameters:
      len - number of leading bytes to treat as the ISO header during unpack
    • getDescription

      Description copied from interface: ISOPackager
      Returns a human-readable description of this packager.
      Specified by:
      getDescription in interface ISOPackager
      Returns:
      Packager's Description