Class AbstractMT

    • 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 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.
      static SwiftTagListBlock getSequence​(SwiftMessage msg, java.lang.String sequence)
      Deprecated.
      Use msg.toMT().getSequence(sequence) instead of this method
      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
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

    • 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 create
        sender - the sender address as a bic8, bic11 or full logical terminal consisting of 12 characters
        receiver - 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 type
        sender - the sender BIC11 code
        receiver - 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.
        Use msg.toMT().getSequence(sequence) instead of this method
        Get the given sequence from the msg
        Parameters:
        msg - the message to extract the sequence from
        sequence - 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
      • 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 class AbstractMessage
        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 named 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)
        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 null
        block - the block from where to get the sequence

        This 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 named 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)
        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 get
        block - 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 class java.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 interface JsonSerializable
        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