Class AbstractMT
- java.lang.Object
-
- com.prowidesoftware.swift.model.AbstractMessage
-
- com.prowidesoftware.swift.model.mt.AbstractMT
-
- All Implemented Interfaces:
JsonSerializable
- Direct Known Subclasses:
MT008
,MT009
,MT010
,MT011
,MT012
,MT015
,MT019
,MT020
,MT021
,MT022
,MT023
,MT024
,MT025
,MT026
,MT027
,MT028
,MT029
,MT031
,MT032
,MT035
,MT036
,MT037
,MT041
,MT042
,MT043
,MT044
,MT045
,MT046
,MT047
,MT048
,MT049
,MT051
,MT052
,MT055
,MT056
,MT057
,MT061
,MT062
,MT063
,MT064
,MT065
,MT066
,MT067
,MT068
,MT069
,MT070
,MT071
,MT072
,MT073
,MT074
,MT077
,MT081
,MT082
,MT083
,MT090
,MT092
,MT094
,MT096
,MT097
,MT101
,MT102
,MT102_STP
,MT103
,MT103_REMIT
,MT103_STP
,MT104
,MT105
,MT107
,MT110
,MT111
,MT112
,MT190
,MT191
,MT192
,MT195
,MT196
,MT198
,MT199
,MT200
,MT201
,MT202
,MT202COV
,MT203
,MT204
,MT205
,MT205COV
,MT210
,MT290
,MT291
,MT292
,MT295
,MT296
,MT298
,MT299
,MT300
,MT304
,MT305
,MT306
,MT320
,MT321
,MT330
,MT340
,MT341
,MT350
,MT360
,MT361
,MT362
,MT364
,MT365
,MT370
,MT380
,MT381
,MT390
,MT391
,MT392
,MT395
,MT396
,MT398
,MT399
,MT400
,MT410
,MT412
,MT416
,MT420
,MT422
,MT430
,MT450
,MT455
,MT456
,MT490
,MT491
,MT492
,MT495
,MT496
,MT498
,MT499
,MT500
,MT501
,MT502
,MT503
,MT504
,MT505
,MT506
,MT507
,MT508
,MT509
,MT510
,MT513
,MT514
,MT515
,MT516
,MT517
,MT518
,MT519
,MT524
,MT526
,MT527
,MT530
,MT535
,MT536
,MT537
,MT538
,MT540
,MT541
,MT542
,MT543
,MT544
,MT545
,MT546
,MT547
,MT548
,MT549
,MT558
,MT564
,MT565
,MT566
,MT567
,MT568
,MT569
,MT575
,MT576
,MT578
,MT581
,MT586
,MT590
,MT591
,MT592
,MT595
,MT596
,MT598
,MT599
,MT600
,MT601
,MT604
,MT605
,MT606
,MT607
,MT608
,MT620
,MT670
,MT671
,MT690
,MT691
,MT692
,MT695
,MT696
,MT698
,MT699
,MT700
,MT701
,MT705
,MT707
,MT708
,MT710
,MT711
,MT720
,MT721
,MT730
,MT732
,MT734
,MT740
,MT742
,MT744
,MT747
,MT750
,MT752
,MT754
,MT756
,MT759
,MT760
,MT761
,MT765
,MT767
,MT768
,MT769
,MT775
,MT785
,MT786
,MT787
,MT790
,MT791
,MT792
,MT795
,MT796
,MT798
,MT799
,MT801
,MT802
,MT890
,MT891
,MT892
,MT895
,MT896
,MT898
,MT899
,MT900
,MT910
,MT920
,MT935
,MT940
,MT941
,MT942
,MT950
,MT970
,MT971
,MT972
,MT973
,MT985
,MT986
,MT990
,MT991
,MT992
,MT995
,MT996
,MT998
,MT999
,ServiceMessage21
public abstract class AbstractMT extends AbstractMessage implements JsonSerializable
Base class for specific MTs.
This class implements several high level delegate methods of SwiftMessage.- Since:
- 6.0
-
-
Field Summary
Fields Modifier and Type Field Description protected SwiftMessage
m
The internal swift message.
-
Constructor Summary
Constructors Constructor Description AbstractMT()
Creates a particular MT initialized with a new SwiftMessage.AbstractMT(int messageType)
Create an input message for the given type setting TEST BICS as sender and receiver.
All mandatory header attributes are completed with default values.AbstractMT(int messageType, java.lang.String sender, java.lang.String receiver)
Creates a new input message for the given type setting the given sender and receiver.
All mandatory header attributes are completed with default values.AbstractMT(SwiftMessage m)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addField(Field f)
Adds the given field to the body block in the last positionAbstractMT
append(Field... fields)
Add all the fields to the end of the block4AbstractMT
append(SwiftTagListBlock block)
Add all tags from block to the end of the block4AbstractMT
append(Tag... tags)
Add all tags to the end of the block4boolean
containsSequence(java.lang.String name)
Test if the MT class contains a getSequenceX methodboolean
containsSequenceList(java.lang.String name)
Test if the MT class contains a getSequenceXList methodstatic AbstractMT
create(int messageType)
Create a blank message for the given category setting TEST bics as sender and receiverstatic AbstractMT
create(int messageType, java.lang.String sender, java.lang.String receiver)
Create a blank message for the given category setting the given sender and receiver BICsstatic AbstractMT
fromJson(java.lang.String json)
This method deserializes the JSON data into a specific MT object.java.lang.String
getApplicationId()
java.util.List<Field>
getFields()
Gets the block 4 complete ordered list of fieldsjava.lang.String
getLogicalTerminal()
java.lang.String
getMessagePriority()
abstract java.lang.String
getMessageType()
Returns this message type according to the specific class.MtId
getMtId()
Returns the MT message identification.
Composed by the business process, message type and variant.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.static SwiftTagListBlock
getSequence(SwiftMessage msg, java.lang.String sequence)
Deprecated.Usemsg.toMT().getSequence(sequence)
instead of this methodSwiftTagListBlock
getSequence(java.lang.String name)
Convenience method to get a sequence namedname
from this message without creating the MTXXX class.SwiftTagListBlock
getSequence(java.lang.String name, SwiftTagListBlock block)
Get the sequence with the given name from the tags in block invoking the proper static method in the mt classjava.util.List<SwiftTagListBlock>
getSequenceList(java.lang.String name)
Convenience method to get the list of sequences namedname
from this message without creating the MTXXX class.java.util.List<SwiftTagListBlock>
getSequenceList(java.lang.String name, SwiftTagListBlock block)
Get the sequence with a given name from the given subblockjava.lang.String
getSequenceNumber()
java.lang.String
getServiceId()
java.lang.String
getSessionNumber()
java.lang.String
getSignature()
Gets the signature of the message (looks for an S block then the MDG tag)SwiftMessage
getSwiftMessage()
protected SwiftMessage
getSwiftMessageNotNullOrException()
Get the swift message guaranteeing a non null return.MTVariant
getVariant()
boolean
isIncoming()
boolean
isInput()
boolean
isOutgoing()
boolean
isOutput()
boolean
isType(java.lang.Integer type)
Returns true if the message is the same type as the indicated by parameter.java.lang.String
message()
Get this message as string containing the FIN message (SWIFT MT message).java.lang.String
nameFromClass()
Derives the message name (substring after.MT
) from the class name.static AbstractMT
parse(java.io.File file)
Parses a the file content into the MTxxx that corresponds to the found message type.static AbstractMT
parse(java.io.InputStream stream)
Parses a the stream content into the MTxxx that corresponds to the found message type.static AbstractMT
parse(java.lang.String fin)
Parses a the string content into the MTxxx that corresponds to the found message type.protected static SwiftMessage
read(java.lang.String fin)
Base implementation for subclasses static parse.void
setReceiver(BIC bic)
Sets the logical terminal field of the application header block 2.void
setReceiver(java.lang.String receiver)
Sets the logical terminal field of the application header block 2.void
setSender(BIC bic)
Sets the logical terminal field of the header block 1 with the parameter BIC code and default LT identifier (the message is assumed to be of type input).void
setSender(java.lang.String sender)
Sets the logical terminal field of the header block 1 (the message is assumed to be of type input).AbstractMT
setSignature(java.lang.String signature)
Sets the signature to the messagevoid
setSwiftMessage(SwiftMessage m)
protected Tag
tag(java.lang.String tagName)
Returns a tag or null if tag not foundprotected Tag[]
tags(java.lang.String tagName)
Returns an array of tags or null if non is foundjava.lang.String
toJson()
Get a json representation of this message with expanded fields content.java.lang.String
toString()
void
write(java.io.File file)
Writes the message into a file with its message content in the FIN format.void
write(java.io.OutputStream stream)
Writes the message into a given output stream with its message content in the FIN format, encoding content in UTF-8.java.lang.String
xml()
Returns the message content in XML format.
The XML created is the internal format defined and used by Prowide Core.
Notice: it is neither a standard nor the MX version of this MT.-
Methods inherited from class com.prowidesoftware.swift.model.AbstractMessage
getMessageStandardType, isMT, isMX
-
-
-
-
Field Detail
-
m
protected SwiftMessage m
The internal swift message.
-
-
Constructor Detail
-
AbstractMT
public AbstractMT(SwiftMessage m)
- Parameters:
m
- swift message to model as a particular MT
-
AbstractMT
public AbstractMT()
Creates a particular MT initialized with a new SwiftMessage. All blocks are initialized.
-
AbstractMT
public AbstractMT(int messageType)
Create an input message for the given type setting TEST BICS as sender and receiver.
All mandatory header attributes are completed with default values.- Parameters:
messageType
- the message type- Since:
- 7.6
- See Also:
AbstractMT(int, String, String)
-
AbstractMT
public AbstractMT(int messageType, java.lang.String sender, java.lang.String receiver)
Creates a new input message for the given type setting the given sender and receiver.
All mandatory header attributes are completed with default values. In particular the sender and receiver addresses will be filled with proper default LT identifier and branch codes if not provided. For the message type, if the indicated number is below 100 the category 0 will be assumed (meaning 10 will be set as 010).- Parameters:
messageType
- message type to createsender
- the sender address as a bic8, bic11 or full logical terminal consisting of 12 charactersreceiver
- the receiver address as a bic8, bic11 or full logical terminal consisting of 12 characters- Since:
- 7.6
-
-
Method Detail
-
parse
public static AbstractMT parse(java.lang.String fin) throws java.io.IOException
Parses a the string content into the MTxxx that corresponds to the found message type. If the file contains more than a message it will parse the first one. If the string is empty, does not contain any MT message, the message type is not set or an error occurs reading and parsing the message content; this method returns null.- Parameters:
fin
- string a string containing a swift MT message- Returns:
- parser message or null if string content could not be parsed
- Throws:
java.io.IOException
- if the message content cannot be read- Since:
- 7.7
-
parse
public static AbstractMT parse(java.io.InputStream stream) throws java.io.IOException
Parses a the stream content into the MTxxx that corresponds to the found message type.- Parameters:
stream
- a stream containing a swift MT message- Returns:
- parser message or null if stream content could not be parsed
- Throws:
java.io.IOException
- if the stream content cannot be read- Since:
- 7.7
- See Also:
parse(String)
-
parse
public static AbstractMT parse(java.io.File file) throws java.io.IOException
Parses a the file content into the MTxxx that corresponds to the found message type.- Parameters:
file
- a file containing a swift MT message- Returns:
- parser message or null if file content could not be parsed
- Throws:
java.io.IOException
- if the file content cannot be read- Since:
- 7.7
- See Also:
parse(String)
-
create
public static AbstractMT create(int messageType)
Create a blank message for the given category setting TEST bics as sender and receiver- Parameters:
messageType
- the message type- Returns:
- created message object
- Since:
- 7.6
- See Also:
create(int, String, String)
-
create
public static AbstractMT create(int messageType, java.lang.String sender, java.lang.String receiver)
Create a blank message for the given category setting the given sender and receiver BICs- Parameters:
messageType
- the message typesender
- the sender BIC11 codereceiver
- the receiver BIC11 code- Returns:
- created message object
- Since:
- 7.6
-
read
protected static SwiftMessage read(java.lang.String fin)
Base implementation for subclasses static parse.- Parameters:
fin
- the plain MT content to parse- Returns:
- the parsed message or null if content cannot be parsed
- Since:
- 7.7
-
getSequence
@Deprecated public static SwiftTagListBlock getSequence(SwiftMessage msg, java.lang.String sequence)
Deprecated.Usemsg.toMT().getSequence(sequence)
instead of this methodGet the given sequence from the msg- Parameters:
msg
- the message to extract the sequence fromsequence
- the sequence name- Returns:
- the given sequence or null if msg is null, sequence is null or the message can not be converted to MT
- Since:
- 7.7
- See Also:
SwiftMessage.toMT()
-
fromJson
public static AbstractMT fromJson(java.lang.String json)
This method deserializes the JSON data into a specific MT object.- Parameters:
json
- a JSON representation of an MT message- Returns:
- a specific deserialized MT message object, for example MT103
- Since:
- 7.10.3
-
getSwiftMessage
public SwiftMessage getSwiftMessage()
- Returns:
- the swift message object modeled as this particular MT
-
setSwiftMessage
public void setSwiftMessage(SwiftMessage m)
- Parameters:
m
- swift message to model as a particular MT
-
getSwiftMessageNotNullOrException
protected SwiftMessage getSwiftMessageNotNullOrException()
Get the swift message guaranteeing a non null return. If the message is null an illegal state exception is thrown- Returns:
- the swift message set
- Since:
- 7.7
-
getApplicationId
public java.lang.String getApplicationId()
- Returns:
- application id from block 1
- See Also:
SwiftBlock1.getApplicationId()
-
getServiceId
public java.lang.String getServiceId()
- Returns:
- service id from block 1
- See Also:
SwiftBlock1.getServiceId()
-
getLogicalTerminal
public java.lang.String getLogicalTerminal()
- Returns:
- logical terminal from block 1
- See Also:
SwiftBlock1.getLogicalTerminal()
-
getSessionNumber
public java.lang.String getSessionNumber()
- Returns:
- session number from block 1
- See Also:
SwiftBlock1.getSessionNumber()
-
getSequenceNumber
public java.lang.String getSequenceNumber()
- Returns:
- sequence number from block 1
- See Also:
SwiftBlock1.getSequenceNumber()
-
getMessagePriority
public java.lang.String getMessagePriority()
- Returns:
- message priority from block 2
- See Also:
SwiftBlock2.getMessagePriority()
-
isInput
public boolean isInput()
- Returns:
- true if message is an input message sent to SWIFTNet, false otherwise
- See Also:
SwiftMessage.isOutgoing()
-
isOutgoing
public boolean isOutgoing()
- Returns:
- true if the message is outgoing (sent to SWIFT), false other case; using the direction attribute.
- Since:
- 7.8.4
- See Also:
SwiftMessage.isOutgoing()
-
isOutput
public boolean isOutput()
- Returns:
- true if message is an output message received from SWIFTNet, false otherwise
- See Also:
SwiftMessage.isIncoming()
-
isIncoming
public boolean isIncoming()
- Returns:
- true if the message is incoming (received from SWIFT), false other case; using the direction attribute.
- Since:
- 7.8.4
- See Also:
SwiftMessage.isIncoming()
-
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 found address or null if the message or the header block are null.
- Since:
- 6.4
-
setSender
public void setSender(java.lang.String sender)
Sets the logical terminal field of the header block 1 (the message is assumed to be of type input). The sender addresses will be filled with proper default LT identifier and branch codes if not provided.
Notice this method only makes sense when building input messages (messages that are going to be sent to swift). To emulate a received message from swift, the sender information must be put at block 2.
- Parameters:
sender
- the sender address as a bic8, bic11 or full logical terminal consisting of 12 characters- Since:
- 6.4
- See Also:
SwiftBlock1.setSender(String)
-
setSender
public void setSender(BIC bic)
Sets the logical terminal field of the header block 1 with the parameter BIC code and default LT identifier (the message is assumed to be of type input).
Notice this method only makes sense when building input messages (messages that are going to be sent to swift). To emulate a received message from swift, the sender information must be put at block 2.
- Parameters:
bic
- a BIC code- Since:
- 6.4
- See Also:
SwiftBlock1.setLogicalTerminal(BIC)
-
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 found BIC code of the sender or null if the message or the header block are null.
- Since:
- 6.4
-
setReceiver
public void setReceiver(java.lang.String receiver)
Sets the logical terminal field of the application header block 2. The receiver addresses will be filled with proper default LT identifier and branch codes if not provided.
Notice this method only makes sense when building input messages (messages that are going to be sent to swift). To emulate a received message from swift, a call to this method has no effect, and the receiver information must be manually set in block 1.
- Parameters:
receiver
- the sender address as a bic8, bic11 or full logical terminal consisting of 12 characters- Since:
- 6.4
- See Also:
SwiftBlock2Input.setReceiver(String)
-
setReceiver
public void setReceiver(BIC bic)
Sets the logical terminal field of the application header block 2.
Notice this method only makes sense when building input messages (messages that are going to be sent to swift). To emulate a received message from swift, a call to this method has no effect, and the receiver information must be manually set in block 1.
- Parameters:
bic
- a BIC code- Since:
- 6.4
- See Also:
SwiftBlock2Input.setReceiver(String)
-
addField
public void addField(Field f)
Adds the given field to the body block in the last position- Parameters:
f
- a field to add
-
message
public java.lang.String message()
Get this message as string containing the FIN message (SWIFT MT message).- Specified by:
message
in classAbstractMessage
- Returns:
- a string with the FIN format representation of the message
- Since:
- 7.7
-
getMessageType
public abstract java.lang.String getMessageType()
Returns this message type according to the specific class.- Returns:
- the message type number of this MT
- Since:
- 6.4
-
getSequenceList
public java.util.List<SwiftTagListBlock> getSequenceList(java.lang.String name)
Convenience method to get the list of sequences namedname
from this message without creating the MTXXX class.getSequenceList("A")
is the same as((CastToSpecificMT)getMT()).getSequenceAList()
The requested sequence must be repetitive for non repetitive sequences use getSequence(name)- Parameters:
name
- the sequence alpha numeric identifier such as A1a- Returns:
- found sequences or empty list
- Since:
- 7.6
- See Also:
getSequence(String)
-
getSequenceList
public java.util.List<SwiftTagListBlock> getSequenceList(java.lang.String name, SwiftTagListBlock block)
Get the sequence with a given name from the given subblock- Parameters:
name
- the name of the sequence to get. Must not be nullblock
- the block from where to get the sequenceThis method invokes the static version of
getSequenceList(String)
- Returns:
- found sequences or empty list
- Since:
- 7.8.1
- See Also:
getSequenceList(String)
-
containsSequenceList
public boolean containsSequenceList(java.lang.String name)
Test if the MT class contains a getSequenceXList method- Parameters:
name
- the sequence alpha numeric identifier such as A1a- Returns:
- found sequences or empty list
- Since:
- 7.8
- See Also:
getSequenceList(String)
-
containsSequence
public boolean containsSequence(java.lang.String name)
Test if the MT class contains a getSequenceX method- Parameters:
name
- the sequence alpha numeric identifier such as A1a- Returns:
- found sequences or empty list
- Since:
- 7.8
- See Also:
getSequence(String)
-
getSequence
public SwiftTagListBlock getSequence(java.lang.String name)
Convenience method to get a sequence namedname
from this message without creating the MTXXX class.getSequence("A")
is the same as((CastToSpecificMT)getMT()).getSequenceA()
The requested sequence must NOT be repetitive for repetitive sequences use getSequenceList(name)- Parameters:
name
- the sequence alpha numeric identifier such as A1a- Returns:
- found sequence or empty sequence block
- Since:
- 7.6
- See Also:
getSequenceList(String)
-
getSequence
public SwiftTagListBlock getSequence(java.lang.String name, SwiftTagListBlock block)
Get the sequence with the given name from the tags in block invoking the proper static method in the mt class- Parameters:
name
- the name of the sequence to getblock
- the block where to extract the sequence from- Returns:
- found sequence or empty sequence block
- Since:
- 7.8.1
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getSignature
public java.lang.String getSignature()
Gets the signature of the message (looks for an S block then the MDG tag)- Returns:
- the signature of the message (or null if none exists)
- Since:
- 7.10.4
-
setSignature
public AbstractMT setSignature(java.lang.String signature)
Sets the signature to the message- Parameters:
signature
- the signature to set in block S- Returns:
this
- Throws:
java.lang.IllegalStateException
- if the internal SwiftMessage object is null- Since:
- 7.10.4
-
append
public AbstractMT append(SwiftTagListBlock block)
Add all tags from block to the end of the block4- Parameters:
block
- a block to append- Returns:
- this same object for chained calls
- Since:
- 7.6
-
append
public AbstractMT append(Tag... tags)
Add all tags to the end of the block4- Parameters:
tags
- a list of tags to add- Returns:
- this same object for chained calls
- Since:
- 7.6
-
append
public AbstractMT append(Field... fields)
Add all the fields to the end of the block4- Parameters:
fields
- a list of fields to add- Returns:
- this same object for chained calls
- Since:
- 7.6
-
write
public void write(java.io.File file) throws java.io.IOException
Writes the message into a file with its message content in the FIN format.The implementation ignores all empty blocks.
- Parameters:
file
- a not null file to write, if it does not exists, it will be created- Throws:
java.io.IOException
- if the file cannot be written- Since:
- 7.7
-
write
public void write(java.io.OutputStream stream) throws java.io.IOException
Writes the message into a given output stream with its message content in the FIN format, encoding content in UTF-8.- Parameters:
stream
- a non null stream to write- Throws:
java.io.IOException
- if the stream cannot be written- Since:
- 7.7
-
xml
public java.lang.String xml()
Returns the message content in XML format.
The XML created is the internal format defined and used by Prowide Core.
Notice: it is neither a standard nor the MX version of this MT.- Returns:
- message content xml
- Since:
- 7.7
-
isType
public boolean isType(java.lang.Integer type)
Returns true if the message is the same type as the indicated by parameter.- Parameters:
type
- a three digits number indicating a SWIFT MT type- Returns:
- true if the message is the same type, false if not or if the message type cannot be determined.
- Since:
- 7.7
-
getVariant
public MTVariant getVariant()
- Returns:
- the corresponding MT variant or null if flag field is not present
- Since:
- 7.8
-
nameFromClass
public java.lang.String nameFromClass()
Derives the message name (substring after.MT
) from the class name.- Returns:
- message name
-
getMtId
public MtId getMtId()
Returns the MT message identification.
Composed by the business process, message type and variant. Example: fin.103.STP- Returns:
- the constructed message id
- Since:
- 7.8.4
-
tag
protected Tag tag(java.lang.String tagName)
Returns a tag or null if tag not found- Parameters:
tagName
- tag name to find including letter option, example "33B"- Returns:
- found tag or null
- Since:
- 7.8.9
-
tags
protected Tag[] tags(java.lang.String tagName)
Returns an array of tags or null if non is found- Parameters:
tagName
- tag name to find including letter option, example "33B"- Returns:
- found tags or null
- Since:
- 7.8.9
-
toJson
public java.lang.String toJson()
Get a json representation of this message with expanded fields content.- Specified by:
toJson
in interfaceJsonSerializable
- Returns:
- the message content as JSON
- Since:
- 7.10.3
-
getFields
public java.util.List<Field> getFields()
Gets the block 4 complete ordered list of fields- Returns:
- return a list of Tag as a FieldNN instance or empty list if non is found
- Since:
- 7.10.3
-
-