Package org.jpos.iso
Class ISOMsg
- java.lang.Object
-
- org.jpos.iso.ISOComponent
-
- org.jpos.iso.ISOMsg
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,java.lang.Cloneable
,Loggeable
- Direct Known Subclasses:
FSDISOMsg
,ISOMsgRef.Ref
,ISOVMsg
public class ISOMsg extends ISOComponent implements java.lang.Cloneable, Loggeable, java.io.Externalizable
implements Composite within a Composite pattern- See Also:
ISOComponent
,ISOField
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
direction
protected boolean
dirty
protected int
fieldNumber
protected java.util.Map<java.lang.Integer,java.lang.Object>
fields
protected ISOHeader
header
static int
INCOMING
protected int
maxField
protected boolean
maxFieldDirty
static int
OUTGOING
protected ISOPackager
packager
protected byte[]
trailer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
java.lang.Object
clone(int... fields)
Partially clone an ISOMsgISOMsg
clone(java.lang.String... fpaths)
Partially clone an ISOMsg by field pathsvoid
dump(java.io.PrintStream p, java.lang.String indent)
dump the message to a PrintStream.byte[]
getBytes(int fldno)
Return the byte[] value associated with the given ISOField numberbyte[]
getBytes(java.lang.String fpath)
Return the String value associated with the given field pathjava.util.Map
getChildren()
clone fieldsISOComponent
getComponent(int fldno)
get the component associated with the given field numberISOComponent
getComponent(java.lang.String fpath)
get the component associated with the given field numberISOComponent
getComposite()
In order to interchange Composites and Leafs we use getComposite().int
getDirection()
int
getFieldNumber()
byte[]
getHeader()
get optional message header imageISOHeader
getISOHeader()
Return this messages ISOHeaderjava.lang.Object
getKey()
valid on Leafs only.int
getMaxField()
a Composite must override this functionjava.lang.String
getMTI()
ISOPackager
getPackager()
ISOSource
getSource()
java.lang.String
getString(int fldno)
Return the String value associated with the given ISOField numberjava.lang.String
getString(java.lang.String fpath)
Return the String value associated with the given field pathbyte[]
getTrailer()
Get optional trailer image.java.lang.Object
getValue()
valid on Leafs only.java.lang.Object
getValue(int fldno)
Return the object value associated with the given field numberjava.lang.Object
getValue(java.lang.String fpath)
Return the object value associated with the given field pathboolean
hasAny(int[] fields)
Check if the message has any of these fieldsboolean
hasAny(java.lang.String... fields)
Check if the message has any of these fieldsboolean
hasField(int fldno)
Check if a given field is presentboolean
hasField(java.lang.String fpath)
Check if a field indicated by a fpath is presentboolean
hasFields()
boolean
hasFields(int[] fields)
Check if all fields are presentboolean
hasMTI()
boolean
isAdministrative()
boolean
isAuthorization()
boolean
isChargeback()
boolean
isFeeCollection()
boolean
isFileAction()
boolean
isFinancial()
boolean
isIncoming()
boolean
isInner()
boolean
isNetworkManagement()
boolean
isOutgoing()
boolean
isReconciliation()
boolean
isRequest()
boolean
isResponse()
boolean
isRetransmission()
boolean
isReversal()
void
merge(ISOMsg m)
add all fields present on received parameter to this ISOMsg
please note that received fields take precedence over existing ones (simplifying card agent message creation and template handling)void
move(int oldFieldNumber, int newFieldNumber)
moves a field (renumber)byte[]
pack()
pack the message with the current packagerprotected void
readDirection(java.io.ObjectInput in)
void
readExternal(java.io.ObjectInput in)
protected void
readHeader(java.io.ObjectInput in)
protected void
readPackager(java.io.ObjectInput in)
void
recalcBitMap()
setup BitMapvoid
set(int fldno, byte[] value)
Creates an ISOBinaryField associated with fldno within this ISOMsg.void
set(int fldno, java.lang.String value)
Creates an ISOField associated with fldno within this ISOMsg.void
set(java.lang.String fpath, byte[] value)
Creates an ISOField associated with fldno within this ISOMsg.void
set(java.lang.String fpath, java.lang.String value)
Creates an ISOField associated with fldno within this ISOMsg.void
set(java.lang.String fpath, ISOComponent c)
Creates an ISOField associated with fldno within this ISOMsgvoid
set(ISOComponent c)
Set a field within this messagevoid
setDirection(int direction)
Sets the direction information related to this messagevoid
setFieldNumber(int fieldNumber)
changes this Component field number
Use with care, this method does not change any reference held by a Composite.void
setHeader(byte[] b)
Sets an optional message header imagevoid
setHeader(ISOHeader header)
void
setMTI(java.lang.String mti)
void
setPackager(ISOPackager p)
void
setResponseMTI()
sets an appropriate response MTI.void
setRetransmissionMTI()
sets an appropriate retransmission MTIvoid
setSource(ISOSource source)
Let this ISOMsg object hold a weak reference to an ISOSource (usually used to carry a reference to the incoming ISOChannel)void
setTrailer(byte[] trailer)
Sets optional trailer data.void
setValue(java.lang.Object obj)
Don't call setValue on an ISOMsg.java.lang.String
toString()
int
unpack(byte[] b)
unpack a messagevoid
unpack(java.io.InputStream in)
void
unset(int fldno)
Unset a field if it exists, otherwise ignore.void
unset(int... flds)
Unsets several fields at oncevoid
unset(java.lang.String fpath)
Unset a field referenced by a fpath if it exists, otherwise ignore.void
unset(java.lang.String... fpaths)
Unset a set of fields referenced by fpaths, if any of them exist.protected void
writeDirection(java.io.ObjectOutput out)
void
writeExternal(java.io.ObjectOutput out)
protected void
writeHeader(java.io.ObjectOutput out)
protected void
writePackager(java.io.ObjectOutput out)
-
Methods inherited from class org.jpos.iso.ISOComponent
getBytes, pack
-
-
-
-
Field Detail
-
fields
protected java.util.Map<java.lang.Integer,java.lang.Object> fields
-
maxField
protected int maxField
-
packager
protected ISOPackager packager
-
dirty
protected boolean dirty
-
maxFieldDirty
protected boolean maxFieldDirty
-
direction
protected int direction
-
trailer
protected byte[] trailer
-
fieldNumber
protected int fieldNumber
-
INCOMING
public static final int INCOMING
- See Also:
- Constant Field Values
-
OUTGOING
public static final int OUTGOING
- See Also:
- Constant Field Values
-
-
Method Detail
-
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 classISOComponent
- 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
-
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
public ISOHeader 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:
ISOChannel
-
isIncoming
public boolean isIncoming()
- Returns:
- true if this message is an incoming message
- See Also:
ISOChannel
-
isOutgoing
public boolean isOutgoing()
- Returns:
- true if this message is an outgoing message
- See Also:
ISOChannel
-
getMaxField
public int getMaxField()
Description copied from class:ISOComponent
a Composite must override this function- Overrides:
getMaxField
in classISOComponent
- Returns:
- the max field number associated with this message
-
setPackager
public void setPackager(ISOPackager p)
- Parameters:
p
- - a peer packager
-
getPackager
public ISOPackager getPackager()
- Returns:
- the peer packager
-
set
public void set(ISOComponent c) throws ISOException
Set a field within this message- Overrides:
set
in classISOComponent
- Parameters:
c
- - a component- Throws:
ISOException
-
set
public void set(int fldno, java.lang.String value)
Creates an ISOField associated with fldno within this ISOMsg.- Parameters:
fldno
- field numbervalue
- field value
-
set
public void set(java.lang.String fpath, java.lang.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(java.lang.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(java.lang.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 numbervalue
- field value
-
unset
public void unset(int fldno)
Unset a field if it exists, otherwise ignore.- Overrides:
unset
in classISOComponent
- 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(java.lang.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(java.lang.String... fpaths)
Unset a set of fields referenced by fpaths, if any of them exist. Otherwise, ignore.- Parameters:
fpaths
- dot-separated field paths (i.e. 63.2)
-
getComposite
public ISOComponent getComposite()
In order to interchange Composites and Leafs we use getComposite(). A Composite component returns itself and a Leaf returns null.- Overrides:
getComposite
in classISOComponent
- Returns:
- ISOComponent
-
recalcBitMap
public void recalcBitMap() throws ISOException
setup BitMap- Throws:
ISOException
- on error
-
getChildren
public java.util.Map getChildren()
clone fields- Overrides:
getChildren
in classISOComponent
- Returns:
- copy of fields
-
pack
public byte[] pack() throws ISOException
pack the message with the current packager- Specified by:
pack
in classISOComponent
- Returns:
- the packed message
- Throws:
ISOException
-
unpack
public int unpack(byte[] b) throws ISOException
unpack a message- Specified by:
unpack
in classISOComponent
- Parameters:
b
- - raw message- Returns:
- consumed bytes
- Throws:
ISOException
-
unpack
public void unpack(java.io.InputStream in) throws java.io.IOException, ISOException
- Specified by:
unpack
in classISOComponent
- Throws:
java.io.IOException
ISOException
-
dump
public void dump(java.io.PrintStream p, java.lang.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 interfaceLoggeable
- Specified by:
dump
in classISOComponent
- Parameters:
p
- - print streamindent
- - 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 java.lang.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 java.lang.Object getValue(java.lang.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
public ISOComponent getComponent(java.lang.String fpath) throws ISOException
get the component associated with the given field number- Parameters:
fpath
- field path- Returns:
- the Component
- Throws:
ISOException
- on error
-
getString
public java.lang.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 java.lang.String getString(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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 classISOComponent
- Parameters:
obj
-- Throws:
ISOException
- See Also:
ISOField
,ISOException
-
clone
public java.lang.Object clone()
- Overrides:
clone
in classjava.lang.Object
-
clone
public java.lang.Object clone(int... fields)
Partially clone an ISOMsg- Parameters:
fields
- int array of fields to go- Returns:
- new ISOMsg instance
-
clone
public ISOMsg clone(java.lang.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)
add all fields present on received parameter to this ISOMsg
please note that received fields take precedence over existing ones (simplifying card agent message creation and template handling)- Parameters:
m
- ISOMsg to merge
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string suitable for a log
-
getKey
public java.lang.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 classISOComponent
- Returns:
- object representing the field number
- Throws:
ISOException
-
getValue
public java.lang.Object getValue()
Description copied from class:ISOComponent
valid on Leafs only.- Overrides:
getValue
in classISOComponent
- Returns:
- object representing the field value
-
isInner
public boolean isInner()
- Returns:
- true on inner messages
-
setMTI
public void setMTI(java.lang.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 numbernewFieldNumber
- new field number- Throws:
ISOException
- on error
-
getFieldNumber
public int getFieldNumber()
- Specified by:
getFieldNumber
in classISOComponent
-
hasMTI
public boolean hasMTI() throws ISOException
- Returns:
- true is message has MTI field
- Throws:
ISOException
- if this is an inner message
-
getMTI
public java.lang.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(java.io.ObjectOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
readHeader
protected void readHeader(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writePackager
protected void writePackager(java.io.ObjectOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
readPackager
protected void readPackager(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeDirection
protected void writeDirection(java.io.ObjectOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
readDirection
protected void readDirection(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
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
-
-