public abstract class AbstractMX extends com.prowidesoftware.swift.model.AbstractMessage implements IDocument, com.prowidesoftware.JsonSerializable
IMPORTANT: An MX message is conformed by a set of optional headers and a message payload or document with the actual specific MX message. The name of the envelope element that binds a Header to the message to which it applies is implementation/network specific and not part of the scope of this model.
This class provides the base container model for MX messages including an attribute for the header. Further it supports both versions for the header; the SWIFT Application Header (legacy) and the ISO Business Application Header.
Serialization of this model into XML text can be done for the with or without the header portion. When the header is set and included into the serialization, the container root element must be provided.
AbstractMT
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_ROOT_ELEMENT
Default root element when an MX is serialized as XML including both AppHdr and Document
|
static java.lang.String |
DOCUMENT_LOCALNAME |
Modifier | Constructor and Description |
---|---|
protected |
AbstractMX() |
protected |
AbstractMX(AppHdr appHdr) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
document()
Get this message Document as an XML string.
|
java.lang.String |
document(java.lang.String prefix,
boolean includeXMLDeclaration)
Get this message Document as an XML string.
|
org.w3c.dom.Element |
element() |
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.
|
AppHdr |
getAppHdr() |
BusinessHeader |
getBusinessHeader()
Deprecated.
use
getAppHdr() instead |
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(java.lang.String prefix,
boolean includeXMLDeclaration)
Get this message AppHdr as an XML string.
|
java.lang.String |
message()
Get this message as an XML string.
|
java.lang.String |
message(java.lang.String rootElement)
Same as
message(String, boolean) with includeXMLDeclaration set to true |
protected static java.lang.String |
message(java.lang.String namespace,
AbstractMX obj,
java.lang.Class[] classes,
java.lang.String prefix,
boolean includeXMLDeclaration) |
java.lang.String |
message(java.lang.String rootElement,
boolean includeXMLDeclaration)
Get this message as an XML string.
|
static AbstractMX |
parse(org.w3c.dom.Element e)
Parses the XML Element into a specific MX object.
|
static AbstractMX |
parse(java.io.File file,
MxId id)
Parses a file content into a specific instance of MX.
|
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.
|
protected static AbstractMX |
read(java.lang.Class<? extends AbstractMX> targetClass,
java.lang.String xml,
java.lang.Class[] classes) |
void |
setAppHdr(AppHdr appHdr) |
void |
setBusinessHeader(BusinessHeader businessHeader)
Deprecated.
use
setAppHdr(AppHdr) instead |
java.lang.String |
targetNamespace() |
java.lang.String |
toJson()
Get a JSON representation of this MX message.
|
void |
write(java.io.File file)
Writes the message document content into a file in XML format (headers not included).
|
void |
write(java.io.OutputStream stream)
Writes the message document content into a file in XML format, encoding content in UTF-8 (headers not included).
|
javax.xml.transform.Source |
xmlSource()
Convenience method to get this message XML as javax.xml.transform.Source.
|
public static final java.lang.String DOCUMENT_LOCALNAME
public static java.lang.String DEFAULT_ROOT_ELEMENT
protected AbstractMX()
protected AbstractMX(AppHdr appHdr)
protected static java.lang.String message(java.lang.String namespace, AbstractMX obj, java.lang.Class[] classes, java.lang.String prefix, boolean includeXMLDeclaration)
protected static AbstractMX read(java.lang.Class<? extends AbstractMX> targetClass, java.lang.String xml, java.lang.Class[] classes)
public static AbstractMX parse(java.lang.String xml)
The implementation uses parse(File, MxId)
with message id null for auto detection.
xml
- the XML content to parsepublic static AbstractMX parse(java.lang.String xml, MxId id)
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.
xml
- string a string containing the Document of an MX message in XML formatid
- optional parameter to indicate the specific MX type to create; auto detected from namespace if null.public static AbstractMX parse(java.io.File file, MxId id) throws java.io.IOException
file
- a file containing a swift MX messageid
- optional parameter to indicate the specific MX type to create; autodetected from namespace if null.java.io.IOException
- if the file cannot be writtenparse(String, MxId)
public static AbstractMX parse(org.w3c.dom.Element e)
e
- content to parseprotected static <T> T fromJson(java.lang.String json, java.lang.Class<T> classOfT)
json
- a JSON representation of an MX messageclassOfT
- the specific MX subclasspublic static AbstractMX fromJson(java.lang.String json)
json
- a JSON representation of an MX messagepublic abstract java.lang.Class[] getClasses()
public abstract java.lang.String getNamespace()
public abstract java.lang.String getBusinessProcess()
public abstract int getFunctionality()
public abstract int getVariant()
public abstract int getVersion()
public java.lang.String message()
If the header is present, then 'AppHdr' and 'Document' elements will be wrapped under a
DEFAULT_ROOT_ELEMENT
Both header and documents are generated with the corresponding namespaces and by default the prefix 'h' is
used for the header and the prefix 'Doc' for the document.
message
in class com.prowidesoftware.swift.model.AbstractMessage
message(String, boolean)
public java.lang.String message(java.lang.String rootElement, boolean includeXMLDeclaration)
If the business header is set, the created XML will include both the 'AppHdr' and the 'Document' elements,
under a the indicated or default 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 default prefixes 'h' and 'Doc'
respectively.
IMPORTANT: The name of the envelope element that binds a Header to the message to which it applies is implementation/network specific. The header root element ‘AppHdr’ and the ISO 20022 MessageDefinition root element ‘Document’ must always be sibling elements in any XML document, with the AppHdr element preceding the Document element.
rootElement
- optional specification of the root element if not provided DEFAULT_ROOT_ELEMENT
is usedincludeXMLDeclaration
- true to include the XML declarationpublic java.lang.String message(java.lang.String rootElement)
message(String, boolean)
with includeXMLDeclaration set to truepublic java.lang.String header()
The XML will not include the XML declaration, and will include de namespace as default (without prefix).
header(String, boolean)
public java.lang.String header(java.lang.String prefix, boolean includeXMLDeclaration)
prefix
- optional prefix for namespace (empty by default)includeXMLDeclaration
- true to include the XML declarationpublic java.lang.String document()
The XML will include the XML declaration, and will use "Doc" as prefix for the elements.
document(String, boolean)
public java.lang.String document(java.lang.String prefix, boolean includeXMLDeclaration)
prefix
- optional prefix for namespace (empty by default)includeXMLDeclaration
- true to include the XML declarationpublic javax.xml.transform.Source xmlSource()
message()
public void write(java.io.File file) throws java.io.IOException
file
- a not null file to write, if it does not exists, it will be createdjava.io.IOException
public void write(java.io.OutputStream stream) throws java.io.IOException
stream
- a non null stream to writejava.io.IOException
- if the stream cannot be written@Deprecated @ProwideDeprecated(phase2=SRU2021) public BusinessHeader getBusinessHeader()
getAppHdr()
instead@ProwideDeprecated(phase2=SRU2021) @Deprecated public void setBusinessHeader(BusinessHeader businessHeader)
setAppHdr(AppHdr)
insteadbusinessHeader
- the header to setpublic AppHdr getAppHdr()
public void setAppHdr(AppHdr appHdr)
appHdr
- the header to setpublic MxId getMxId()
public org.w3c.dom.Element element()
public java.lang.String toJson()
toJson
in interface com.prowidesoftware.JsonSerializable
public java.lang.String targetNamespace()
getNamespace()