Class AbstractMX

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractMX()  
      protected AbstractMX​(AppHdr appHdr)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.String document()
      Get this message Document as an XML string.
      java.lang.String document​(MxWriteParams params)
      Get this message Document as an XML string.
      java.lang.String document​(java.lang.String prefix, boolean includeXMLDeclaration, EscapeHandler escapeHandler)
      Deprecated.
      org.w3c.dom.Element element()  
      org.w3c.dom.Element element​(jakarta.xml.bind.JAXBContext inputContext)  
      static AbstractMX fromJson​(java.lang.String json)
      Creates an MX messages from its JSON representation.
      protected static <T> T fromJson​(java.lang.String json, java.lang.Class<T> classOfT)
      Used by subclasses to implement JSON deserialization.
      static AbstractMX fromJsonV9​(java.lang.String json)
      Deserializes the given JSON string into a specific MX message object, using version 9 (Java 8) adapters.
      protected static <T> T fromJsonV9​(java.lang.String json, java.lang.Class<T> classOfT)
      Deserializes the given JSON string into an object of the specified class, using version 9 (Java 8) adapters.
      AppHdr getAppHdr()  
      abstract java.lang.String getBusinessProcess()
      get the Alphabetic code in four positions (fixed length) identifying the Business Process
      abstract java.lang.Class[] getClasses()
      Get the classes associated with this message
      abstract int getFunctionality()
      Get the code identifying the Message Functionality
      MxId getMxId()
      Returns the MX message identification.
      Composed by the business process, functionality, variant and version.
      abstract java.lang.String getNamespace()
      Get the XML namespace of the message
      abstract int getVariant()
      Get the Message variant
      abstract int getVersion()
      Get the message version
      java.lang.String header()
      Get this message AppHdr as an XML string.
      java.lang.String header​(MxWriteParams params)
      Get this message AppHdr as an XML string.
      java.lang.String message()
      Get this message as an XML string.
      java.lang.String message​(MxWriteConfiguration conf)
      Get this message as an XML string.
      static AbstractMX parse​(java.io.File file, MxId id)
      Deprecated.
      use Lib.readFile(file) and any parse from String method
      static AbstractMX parse​(java.lang.String xml)
      Parses the XML string containing the Document and optional AppHdr into a specific instance of MX message object.
      static AbstractMX parse​(java.lang.String xml, MxId id)
      Parses the XML string containing the Document and optional AppHdr into a specific instance of MX message object.
      static AbstractMX parse​(java.lang.String xml, MxId id, MxReadConfiguration conf)
      Parses the XML string containing the Document and optional AppHdr into a specific instance of MX message object.
      static AbstractMX parse​(org.w3c.dom.Element e)
      Parses the XML Element into a specific MX object.
      void setAppHdr​(AppHdr appHdr)  
      java.lang.String targetNamespace()  
      java.lang.String toJson()
      Get a JSON representation of this MX message.
      java.lang.String toJsonV9()
      Serializes this MX message into its JSON representation, using version 9 (Java 8) adapters.
      void write​(java.io.File file)
      Deprecated.
      use message(MxWriteConfiguration) and handle write from String to file with plain Java API
      void write​(java.io.OutputStream stream)
      Deprecated.
      use message(MxWriteConfiguration) and handle write from String to stream with plain Java API
      javax.xml.transform.Source xmlSource()
      Convenience method to get this message XML as javax.xml.transform.Source.
      • Methods inherited from class com.prowidesoftware.swift.model.AbstractMessage

        getMessageStandardType, isMT, isMX
      • Methods inherited from class java.lang.Object

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

      • DOCUMENT_LOCALNAME

        public static final java.lang.String DOCUMENT_LOCALNAME
        See Also:
        Constant Field Values
      • DEFAULT_ROOT_ELEMENT

        @Deprecated
        @ProwideDeprecated(phase2=SRU2025)
        public static java.lang.String DEFAULT_ROOT_ELEMENT
        Deprecated.
        the default root element for the custom envelope is now defined in EnvelopeType.CUSTOM
    • Constructor Detail

      • AbstractMX

        protected AbstractMX()
      • AbstractMX

        protected AbstractMX​(AppHdr appHdr)
    • Method Detail

      • parse

        public static AbstractMX parse​(java.lang.String xml)
        Parses the XML string containing the Document and optional AppHdr into a specific instance of MX message object. The message and header types and version is auto-detected.

        The unmarshaller uses the default type adapters. For more parse options use parse(String, MxId, MxReadConfiguration).

        Parameters:
        xml - the XML content to parse
        Returns:
        parsed message or null if string content could not be parsed into an Mx
        Since:
        9.0.1
      • parse

        public static AbstractMX parse​(java.lang.String xml,
                                       MxId id)
        Parses the XML string containing the Document and optional AppHdr into a specific instance of MX message object. The header version, if present, is auto-detected from its namespace.

        If the string is empty, does not contain an MX document, the message type cannot be detected or an error occur reading and parsing the message content; this method returns null.

        The implementation detects the message type and uses reflection to call the parser in the specific subclass.

        The unmarshaller uses the default type adapters. For more parse options use parse(String, MxId, MxReadConfiguration).

        Parameters:
        xml - string a string containing the Document of an MX message in XML format
        id - optional parameter to indicate the specific MX type to create; auto detected from namespace if null.
        Returns:
        parsed message or null if string content could not be parsed into an Mx
        Since:
        7.8.4
      • parse

        @Deprecated
        @ProwideDeprecated(phase4=SRU2025)
        public static AbstractMX parse​(java.io.File file,
                                       MxId id)
                                throws java.io.IOException
        Deprecated.
        use Lib.readFile(file) and any parse from String method
        Throws:
        java.io.IOException
      • parse

        public static AbstractMX parse​(org.w3c.dom.Element e)
        Parses the XML Element into a specific MX object. The Mx to create is detected from the namespace.
        Parameters:
        e - content to parse
        Returns:
        specific Mx instance, for example, MxCamt0010101; or null if XML cannot be parsed or specific Mx cannot be detected
        Since:
        9.0
      • parse

        public static AbstractMX parse​(java.lang.String xml,
                                       MxId id,
                                       MxReadConfiguration conf)
        Parses the XML string containing the Document and optional AppHdr into a specific instance of MX message object. The header version, if present, is auto detected from its namespace.

        If the string is empty, does not contain an MX document, the message type cannot be detected or an error occur reading and parsing the message content; this method returns null.

        The implementation detects the message type and uses reflection to call the parser in the specific subclass.

        Parameters:
        xml - string a string containing the Document of an MX message in XML format
        id - optional parameter to indicate the specific MX type to create; auto detected from namespace if null.
        conf - specific options for the unmarshalling or null to use the default parameters
        Returns:
        parsed message or null if string content could not be parsed into an Mx
        Since:
        9.2.6
      • fromJson

        protected static <T> T fromJson​(java.lang.String json,
                                        java.lang.Class<T> classOfT)
        Used by subclasses to implement JSON deserialization.
        Parameters:
        json - a JSON representation of an MX message
        classOfT - the specific MX subclass
        Returns:
        a specific deserialized MX message object
        Since:
        7.10.3
      • fromJson

        public static AbstractMX fromJson​(java.lang.String json)
        Creates an MX messages from its JSON representation.
        Parameters:
        json - a JSON representation of an MX message
        Returns:
        a specific deserialized MX message object, for example MxPain00100108
        Since:
        7.10.3
      • fromJsonV9

        protected static <T> T fromJsonV9​(java.lang.String json,
                                          java.lang.Class<T> classOfT)
        Deserializes the given JSON string into an object of the specified class, using version 9 (Java 8) adapters.

        This method ensures compatibility by checking for date-time fields stored in JSON as XMLGregorianCalendar based json elements and converting them into OffsetDateTime. The Gson adapters (version 9) manage both Java 8 and Java 11 formats.

        Type Parameters:
        T - the type of the object to be deserialized
        Parameters:
        json - a JSON representation of the object
        classOfT - the class of the object to be deserialized
        Returns:
        a deserialized instance of the specified class, or null if the JSON string cannot be parsed.
        Since:
        10.1.8
      • fromJsonV9

        public static AbstractMX fromJsonV9​(java.lang.String json)
        Deserializes the given JSON string into a specific MX message object, using version 9 (Java 8) adapters.

        This method ensures compatibility with older versions by converting XMLGregorianCalendar based json elements in JSON to OffsetDateTime if needed. The deserialization uses custom adapters (version 9) that handle both formats for date-time fields.

        Parameters:
        json - a JSON representation of an MX message
        Returns:
        a deserialized instance of AbstractMX, or null if the JSON string cannot be parsed.
        Since:
        10.1.8
      • message

        public java.lang.String message​(MxWriteConfiguration conf)
        Get this message as an XML string.

        If the business header is set, the created XML will include both the 'AppHdr' and the 'Document' elements, under the configured root element. If the header is not present, the created XMl will only include the 'Document'. Both 'AppHdr' and 'Document' are generated with namespace declaration and optional with prefixes as indicated in the configuration.

        The configuration options enables customization of the XML serialization, including the root element name and prefixes. And it also provides default configurations for SWIFT and ISO 20022 envelopes.

        Parameters:
        conf - specific options for the serialization or null to use the default parameters
        Returns:
        the XML content or null if errors occur during serialization
      • header

        public java.lang.String header​(MxWriteParams params)
        Get this message AppHdr as an XML string.
        Since:
        9.2.6
      • document

        public java.lang.String document​(MxWriteParams params)
        Get this message Document as an XML string.
        Parameters:
        params - not null marshalling parameters
        Since:
        9.2.6
      • getClasses

        public abstract java.lang.Class[] getClasses()
        Get the classes associated with this message
        Since:
        7.7
      • getNamespace

        public abstract java.lang.String getNamespace()
        Get the XML namespace of the message
        Since:
        7.7
      • header

        public java.lang.String header()
        Get this message AppHdr as an XML string.

        The XML will not include the XML declaration, will bind the namespace to all elements without prefix and will use the default escape handler and content adapters.

        For more serialization options use header(MxWriteParams)

        Returns:
        the serialized header or null if header is not set or errors occur during serialization
        Since:
        7.8
      • document

        public java.lang.String document()
        Get this message Document as an XML string.

        The XML will not include the XML declaration, will bind the namespace to all elements using "doc" as default prefix and will use the default escape handler. For more serialization options use document(MxWriteParams)

        Returns:
        document serialized into XML string or null if errors occur during serialization
        Since:
        7.8
      • document

        @Deprecated
        @ProwideDeprecated(phase4=SRU2025)
        public java.lang.String document​(java.lang.String prefix,
                                         boolean includeXMLDeclaration,
                                         EscapeHandler escapeHandler)
        Deprecated.
      • xmlSource

        public javax.xml.transform.Source xmlSource()
        Convenience method to get this message XML as javax.xml.transform.Source.
        Returns:
        null if message() returns null or StreamSource in other case
        Since:
        7.7
        See Also:
        message()
      • message

        public java.lang.String message()
        Get this message as an XML string.

        If the header is present, then 'AppHdr' and 'Document' elements will be wrapped under a default root element 'RequestPayload'. Both header and document are generated with the corresponding namespaces and by default the prefix 'head' is used for the header and the message category is used as prefix for the document.
        For more serialization options see message(MxWriteConfiguration)
        To serialize only the header or the document (without header) see header() and document()

        Specified by:
        message in class com.prowidesoftware.swift.model.AbstractMessage
        Returns:
        the XML content or null if errors occur during serialization
        Since:
        7.7
      • write

        @Deprecated
        @ProwideDeprecated(phase4=SRU2025)
        public void write​(java.io.File file)
                   throws java.io.IOException
        Deprecated.
        use message(MxWriteConfiguration) and handle write from String to file with plain Java API
        Throws:
        java.io.IOException
      • write

        @Deprecated
        @ProwideDeprecated(phase4=SRU2025)
        public void write​(java.io.OutputStream stream)
                   throws java.io.IOException
        Deprecated.
        use message(MxWriteConfiguration) and handle write from String to stream with plain Java API
        Throws:
        java.io.IOException
      • getAppHdr

        public AppHdr getAppHdr()
        Returns:
        the business header or null if not set
        Since:
        9.0.1
      • setAppHdr

        public void setAppHdr​(AppHdr appHdr)
        Parameters:
        appHdr - the header to set
        Since:
        9.0.1
      • getMxId

        public MxId getMxId()
        Returns the MX message identification.
        Composed by the business process, functionality, variant and version.
        Returns:
        the constructed message id
        Since:
        7.7
      • getBusinessProcess

        public abstract java.lang.String getBusinessProcess()
        get the Alphabetic code in four positions (fixed length) identifying the Business Process
        Returns:
        the business process of the implementing class
        Since:
        7.7
      • getFunctionality

        public abstract int getFunctionality()
        Get the code identifying the Message Functionality
        Returns:
        the set functionality or null if not set
        Since:
        7.7
      • getVariant

        public abstract int getVariant()
        Get the Message variant
        Returns:
        the set variant or null if not set
        Since:
        7.7
      • getVersion

        public abstract int getVersion()
        Get the message version
        Returns:
        the set vesion or null if not set
        Since:
        7.7
      • element

        public org.w3c.dom.Element element()
      • element

        public org.w3c.dom.Element element​(jakarta.xml.bind.JAXBContext inputContext)
      • toJson

        public java.lang.String toJson()
        Get a JSON representation of this MX message.
        Specified by:
        toJson in interface com.prowidesoftware.JsonSerializable
        Since:
        7.10.3
      • toJsonV9

        public java.lang.String toJsonV9()
        Serializes this MX message into its JSON representation, using version 9 (Java 8) adapters.

        This method ensures that when serializing to JSON, OffsetDateTime fields can be converted back into XMLGregorianCalendar based json element format for compatibility with older systems that still use the Java 8 format.

        Returns:
        a JSON representation of the MX message, compatible with Java 8
        Since:
        10.1.8
      • targetNamespace

        public java.lang.String targetNamespace()
        Returns:
        same as getNamespace()
        Since:
        9.1.2