com.solab.iso8583
Class IsoMessage

java.lang.Object
  extended by com.solab.iso8583.IsoMessage

public class IsoMessage
extends Object

Represents an ISO8583 message. This is the core class of the framework. Contains the bitmap which is modified as fields are added/removed. This class makes no assumptions as to what types belong in each field, nor what fields should each different message type have; that is left for the developer, since the different ISO8583 implementations can vary greatly.

Author:
Enrique Zamudio

Constructor Summary
IsoMessage()
          Creates a new empty message with no values set.
 
Method Summary
 IsoValue<?> getField(int field)
          Returns the IsoValue for the specified field.
 String getIsoHeader()
          Returns the ISO header that this message was created with.
 Object getObjectValue(int field)
          Returns the stored value in the field, without converting or formatting it.
 int getType()
          Returns the ISO message type.
 boolean hasField(int idx)
          Returns true is the message has a value in the specified field.
 boolean isBinary()
          Returns true if the message is binary coded; default is false.
 void setBinary(boolean flag)
          Indicates whether the message should be binary.
 void setEtx(int value)
          Sets the ETX character, which is sent at the end of the message as a terminator.
 void setField(int index, IsoValue<?> field)
          Stored the field in the specified index.
 void setIsoHeader(String value)
          Sets the string to be sent as ISO header, that is, after the length header but before the message type.
 void setType(int value)
          Sets the ISO message type.
 void setValue(int index, Object value, CustomField<Object> encoder, IsoType t, int length)
          Sets the specified value in the specified field, creating an IsoValue internally.
 void setValue(int index, Object value, IsoType t, int length)
          Sets the specified value in the specified field, creating an IsoValue internally.
 void write(OutputStream outs, int lengthBytes)
          Writes a message to a stream, after writing the specified number of bytes indicating the message's length.
 byte[] writeData()
          This calls writeInternal(), allowing applications to get the byte buffer containing the message data, without the length header.
protected  byte[] writeInternal()
          Writes the message to a memory buffer and returns it.
 ByteBuffer writeToBuffer(int lengthBytes)
          Creates and returns a ByteBuffer with the data of the message, including the length header.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IsoMessage

public IsoMessage()
Creates a new empty message with no values set.

Method Detail

setIsoHeader

public void setIsoHeader(String value)
Sets the string to be sent as ISO header, that is, after the length header but before the message type. This is useful in case an application needs some custom data in the ISO header of each message (very rare).


getIsoHeader

public String getIsoHeader()
Returns the ISO header that this message was created with.


setType

public void setType(int value)
Sets the ISO message type. Common values are 0x200, 0x210, 0x400, 0x410, 0x800, 0x810.


getType

public int getType()
Returns the ISO message type.


setBinary

public void setBinary(boolean flag)
Indicates whether the message should be binary. Default is false.


isBinary

public boolean isBinary()
Returns true if the message is binary coded; default is false.


setEtx

public void setEtx(int value)
Sets the ETX character, which is sent at the end of the message as a terminator. Default is -1, which means no terminator is sent.


getObjectValue

public Object getObjectValue(int field)
Returns the stored value in the field, without converting or formatting it.

Parameters:
field - The field number. 1 is the secondary bitmap and is not returned as such; real fields go from 2 to 128.

getField

public IsoValue<?> getField(int field)
Returns the IsoValue for the specified field. First real field is 2.


setField

public void setField(int index,
                     IsoValue<?> field)
Stored the field in the specified index. The first field is the secondary bitmap and has index 1, so the first valid value for index must be 2.


setValue

public void setValue(int index,
                     Object value,
                     IsoType t,
                     int length)
Sets the specified value in the specified field, creating an IsoValue internally.

Parameters:
index - The field number (2 to 128)
value - The value to be stored.
t - The ISO type.
length - The length of the field, used for ALPHA and NUMERIC values only, ignored with any other type.

setValue

public void setValue(int index,
                     Object value,
                     CustomField<Object> encoder,
                     IsoType t,
                     int length)
Sets the specified value in the specified field, creating an IsoValue internally.

Parameters:
index - The field number (2 to 128)
value - The value to be stored.
encoder - An optional CustomField to encode/decode the value.
t - The ISO type.
length - The length of the field, used for ALPHA and NUMERIC values only, ignored with any other type.

hasField

public boolean hasField(int idx)
Returns true is the message has a value in the specified field.

Parameters:
idx - The field number.

write

public void write(OutputStream outs,
                  int lengthBytes)
           throws IOException
Writes a message to a stream, after writing the specified number of bytes indicating the message's length. The message will first be written to an internal memory stream which will then be dumped into the specified stream. This method flushes the stream after the write. There are at most three write operations to the stream: one for the length header, one for the message, and the last one with for the ETX.

Parameters:
outs - The stream to write the message to.
lengthBytes - The size of the message length header. Valid ranges are 0 to 4.
Throws:
IllegalArgumentException - if the specified length header is more than 4 bytes.
IOException - if there is a problem writing to the stream.

writeToBuffer

public ByteBuffer writeToBuffer(int lengthBytes)
Creates and returns a ByteBuffer with the data of the message, including the length header. The returned buffer is already flipped, so it is ready to be written to a Channel.


writeData

public byte[] writeData()
This calls writeInternal(), allowing applications to get the byte buffer containing the message data, without the length header.


writeInternal

protected byte[] writeInternal()
Writes the message to a memory buffer and returns it. The message does not include the ETX character or the header length.