Class ISOMsg

All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Loggeable
Direct Known Subclasses:
FSDISOMsg, ISOMsgRef.Ref, ISOVMsg

public class ISOMsg extends ISOComponent implements Cloneable, Loggeable, Externalizable
implements Composite within a Composite pattern
See Also:
  • Field Details

  • Constructor Details

    • ISOMsg

      public ISOMsg()
      Creates an ISOMsg
    • ISOMsg

      public ISOMsg(int fieldNumber)
      Creates a nested ISOMsg
      Parameters:
      fieldNumber - (in the outer ISOMsg) of this nested message
    • ISOMsg

      public ISOMsg(String mti)
      Creates an ISOMsg with given mti
      Parameters:
      mti - Msg's MTI
  • Method Details

    • setFieldNumber

      public void setFieldNumber(int fieldNumber)
      changes this Component field number
      Use with care, this method does not change any reference held by a Composite.
      Specified by:
      setFieldNumber in class ISOComponent
      Parameters:
      fieldNumber - new field number
    • setDirection

      public void setDirection(int direction)
      Sets the direction information related to this message
      Parameters:
      direction - can be either ISOMsg.INCOMING or ISOMsg.OUTGOING
    • setHeader

      public void setHeader(byte[] b)
      Sets an optional message header image
      Parameters:
      b - header image
    • setHeader

      public void setHeader(ISOHeader header)
    • getHeader

      public byte[] getHeader()
      get optional message header image
      Returns:
      message header image (may be null)
    • setTrailer

      public void setTrailer(byte[] trailer)
      Sets optional trailer data.

      Note: The trailer data requires a customised channel that explicitly handles the trailer data from the ISOMsg.

      Parameters:
      trailer - The trailer data.
    • getTrailer

      public byte[] getTrailer()
      Get optional trailer image.
      Returns:
      message trailer image (may be null)
    • getISOHeader

      Return this messages ISOHeader
      Returns:
      header associated with this ISOMsg, can be null
    • getDirection

      public int getDirection()
      Returns:
      the direction (ISOMsg.INCOMING or ISOMsg.OUTGOING)
      See Also:
    • isIncoming

      public boolean isIncoming()
      Returns:
      true if this message is an incoming message
      See Also:
    • isOutgoing

      public boolean isOutgoing()
      Returns:
      true if this message is an outgoing message
      See Also:
    • getMaxField

      public int getMaxField()
      Description copied from class: ISOComponent
      a Composite must override this function
      Overrides:
      getMaxField in class ISOComponent
      Returns:
      the max field number associated with this message
    • setPackager

      public void setPackager(ISOPackager p)
      Parameters:
      p - - a peer packager
    • getPackager

      Returns:
      the peer packager
    • set

      public void set(ISOComponent c) throws ISOException
      Set a field within this message
      Overrides:
      set in class ISOComponent
      Parameters:
      c - - a component
      Throws:
      ISOException
    • set

      public void set(int fldno, String value)
      Creates an ISOField associated with fldno within this ISOMsg.
      Parameters:
      fldno - field number
      value - field value
    • set

      public void set(String fpath, String value)
      Creates an ISOField associated with fldno within this ISOMsg.
      Parameters:
      fpath - dot-separated field path (i.e. 63.2)
      value - field value
    • set

      public void set(String fpath, ISOComponent c) throws ISOException
      Creates an ISOField associated with fldno within this ISOMsg
      Parameters:
      fpath - dot-separated field path (i.e. 63.2)
      c - component
      Throws:
      ISOException - on error
    • set

      public void set(String fpath, byte[] value)
      Creates an ISOField associated with fldno within this ISOMsg.
      Parameters:
      fpath - dot-separated field path (i.e. 63.2)
      value - binary field value
    • set

      public void set(int fldno, byte[] value)
      Creates an ISOBinaryField associated with fldno within this ISOMsg.
      Parameters:
      fldno - field number
      value - field value
    • unset

      public void unset(int fldno)
      Unset a field if it exists, otherwise ignore.
      Overrides:
      unset in class ISOComponent
      Parameters:
      fldno - - the field number
    • unset

      public void unset(int... flds)
      Unsets several fields at once
      Parameters:
      flds - - array of fields to be unset from this ISOMsg
    • unset

      public void unset(String fpath)
      Unset a field referenced by a fpath if it exists, otherwise ignore.
      Parameters:
      fpath - dot-separated field path (i.e. 63.2)
    • unset

      public void unset(String... fpaths)
      Unset a a set of fields referenced by fpaths if any ot them exist, otherwise ignore.
      Parameters:
      fpaths - dot-separated field paths (i.e. 63.2)
    • getComposite

      In order to interchange Composites and Leafs we use getComposite(). A Composite component returns itself and a Leaf returns null.
      Overrides:
      getComposite in class ISOComponent
      Returns:
      ISOComponent
    • recalcBitMap

      public void recalcBitMap() throws ISOException
      setup BitMap
      Throws:
      ISOException - on error
    • getChildren

      public Map getChildren()
      clone fields
      Overrides:
      getChildren in class ISOComponent
      Returns:
      copy of fields
    • pack

      public byte[] pack() throws ISOException
      pack the message with the current packager
      Specified by:
      pack in class ISOComponent
      Returns:
      the packed message
      Throws:
      ISOException
    • unpack

      public int unpack(byte[] b) throws ISOException
      unpack a message
      Specified by:
      unpack in class ISOComponent
      Parameters:
      b - - raw message
      Returns:
      consumed bytes
      Throws:
      ISOException
    • unpack

      public void unpack(InputStream in) throws IOException, ISOException
      Specified by:
      unpack in class ISOComponent
      Throws:
      IOException
      ISOException
    • dump

      public void dump(PrintStream p, String indent)
      dump the message to a PrintStream. The output is sorta XML, intended to be easily parsed.
      Each component is responsible for its own dump function, ISOMsg just calls dump on every valid field.
      Specified by:
      dump in interface Loggeable
      Specified by:
      dump in class ISOComponent
      Parameters:
      p - - print stream
      indent - - optional indent string
    • getComponent

      public ISOComponent getComponent(int fldno)
      get the component associated with the given field number
      Parameters:
      fldno - the Field Number
      Returns:
      the Component
    • getValue

      public Object getValue(int fldno)
      Return the object value associated with the given field number
      Parameters:
      fldno - the Field Number
      Returns:
      the field Object
    • getValue

      public Object getValue(String fpath) throws ISOException
      Return the object value associated with the given field path
      Parameters:
      fpath - field path
      Returns:
      the field Object (may be null)
      Throws:
      ISOException - on error
    • getComponent

      get the component associated with the given field number
      Parameters:
      fpath - field path
      Returns:
      the Component
      Throws:
      ISOException - on error
    • getString

      public String getString(int fldno)
      Return the String value associated with the given ISOField number
      Parameters:
      fldno - the Field Number
      Returns:
      field's String value
    • getString

      public String getString(String fpath)
      Return the String value associated with the given field path
      Parameters:
      fpath - field path
      Returns:
      field's String value (may be null)
    • getBytes

      public byte[] getBytes(int fldno)
      Return the byte[] value associated with the given ISOField number
      Parameters:
      fldno - the Field Number
      Returns:
      field's byte[] value or null if ISOException or UnsupportedEncodingException happens
    • getBytes

      public byte[] getBytes(String fpath)
      Return the String value associated with the given field path
      Parameters:
      fpath - field path
      Returns:
      field's byte[] value (may be null)
    • hasField

      public boolean hasField(int fldno)
      Check if a given field is present
      Parameters:
      fldno - the Field Number
      Returns:
      boolean indicating the existence of the field
    • hasFields

      public boolean hasFields(int[] fields)
      Check if all fields are present
      Parameters:
      fields - an array of fields to check for presence
      Returns:
      true if all fields are present
    • hasAny

      public boolean hasAny(int[] fields)
      Check if the message has any of these fields
      Parameters:
      fields - an array of fields to check for presence
      Returns:
      true if at least one field is present
    • hasAny

      public boolean hasAny(String... fields)
      Check if the message has any of these fields
      Parameters:
      fields - to check for presence
      Returns:
      true if at least one field is present
    • hasField

      public boolean hasField(String fpath)
      Check if a field indicated by a fpath is present
      Parameters:
      fpath - dot-separated field path (i.e. 63.2)
      Returns:
      true if field present
    • hasFields

      public boolean hasFields()
      Returns:
      true if ISOMsg has at least one field
    • setValue

      public void setValue(Object obj) throws ISOException
      Don't call setValue on an ISOMsg. You'll sure get an ISOException. It's intended to be used on Leafs
      Specified by:
      setValue in class ISOComponent
      Parameters:
      obj -
      Throws:
      ISOException
      See Also:
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • clone

      public Object clone(int... fields)
      Partially clone an ISOMsg
      Parameters:
      fields - int array of fields to go
      Returns:
      new ISOMsg instance
    • clone

      public ISOMsg clone(String... fpaths)
      Partially clone an ISOMsg by field paths
      Parameters:
      fpaths - string array of field paths to copy
      Returns:
      new ISOMsg instance
    • merge

      public void merge(ISOMsg m, boolean mergeHeader)
      Merges the content of the specified ISOMsg into this ISOMsg instance. It iterates over the fields of the input message and, for each field that is present, sets the corresponding component in this message to the value from the input message. This operation includes all fields that are present in the input message, but does not remove any existing fields from this message unless they are explicitly overwritten by the input message.

      If the input message contains a header (non-null), this method also clones the header and sets it as the header of this message.

      Parameters:
      m - The ISOMsg to merge into this ISOMsg. It must not be null. The method does nothing if m is null.
      mergeHeader - A boolean flag indicating whether to merge the header of the input message into this message.
    • merge

      public void merge(ISOMsg m)
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      a string suitable for a log
    • getKey

      public Object getKey() throws ISOException
      Description copied from class: ISOComponent
      valid on Leafs only. The value returned is used by ISOMsg as a key to this field.
      Overrides:
      getKey in class ISOComponent
      Returns:
      object representing the field number
      Throws:
      ISOException
    • getValue

      public Object getValue()
      Description copied from class: ISOComponent
      valid on Leafs only.
      Overrides:
      getValue in class ISOComponent
      Returns:
      object representing the field value
    • isInner

      public boolean isInner()
      Returns:
      true on inner messages
    • setMTI

      public void setMTI(String mti) throws ISOException
      Parameters:
      mti - new MTI
      Throws:
      ISOException - if message is inner message
    • move

      public void move(int oldFieldNumber, int newFieldNumber) throws ISOException
      moves a field (renumber)
      Parameters:
      oldFieldNumber - old field number
      newFieldNumber - new field number
      Throws:
      ISOException - on error
    • getFieldNumber

      public int getFieldNumber()
      Specified by:
      getFieldNumber in class ISOComponent
    • hasMTI

      public boolean hasMTI() throws ISOException
      Returns:
      true is message has MTI field
      Throws:
      ISOException - if this is an inner message
    • getMTI

      public String getMTI() throws ISOException
      Returns:
      current MTI
      Throws:
      ISOException - on inner message or MTI not set
    • isRequest

      public boolean isRequest() throws ISOException
      Returns:
      true if message "seems to be" a request
      Throws:
      ISOException - on MTI not set
    • isResponse

      public boolean isResponse() throws ISOException
      Returns:
      true if message "seems not to be" a request
      Throws:
      ISOException - on MTI not set
    • isAuthorization

      public boolean isAuthorization() throws ISOException
      Returns:
      true if message class is "authorization"
      Throws:
      ISOException - on MTI not set
    • isFinancial

      public boolean isFinancial() throws ISOException
      Returns:
      true if message class is "financial"
      Throws:
      ISOException - on MTI not set
    • isFileAction

      public boolean isFileAction() throws ISOException
      Returns:
      true if message class is "file action"
      Throws:
      ISOException - on MTI not set
    • isReversal

      public boolean isReversal() throws ISOException
      Returns:
      true if message class is "reversal"
      Throws:
      ISOException - on MTI not set
    • isChargeback

      public boolean isChargeback() throws ISOException
      Returns:
      true if message class is "chargeback"
      Throws:
      ISOException - on MTI not set
    • isReconciliation

      public boolean isReconciliation() throws ISOException
      Returns:
      true if message class is "reconciliation"
      Throws:
      ISOException - on MTI not set
    • isAdministrative

      public boolean isAdministrative() throws ISOException
      Returns:
      true if message class is "administrative"
      Throws:
      ISOException - on MTI not set
    • isFeeCollection

      public boolean isFeeCollection() throws ISOException
      Returns:
      true if message class is "fee collection"
      Throws:
      ISOException - on MTI not set
    • isNetworkManagement

      public boolean isNetworkManagement() throws ISOException
      Returns:
      true if message class is "fee collection"
      Throws:
      ISOException - on MTI not set
    • isRetransmission

      public boolean isRetransmission() throws ISOException
      Returns:
      true if message is Retransmission
      Throws:
      ISOException - on MTI not set
    • setResponseMTI

      public void setResponseMTI() throws ISOException
      sets an appropriate response MTI. i.e. 0100 becomes 0110
      i.e. 0201 becomes 0210
      i.e. 1201 becomes 1210
      Throws:
      ISOException - on MTI not set or it is not a request
    • setRetransmissionMTI

      public void setRetransmissionMTI() throws ISOException
      sets an appropriate retransmission MTI
      Throws:
      ISOException - on MTI not set or it is not a request
    • writeHeader

      protected void writeHeader(ObjectOutput out) throws IOException
      Throws:
      IOException
    • readHeader

    • writePackager

      protected void writePackager(ObjectOutput out) throws IOException
      Throws:
      IOException
    • readPackager

    • writeDirection

      protected void writeDirection(ObjectOutput out) throws IOException
      Throws:
      IOException
    • readDirection

    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

    • setSource

      public void setSource(ISOSource source)
      Let this ISOMsg object hold a weak reference to an ISOSource (usually used to carry a reference to the incoming ISOChannel)
      Parameters:
      source - an ISOSource
    • getSource

      public ISOSource getSource()
      Returns:
      an ISOSource or null