public abstract class AbstractMT extends AbstractMessage implements JsonSerializable
Modifier and Type | Field and Description |
---|---|
protected SwiftMessage |
m
The internal swift message.
|
Constructor and 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) |
Modifier and Type | Method and Description |
---|---|
void |
addField(Field f)
Adds the given field to the body block in the last position
|
AbstractMT |
append(Field... fields)
Add all the fields to the end of the block4
|
AbstractMT |
append(SwiftTagListBlock block)
Add all tags from block to the end of the block4
|
AbstractMT |
append(Tag... tags)
Add all tags to the end of the block4
|
boolean |
containsSequence(java.lang.String name)
Test if the MT class contains a getSequenceX method
|
boolean |
containsSequenceList(java.lang.String name)
Test if the MT class contains a getSequenceXList method
|
static AbstractMT |
create(int messageType)
Create a blank message for the given category setting TEST bics as sender and receiver
|
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
|
static 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 fields
|
java.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.
|
SwiftTagListBlock |
getSequence(java.lang.String name)
Convenience method to get a sequence named
name 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 class
|
static SwiftTagListBlock |
getSequence(SwiftMessage msg,
java.lang.String sequence)
Deprecated.
Use
msg.toMT().getSequence(sequence) instead of this method |
java.util.List<SwiftTagListBlock> |
getSequenceList(java.lang.String name)
Convenience method to get the list of sequences named
name 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 subblock
|
java.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 message
|
void |
setSwiftMessage(SwiftMessage m) |
protected Tag |
tag(java.lang.String tagName)
Returns a tag or null if tag not found
|
protected Tag[] |
tags(java.lang.String tagName)
Returns an array of tags or null if non is found
|
java.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. |
getMessageStandardType, isMT, isMX
protected SwiftMessage m
public AbstractMT(SwiftMessage m)
m
- swift message to model as a particular MTpublic AbstractMT()
public AbstractMT(int messageType)
messageType
- the message typeAbstractMT(int, String, String)
public AbstractMT(int messageType, java.lang.String sender, java.lang.String receiver)
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 characterspublic static AbstractMT parse(java.lang.String fin) throws java.io.IOException
fin
- string a string containing a swift MT messagejava.io.IOException
- if the message content cannot be readpublic static AbstractMT parse(java.io.InputStream stream) throws java.io.IOException
stream
- a stream containing a swift MT messagejava.io.IOException
- if the stream content cannot be readparse(String)
public static AbstractMT parse(java.io.File file) throws java.io.IOException
file
- a file containing a swift MT messagejava.io.IOException
- if the file content cannot be readparse(String)
public static AbstractMT create(int messageType)
messageType
- the message typecreate(int, String, String)
public static AbstractMT create(int messageType, java.lang.String sender, java.lang.String receiver)
messageType
- the message typesender
- the sender BIC11 codereceiver
- the receiver BIC11 codeprotected static SwiftMessage read(java.lang.String fin)
fin
- the plain MT content to parse@Deprecated public static SwiftTagListBlock getSequence(SwiftMessage msg, java.lang.String sequence)
msg.toMT().getSequence(sequence)
instead of this methodmsg
- the message to extract the sequence fromsequence
- the sequence nameSwiftMessage.toMT()
public static AbstractMT fromJson(java.lang.String json)
json
- a JSON representation of an MT messagepublic SwiftMessage getSwiftMessage()
public void setSwiftMessage(SwiftMessage m)
m
- swift message to model as a particular MTprotected SwiftMessage getSwiftMessageNotNullOrException()
public java.lang.String getApplicationId()
SwiftBlock1.getApplicationId()
public java.lang.String getServiceId()
SwiftBlock1.getServiceId()
public java.lang.String getLogicalTerminal()
SwiftBlock1.getLogicalTerminal()
public java.lang.String getSessionNumber()
SwiftBlock1.getSessionNumber()
public java.lang.String getSequenceNumber()
SwiftBlock1.getSequenceNumber()
public java.lang.String getMessagePriority()
SwiftBlock2.getMessagePriority()
public boolean isInput()
SwiftMessage.isOutgoing()
public boolean isOutgoing()
SwiftMessage.isOutgoing()
public boolean isOutput()
SwiftMessage.isIncoming()
public boolean isIncoming()
SwiftMessage.isIncoming()
public java.lang.String getSender()
public void setSender(java.lang.String sender)
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.
sender
- the sender address as a bic8, bic11 or full logical terminal consisting of 12 charactersSwiftBlock1.setSender(String)
public void setSender(BIC bic)
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.
bic
- a BIC codeSwiftBlock1.setLogicalTerminal(BIC)
public java.lang.String getReceiver()
public void setReceiver(java.lang.String receiver)
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.
receiver
- the sender address as a bic8, bic11 or full logical terminal consisting of 12 charactersSwiftBlock2Input.setReceiver(String)
public void setReceiver(BIC bic)
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.
bic
- a BIC codeSwiftBlock2Input.setReceiver(String)
public void addField(Field f)
f
- a field to addpublic java.lang.String message()
message
in class AbstractMessage
public abstract java.lang.String getMessageType()
public java.util.List<SwiftTagListBlock> getSequenceList(java.lang.String name)
name
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)name
- the sequence alpha numeric identifier such as A1agetSequence(String)
public java.util.List<SwiftTagListBlock> getSequenceList(java.lang.String name, SwiftTagListBlock block)
name
- the name of the sequence to get. Must not be nullblock
- the block from where to get the sequence
This method invokes the static version of getSequenceList(String)
getSequenceList(String)
public boolean containsSequenceList(java.lang.String name)
name
- the sequence alpha numeric identifier such as A1agetSequenceList(String)
public boolean containsSequence(java.lang.String name)
name
- the sequence alpha numeric identifier such as A1agetSequence(String)
public SwiftTagListBlock getSequence(java.lang.String name)
name
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)name
- the sequence alpha numeric identifier such as A1agetSequenceList(String)
public SwiftTagListBlock getSequence(java.lang.String name, SwiftTagListBlock block)
name
- the name of the sequence to getblock
- the block where to extract the sequence frompublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getSignature()
public AbstractMT setSignature(java.lang.String signature)
signature
- the signature to set in block Sthis
java.lang.IllegalStateException
- if the internal SwiftMessage object is nullpublic AbstractMT append(SwiftTagListBlock block)
block
- a block to appendpublic AbstractMT append(Tag... tags)
tags
- a list of tags to addpublic AbstractMT append(Field... fields)
fields
- a list of fields to addpublic void write(java.io.File file) throws java.io.IOException
The implementation ignores all empty blocks.
file
- a not null file to write, if it does not exists, it will be createdjava.io.IOException
- if the file cannot be writtenpublic void write(java.io.OutputStream stream) throws java.io.IOException
stream
- a non null stream to writejava.io.IOException
- if the stream cannot be writtenpublic java.lang.String xml()
public boolean isType(java.lang.Integer type)
type
- a three digits number indicating a SWIFT MT typepublic MTVariant getVariant()
public java.lang.String nameFromClass()
.MT
) from the class name.public MtId getMtId()
protected Tag tag(java.lang.String tagName)
tagName
- tag name to find including letter option, example "33B"protected Tag[] tags(java.lang.String tagName)
tagName
- tag name to find including letter option, example "33B"public java.lang.String toJson()
toJson
in interface JsonSerializable
public java.util.List<Field> getFields()