com.prowidesoftware.swift.model
Class SwiftMessage

java.lang.Object
  extended by com.prowidesoftware.swift.model.SwiftMessage
All Implemented Interfaces:
java.io.Serializable

public class SwiftMessage
extends java.lang.Object
implements java.io.Serializable

Base class for swift messages.
This class is a generic data structure container for SWIFT messages.

Instances of this class may have a list of unparsed texts (UnparsedTextList). For easy access, methods have been created that first ensure the lists exists (the real object is created and then call the base method).
However, not all the base list methods have been implemented. If you need to use not exposed functionality, retrieve the underlying list with (see getUnparsedTexts method).

Author:
www.prowidesoftware.com
See Also:
Serialized Form

Field Summary
protected  java.lang.Long id
          Identification of the message when persisted
protected  UnparsedTextList unparsedTexts
          List of unparsed texts.
protected  java.util.List<SwiftBlockUser> userBlocks
          User defined blocks List of SwiftBlockUser.
 
Constructor Summary
SwiftMessage()
          Default constructor.
SwiftMessage(boolean initBlocks)
          Constructor that initializes blocks TODO document hibernate didn't work
SwiftMessage(boolean initBlocks, UnparsedTextList unparsedText)
          Constructor for an unparsed text list that initializes blocks
SwiftMessage(UnparsedTextList unparsedText)
          Constructor for an unparsed text list
 
Method Summary
 void addBlock(SwiftBlock b)
          Add a block to this message.
 void addUserBlock(SwiftBlockUser userBlock)
          Add a user defined block to the message (if the block already exists, it is replaced)
 void clear()
          remove all blocks from these message, including user blocks
 boolean equals(java.lang.Object obj)
           
 java.util.List<Field> fields(java.lang.String... names)
          Get all fields with the given name in the block 4
 java.lang.Integer fragmentCount()
          Gets the total number of fragments of a fragmented message as informed in tag 203.
 java.lang.Integer fragmentNumber()
          Gets the number of this fragment
 SwiftBlock getBlock(int b)
          Get the block number specified by b.
 SwiftBlock1 getBlock1()
          Get block number 1 of this message, may be null if not set
 SwiftBlock2 getBlock2()
          Get block number 2 of this message, may be null if not set
 SwiftBlock3 getBlock3()
          Get block number 3 of this message, may be null if not set
 SwiftBlock4 getBlock4()
          Get block number 4 of this message, may be null if not set
 SwiftBlock5 getBlock5()
          Get block number 5 of this message, may be null if not set
 int getBlockCount()
          Get the number of blocks in this message, including the user blocks
 int getBlockCount(java.lang.Boolean includeUserBlocks)
          Get the number of blocks in this message, optionally including the user blocks.
A block is summed if it is not null and is not empty.
 MessageIOType getDirection()
          Returns the message direction from block 2 or null if block 2 is not found or incomplete
 java.lang.Long getId()
          Get the unique identifier of this message
 java.lang.String getMIR()
          Gets MIR from the application header block or null if the the message is not incoming or the application header block is null
 java.lang.String getMUR()
          Gets MUR from the application header block or null if the the message is not incoming or the application header block is null
 SequenceNode getParsedSequences()
           
 java.lang.String getPDE()
          Gets PDE from the trailer block or null if the trailer or the PDE field is not present
 java.lang.String getPDM()
          Gets PDM from the trailer block or null if the trailer or the PDE field is not present
 java.lang.String getReceiver()
          Gets the message receiver BIC from the message headers.
 java.lang.String getSender()
          Gets the message sender BIC from the message headers.
 java.lang.String getType()
          Tell the message type associated with this object if a block 2 is present.
 int getTypeInt()
          get message type as an int or -1 if an error occurrs or it is not set
 UnparsedTextList getUnparsedTexts()
          returns the unparsed text list
 java.lang.Integer getUnparsedTextsSize()
          returns the size of the unparsed text list
 SwiftBlockUser getUserBlock(java.lang.Integer blockNumber)
          Get a user defined block by number, may be null if not set
 SwiftBlockUser getUserBlock(java.lang.String blockName)
          Get a user defined block by name, may be null if not set
 int getUserBlockPosition(java.lang.String blockName)
          Finds the position of a given User Defined Block in the internal list
 java.util.List<SwiftBlockUser> getUserBlocks()
          Get the list of List of SwiftBlockUser user defined blocks.
 java.lang.String getUUID()
          Gets UUID
 int hashCode()
           
 boolean isCOV()
          Checks if the message is a cover payment, based on the content of the User Header (block3).
 java.lang.Boolean isFragment()
          Checks if the message is a fragment
 java.lang.Boolean isLastFragment()
          Checks if the message is the last fragment
 boolean isMT(java.lang.String type)
          Attempt to identify the current message type (MT).
 boolean isSTP()
          Checks if the message is Straight Through Processing (STP), based on the content of the User Header (block3).
 void removeEmptyBlocks()
          Checks all blocks (1 to 5) and if a block is empty, it is removed from the message.
 void removeUserBlock(java.lang.Integer blockNumber)
          removes a user defined block to the message (if the block does not exists, nothing is done)
 void removeUserBlock(java.lang.String blockName)
          removes a user defined block to the message (if the block does not exists, nothing is done)
 void setBlock1(SwiftBlock1 block1)
          Set the block 1 of the message
 void setBlock2(SwiftBlock2 block2)
          Set the block 2 of the message
 void setBlock3(SwiftBlock3 block3)
          Set the block 3 of the message
 void setBlock4(SwiftBlock4 block4)
          Set the block 4 of the message
 void setBlock5(SwiftBlock5 block5)
          Set the block 5 of the message
 void setId(java.lang.Long id)
          Set the unique identifier of this message
 void setParsedSequences(SequenceNode parsedSequences)
           
 void setUnparsedTexts(UnparsedTextList texts)
          sets the list of unparsed texts
protected  void setUserBlocks(java.util.List<SwiftBlockUser> userBlocks)
          Set the list of user defined blocks.
This method is mainly needed for persistence services.
 java.lang.String toString()
          Commons-lang reflection toString implementation
 void unparsedTextAddText(java.lang.String text)
          adds a new unparsed text
 void unparsedTextAddText(SwiftMessage message)
          adds a new unparsed text from a message
 SwiftMessage unparsedTextGetAsMessage(java.lang.Integer index)
          get an unparsed text as a parsed swift message
 java.lang.String unparsedTextGetText(java.lang.Integer index)
          get an unparsed text
 java.lang.Boolean unparsedTextIsMessage(java.lang.Integer index)
          decides if a specific text (by index) is likely a SWIFT FIN message.
protected  void unparsedTextVerify()
          verifies that the unparsed text list exists
 void visit(IMessageVisitor visitor)
          Visit the current message with the given visitor.
 void visit(SwiftBlock3 block, IMessageVisitor visitor)
          Visit a Block 3 (SwiftBlock3), i.e: call the tag method for block 3 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.
 void visit(SwiftBlock4 block, IMessageVisitor visitor)
          Visit a Block 4 (SwiftBlock4), i.e: call the tag method for block 4 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.
 void visit(SwiftBlock5 block, IMessageVisitor visitor)
          Visit a Block 5 (SwiftBlock5), i.e: call the tag method for block 4 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.
 void visit(SwiftBlockUser block, IMessageVisitor visitor)
          Visit a User Defined Block (SwiftBlockUser), i.e: call the tag method for block 4 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

userBlocks

protected java.util.List<SwiftBlockUser> userBlocks
User defined blocks List of SwiftBlockUser.

Since:
5.0

unparsedTexts

protected UnparsedTextList unparsedTexts
List of unparsed texts. For performance reasons, this will be null until really needed.


id

protected java.lang.Long id
Identification of the message when persisted

Constructor Detail

SwiftMessage

public SwiftMessage()
Default constructor. Must be called since here is performed default handler registration

See Also:
SwiftMessage(boolean)

SwiftMessage

public SwiftMessage(boolean initBlocks)
Constructor that initializes blocks TODO document hibernate didn't work

Parameters:
initBlocks - when false the message will not have any blocks when constructed, if true blocks are created, just like with default constructor

SwiftMessage

public SwiftMessage(boolean initBlocks,
                    UnparsedTextList unparsedText)
Constructor for an unparsed text list that initializes blocks

Parameters:
initBlocks - when false the message will not have any blocks when constructed, if true blocks are created, just like with default consturctor
unparsedText - the list of unparsed texts
See Also:
SwiftMessage()

SwiftMessage

public SwiftMessage(UnparsedTextList unparsedText)
Constructor for an unparsed text list

Parameters:
unparsedText - the list of unparsed texts
See Also:
SwiftMessage()
Method Detail

getBlock

public SwiftBlock getBlock(int b)
Get the block number specified by b.

Parameters:
b - the block number to retrieve, must be greater or equal to 1 and smaller or equal to 5.
Returns:
the block number specified in this message
Throws:
java.lang.IllegalArgumentException - if b < 1 or b > 5

toString

public java.lang.String toString()
Commons-lang reflection toString implementation

Overrides:
toString in class java.lang.Object

addBlock

public void addBlock(SwiftBlock b)
Add a block to this message.

Parameters:
b - the block to add, may be null in which case nothing happens
Throws:
java.lang.IllegalArgumentException - b is null or the method getInt in the block returns a value out of range (non user blocks)

isMT

public boolean isMT(java.lang.String type)
Attempt to identify the current message type (MT).

Parameters:
type - must be a valid registered handler id
Returns:
true if this message is successfully identified as the given MT and false in other case *
Throws:
java.lang.IllegalArgumentException - if parameter type is null or not a valid type (i.e: 3 chars len)
See Also:
SwiftBlock2.getMessageType(), getType()

getType

public java.lang.String getType()
Tell the message type associated with this object if a block 2 is present.

Returns:
a String containing the SWIFT numeric code for the message types or null if the message does not have a block 2.
See Also:
SwiftBlock2.getMessageType()

visit

public void visit(IMessageVisitor visitor)
Visit the current message with the given visitor. This is a simple implementation of the visitor pattern.

Parameters:
visitor - the visitor to use
Throws:
java.lang.IllegalArgumentException - if parameter visitor is null

visit

public void visit(SwiftBlock3 block,
                  IMessageVisitor visitor)
Visit a Block 3 (SwiftBlock3), i.e: call the tag method for block 3 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.

Parameters:
block - the block containing the tags to visit
visitor - the visitor to use
Throws:
java.lang.IllegalArgumentException - if parameter block or visitor are null
Since:
5.0

visit

public void visit(SwiftBlock4 block,
                  IMessageVisitor visitor)
Visit a Block 4 (SwiftBlock4), i.e: call the tag method for block 4 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.

Parameters:
block - the block containing the tags to visit
visitor - the visitor to use
Throws:
java.lang.IllegalArgumentException - if parameter block or visitor are null
Since:
5.0

visit

public void visit(SwiftBlock5 block,
                  IMessageVisitor visitor)
Visit a Block 5 (SwiftBlock5), i.e: call the tag method for block 4 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.

Parameters:
block - the block containing the tags to visit
visitor - the visitor to use
Throws:
java.lang.IllegalArgumentException - if parameter block or visitor are null
Since:
5.0

visit

public void visit(SwiftBlockUser block,
                  IMessageVisitor visitor)
Visit a User Defined Block (SwiftBlockUser), i.e: call the tag method for block 4 This method is called from visit(IMessageVisitor) or the deprecated #visit(SwiftBlock, IMessageVisitor) but may be used independently, in such case, the startBlockX and endBlockX in the visitor will not be called.

Parameters:
block - the block containing the tags to visit
visitor - the visitor to use
Throws:
java.lang.IllegalArgumentException - if parameter block or visitor are null
Since:
5.0

getId

public java.lang.Long getId()
Get the unique identifier of this message

Returns:
the message id
See Also:
id

setId

public void setId(java.lang.Long id)
Set the unique identifier of this message

Parameters:
id - the id to be set
See Also:
id

getBlockCount

public int getBlockCount()
Get the number of blocks in this message, including the user blocks

Returns:
an int greater or equal to zero

getBlockCount

public int getBlockCount(java.lang.Boolean includeUserBlocks)
Get the number of blocks in this message, optionally including the user blocks.
A block is summed if it is not null and is not empty. NOTE: that isEmpty() will be called in each block, the behaviour of isEmpty is block dependent

Parameters:
includeUserBlocks - indicates whether or not user defined blocks should be counted
Returns:
an int greater or equal to zero
See Also:
SwiftBlock1.isEmpty(), SwiftBlock2Input.isEmpty(), SwiftBlock2Output.isEmpty(), SwiftTagListBlock.isEmpty(), SwiftTagListBlock.isEmpty(), SwiftTagListBlock.isEmpty()

getBlock1

public SwiftBlock1 getBlock1()
Get block number 1 of this message, may be null if not set

Returns:
the block 1 of the message or null

setBlock1

public void setBlock1(SwiftBlock1 block1)
Set the block 1 of the message

Parameters:
block1 - the content of the block 1

getBlock2

public SwiftBlock2 getBlock2()
Get block number 2 of this message, may be null if not set

Returns:
the block 2 of the message or null

setBlock2

public void setBlock2(SwiftBlock2 block2)
Set the block 2 of the message

Parameters:
block2 - the content of the block 1

getBlock3

public SwiftBlock3 getBlock3()
Get block number 3 of this message, may be null if not set

Returns:
the block 3 of the message or null

setBlock3

public void setBlock3(SwiftBlock3 block3)
Set the block 3 of the message

Parameters:
block3 - the content of the block 1

getBlock4

public SwiftBlock4 getBlock4()
Get block number 4 of this message, may be null if not set

Returns:
the block 4 of the message or null

setBlock4

public void setBlock4(SwiftBlock4 block4)
Set the block 4 of the message

Parameters:
block4 - the content of the block 1

getBlock5

public SwiftBlock5 getBlock5()
Get block number 5 of this message, may be null if not set

Returns:
the block 5 of the message or null

setBlock5

public void setBlock5(SwiftBlock5 block5)
Set the block 5 of the message

Parameters:
block5 - the content of the block 5

getUserBlockPosition

public int getUserBlockPosition(java.lang.String blockName)
Finds the position of a given User Defined Block in the internal list

Parameters:
blockName - the block name to find may be empty or null, in which case this method does nothing
Returns:
the position or -1 if not found
Since:
5.0

getUserBlocks

public java.util.List<SwiftBlockUser> getUserBlocks()
Get the list of List of SwiftBlockUser user defined blocks. The requested object may be null if the message was cleared or not initialized.

Returns:
the list or user blocks or null
Since:
5.0

setUserBlocks

protected void setUserBlocks(java.util.List<SwiftBlockUser> userBlocks)
Set the list of user defined blocks.
This method is mainly needed for persistence services.

Parameters:
userBlocks - the new list of user defined blocks
Throws:
java.lang.IllegalArgumentException - if parameter userBlocks is null
java.lang.IllegalArgumentException - if parameter userBlocks has elements of class other than SwiftBlockUser
Since:
5.0
See Also:
SwiftBlockUser

getUserBlock

public SwiftBlockUser getUserBlock(java.lang.String blockName)
Get a user defined block by name, may be null if not set

Parameters:
blockName - the name of the block to find
Returns:
the requested user defined block or null
Throws:
java.lang.IllegalArgumentException - if parameter blockName is null
java.lang.IllegalArgumentException - if parameter blockName has an invalid block name
Since:
5.0

getUserBlock

public SwiftBlockUser getUserBlock(java.lang.Integer blockNumber)
Get a user defined block by number, may be null if not set

Parameters:
blockNumber - the number of the block to find
Returns:
the requested user defined block or null
Throws:
java.lang.IllegalArgumentException - if parameter userBlock is null
java.lang.IllegalArgumentException - if parameter userBlock has an invalid block name
Since:
5.0

addUserBlock

public void addUserBlock(SwiftBlockUser userBlock)
Add a user defined block to the message (if the block already exists, it is replaced)

Parameters:
userBlock - the user defined block
Throws:
java.lang.IllegalArgumentException - if parameter userBlock is null
java.lang.IllegalArgumentException - if parameter userBlock has an invalid block name
Since:
5.0

removeUserBlock

public void removeUserBlock(java.lang.Integer blockNumber)
removes a user defined block to the message (if the block does not exists, nothing is done)

Parameters:
blockNumber - the block number to remove
Throws:
java.lang.IllegalArgumentException - if parameter blockNumber is null
java.lang.IllegalArgumentException - if parameter blockNumber is invalid
Since:
5.0
See Also:
SwiftBlockUser.isValidName(Integer)

removeUserBlock

public void removeUserBlock(java.lang.String blockName)
removes a user defined block to the message (if the block does not exists, nothing is done)

Parameters:
blockName - the block name to remove
Throws:
java.lang.IllegalArgumentException - if parameter blockName is null
java.lang.IllegalArgumentException - if parameter blockName is invalid
Since:
5.0

clear

public void clear()
remove all blocks from these message, including user blocks


isFragment

public java.lang.Boolean isFragment()
Checks if the message is a fragment

Returns:
true if the message is a fragment
Since:
5.0

isLastFragment

public java.lang.Boolean isLastFragment()
Checks if the message is the last fragment

Returns:
true if the message is the last fragment of a fragmented message
Since:
5.0

fragmentCount

public java.lang.Integer fragmentCount()
Gets the total number of fragments of a fragmented message as informed in tag 203.

Returns:
the total number of fragments or zero if the message is not fragmented
Since:
5.0

fragmentNumber

public java.lang.Integer fragmentNumber()
Gets the number of this fragment

Returns:
the number of this fragment
Throws:
java.lang.UnsupportedOperationException - if the message is not a part of a fragmented message
Since:
5.0

unparsedTextVerify

protected void unparsedTextVerify()
verifies that the unparsed text list exists


getUnparsedTexts

public UnparsedTextList getUnparsedTexts()
returns the unparsed text list

Returns:
the unparsed text attached to this message

setUnparsedTexts

public void setUnparsedTexts(UnparsedTextList texts)
sets the list of unparsed texts

Parameters:
texts - the new list of unparsed texts (may be null)

getUnparsedTextsSize

public java.lang.Integer getUnparsedTextsSize()
returns the size of the unparsed text list

Returns:
the count of unparsed texts attached to this message

unparsedTextIsMessage

public java.lang.Boolean unparsedTextIsMessage(java.lang.Integer index)
decides if a specific text (by index) is likely a SWIFT FIN message. Exceptions are inherited from base implementation methods.

Parameters:
index - the unparsed text number
Returns:
true if the unparsed text at position index is a full SWIFT message
Throws:
java.lang.IllegalArgumentException - if parameter index is null
java.lang.IndexOutOfBoundsException - if parameter index is out of bounds

unparsedTextGetText

public java.lang.String unparsedTextGetText(java.lang.Integer index)
get an unparsed text

Parameters:
index - the unparsed text number
Returns:
the requested text
Throws:
java.lang.IllegalArgumentException - if parameter index is null
java.lang.IndexOutOfBoundsException - if parameter index is out of bounds

unparsedTextGetAsMessage

public SwiftMessage unparsedTextGetAsMessage(java.lang.Integer index)
get an unparsed text as a parsed swift message

Parameters:
index - the unparsed text number
Returns:
the unparsed text at position index parsed into a SwiftMessage object
Throws:
java.lang.IllegalArgumentException - if parameter index is null

unparsedTextAddText

public void unparsedTextAddText(java.lang.String text)
adds a new unparsed text

Parameters:
text - the unparsed text to append
Throws:
java.lang.IllegalArgumentException - if parameter text is null

unparsedTextAddText

public void unparsedTextAddText(SwiftMessage message)
adds a new unparsed text from a message

Parameters:
message - the message to be appended
Throws:
java.lang.IllegalArgumentException - if parameter message is null

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

isCOV

public boolean isCOV()
Checks if the message is a cover payment, based on the content of the User Header (block3).

Returns:
true if tag119:COV is found at User Header (block3)

isSTP

public boolean isSTP()
Checks if the message is Straight Through Processing (STP), based on the content of the User Header (block3).

Returns:
true if tag119:STP is found at User Header (block3)

getSender

public java.lang.String getSender()
Gets the message sender BIC from the message headers. For outgoing messages this is the the logical terminal at block 1, and for incoming messages this is logical terminal at the MIR of block 2.

Returns:
the proper sender address or null if blocks 1 or 2 are not found or incomplete

getReceiver

public java.lang.String getReceiver()
Gets the message receiver BIC from the message headers. For outgoing messages this is the receiver address at block 2, and for incoming messages this is logical terminal at block 1.

Returns:
the proper receiver address or null if blocks 1 or 2 are not found or incomplete

fields

public java.util.List<Field> fields(java.lang.String... names)
Get all fields with the given name in the block 4

Parameters:
names -
Returns:
Throws:
java.lang.IllegalArgumentException - if names is null

removeEmptyBlocks

public void removeEmptyBlocks()
Checks all blocks (1 to 5) and if a block is empty, it is removed from the message.

Since:
6.4

getTypeInt

public int getTypeInt()
get message type as an int or -1 if an error occurrs or it is not set

Returns:
Since:
6.4.1

getDirection

public MessageIOType getDirection()
Returns the message direction from block 2 or null if block 2 is not found or incomplete

Since:
7.0

getPDE

public java.lang.String getPDE()
Gets PDE from the trailer block or null if the trailer or the PDE field is not present

Since:
7.0

getPDM

public java.lang.String getPDM()
Gets PDM from the trailer block or null if the trailer or the PDE field is not present

Since:
7.0

getMIR

public java.lang.String getMIR()
Gets MIR from the application header block or null if the the message is not incoming or the application header block is null

Since:
7.0

getMUR

public java.lang.String getMUR()
Gets MUR from the application header block or null if the the message is not incoming or the application header block is null

Since:
7.0

getUUID

public java.lang.String getUUID()
Gets UUID

Since:
7.0

getParsedSequences

public SequenceNode getParsedSequences()

setParsedSequences

public void setParsedSequences(SequenceNode parsedSequences)