Class SwiftBlock2Input

  • All Implemented Interfaces:
    java.io.Serializable

    public class SwiftBlock2Input
    extends SwiftBlock2
    implements java.io.Serializable
    Base class for SWIFT Application Header Block (block 2) for INPUT (to SWIFT).
    This block is used to construct messages that are going to be input to the SWIFT network. From the application point of view, it correspond to the SENT messages.

    It's value is fixed-length and continuous with no field delimiters. This class contains its elements as individual attributes for easier management of the block value.

    This class does not provide explicit API to get the MIR of an outgoing message because it should be created using the session and sequence numbers at header block 1, and this information is not usually generated by the application creating the message but by the SWIFT Alliance interface. Therefore neither SwiftBLock1 or SwiftBlock2Input provide a getter for the MIR.
    It also does not provide any API to get the MOR of a sent message because that information will be available only when the message is delivered at destination.

    Since:
    4.0
    See Also:
    MIR, Serialized Form
    • Constructor Detail

      • SwiftBlock2Input

        public SwiftBlock2Input​(java.lang.String messageType,
                                java.lang.String receiverAddress,
                                java.lang.String messagePriority,
                                java.lang.String deliveryMonitoring,
                                java.lang.String obsolescencePeriod)
        Constructor for specific values
        Parameters:
        messageType - the message type
        receiverAddress - the receiver address
        messagePriority - the message priority (S=system, U=urgent, N=normal)
        deliveryMonitoring - the delivery monitoring option (1 or 3 for U priority, 2 for N priority)
        obsolescencePeriod - the obsolescence period, measured in 5 minutes units (3 for priority U, 20 for priority N).
        According to SWIFT documentation, this value is ignored by the system
      • SwiftBlock2Input

        public SwiftBlock2Input​(java.lang.String value)
        Creates the block with lenient false, meaning it expects a fixed length value. Example of supported values:
        "I100BANKDEFFXXXXU3003" (21) or "2:I100BANKDEFFXXXXU3003" (23) "I100BANKDEFFXXXXU3" (18) or "2:I100BANKDEFFXXXXU3" (20) "I100BANKDEFFXXXXU" (17) or "2:I100BANKDEFFXXXXU" (19)
        Parameters:
        value - a string with length between 16 and 23 containing the blocks value
        Throws:
        java.lang.IllegalArgumentException - if parameter has an invalid total size
        See Also:
        setValue(String, boolean)
      • SwiftBlock2Input

        public SwiftBlock2Input​(java.lang.String value,
                                boolean lenient)
        Creates a block 2 output object setting attributes by parsing the string argument containing the blocks value. This value can be in different flavors because some fields are optional.
        Parameters:
        value - string containing the entire blocks value
        lenient - if true the value will be parsed with a best effort heuristic, if false it will throw a IllegalArgumentException if the value has an invalid total size
        Since:
        7.7
        See Also:
        setValue(String, boolean)
      • SwiftBlock2Input

        public SwiftBlock2Input()
        Default constructor
      • SwiftBlock2Input

        public SwiftBlock2Input​(SwiftBlock2Input block)
        Copy constructor
        Parameters:
        block - an existing block2 to copy
        Since:
        7.10.4
    • Method Detail

      • fromJson

        public static SwiftBlock2Input fromJson​(java.lang.String json)
        This method deserializes the JSON data into an outgoing (input) block 2 object.
        Parameters:
        json - JSON representation
        Returns:
        block 2 object
        Since:
        7.9.8
        See Also:
        SwiftBlock2.toJson()
      • getMessageType

        public java.lang.String getMessageType()
        Description copied from class: SwiftBlock2
        Gets the Message Type (MT) as classified and numbered by SWIFT.
        Overrides:
        getMessageType in class SwiftBlock2
        Returns:
        messageType String of 3 character
      • setMessageType

        public void setMessageType​(java.lang.String messageType)
        Sets the Message Type (MT) as classified and numbered by SWIFT. Three-digit FIN message type, example: 103
        Overrides:
        setMessageType in class SwiftBlock2
        Parameters:
        messageType - String of 3 character
      • setReceiver

        public void setReceiver​(BIC bic)
        Creates a full LT address using the parameter BIC code and a default LT identifier.
        Parameters:
        bic - receiver
        Since:
        7.6
        See Also:
        setReceiverAddress(LogicalTerminalAddress)
      • setReceiver

        public void setReceiver​(java.lang.String receiver)
        Completes if necessary and sets the LT address of the receiver.
        The receiver addresses will be filled with proper default LT identifier and branch codes if not provided.
        Parameters:
        receiver - receiver
        Since:
        7.6
        See Also:
        setReceiverAddress(LogicalTerminalAddress)
      • getReceiverAddress

        public java.lang.String getReceiverAddress()
        Gets the LT receiver's address field in block 2 input
        Returns:
        receiver address
      • setReceiverAddress

        public void setReceiverAddress​(java.lang.String receiverAddress)
        Sets the receiver's address.
        It is fixed at 12 characters; it must have X in position 9 (padded with "X" if no branch is required).
        Parameters:
        receiverAddress - 12 characters String
      • getReceiverBIC

        public BIC getReceiverBIC()
        Gets the receiver's BIC code from the receiver LT address.
        Returns:
        receiver BIC address
        Since:
        7.6
        See Also:
        BIC
      • getMessagePriority

        public java.lang.String getMessagePriority()
        Gets the the message priority field in block 2 input
        Overrides:
        getMessagePriority in class SwiftBlock2
        Returns:
        message priority
      • setMessagePriority

        public void setMessagePriority​(java.lang.String messagePriority)
        Sets the message priority as follows:
        S = System
        N = Normal
        U = Urgent
        Overrides:
        setMessagePriority in class SwiftBlock2
        Parameters:
        messagePriority - String of 1 character
      • getDeliveryMonitoring

        public java.lang.String getDeliveryMonitoring()
        Gets the Delivery Monitoring field in block 2 input
        Returns:
        the delivery monitoring
      • setDeliveryMonitoring

        public void setDeliveryMonitoring​(java.lang.String deliveryMonitoring)
        Sets the Delivery Monitoring field is as follows:
        1 = Non-Delivery Warning
        2 = Delivery Notification
        3 = Both valid, Non-Delivery Warning and Delivery Notification
        This value is optional.
        If the priority is U, delivery monitoring must be: 1 or 3.
        If the priority is N, delivery monitoring must be: 2 or not included.
        Parameters:
        deliveryMonitoring - String of 1 character containing the Delivery Monitoring field
      • getDeliveryMonitoringType

        public SwiftBlock2Input.DeliveryMonitoring getDeliveryMonitoringType()
        Gets the delivery monitoring as enum
        Returns:
        delivery monitoring enum value or null if the delivery monitoring is not set or contains an invalid value
        Since:
        7.8.4
      • getObsolescencePeriod

        public java.lang.String getObsolescencePeriod()
        Gets the obsolescence period field in block 2 input
        Returns:
        the obsolescence period
      • setObsolescencePeriod

        public void setObsolescencePeriod​(java.lang.String obsolescencePeriod)
        Sets the Obsolescence Period.
        It specifies when a non-delivery notification is generated as follows:
        Valid for U = 003 (15 minutes)
        Valid for N = 020 (100 minutes)
        This value is optional.
        Parameters:
        obsolescencePeriod - String of 3 characters containing the Obsolescence Period
      • isEmpty

        public boolean isEmpty()
        Tell if this block is empty or not. This block is considered to be empty if all its attributes are set to null.
        Overrides:
        isEmpty in class SwiftValueBlock
        Returns:
        true if all fields are null and false in other case
      • getValue

        public java.lang.String getValue()
        Gets the fixed length block 2 value, as a result of concatenating its individual elements as follow:
        Message Type + Receivers address + Message Priority + Delivery Monitoring + Obsolescence Period.
        Overrides:
        getValue in class SwiftValueBlock
        Returns:
        the blocks value as a single string
      • setValue

        public void setValue​(java.lang.String value)
        Sets the block's attributes by parsing the fixed length string argument.
        Overrides:
        setValue in class SwiftValueBlock
        Parameters:
        value - a fixed length (between 16 and 23) string containing the blocks' value
        Throws:
        java.lang.IllegalArgumentException - if parameter has an invalid total size.
        See Also:
        setValue(String, boolean)
      • setBlockValue

        public void setBlockValue​(java.lang.String value)
        Description copied from class: SwiftValueBlock
        This method should be overwritten by subclasses, calling this method will throw a java.lang.UnsupportedOperationException
        Overrides:
        setBlockValue in class SwiftValueBlock
        Parameters:
        value - unused
        See Also:
        setValue(String)
      • setValue

        public void setValue​(java.lang.String value,
                             boolean lenient)
        Sets the block's attributes by parsing the string argument containing the blocks value.
        This value can be in different flavors because some fields are optional.
        Example of supported values:
         "I100BANKDEFFXXXX"      (16) or "2:I100BANKDEFFXXXX"      (18)   // used for service/system messages
         "I100BANKDEFFXXXXU"     (17) or "2:I100BANKDEFFXXXXU"     (19)
         "I100BANKDEFFXXXXU3"    (18) or "2:I100BANKDEFFXXXXU3"    (20)
         "I100BANKDEFFXXXXU3003" (21) or "2:I100BANKDEFFXXXXU3003" (23)
         

        Parameters:
        value - string containing the entire blocks value
        lenient - if true the value will be parsed with a best effort heuristic, if false it will throw a IllegalArgumentException if the value has an invalid total size
      • clean

        public void clean()
        Sets all attributes to null
        Overrides:
        clean in class SwiftBlock2
        Since:
        6.4
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class SwiftBlock2
      • field

        public java.lang.String field​(SwiftBlock2InputField field)
        Generic getter for block attributes based on qualified names from SwiftBlock2InputField
        Parameters:
        field - field to get
        Returns:
        field value or null if attribute is not set
        Since:
        7.7
      • setField

        public void setField​(SwiftBlock2InputField field,
                             java.lang.String value)
        Generic setter for block attributes based on qualified names from SwiftBlock2InputField
        Parameters:
        field - field to get
        value - content to set
        Since:
        7.8