jPOS 1.6.5 API Documentation

org.jpos.util
Class FSDMsg

java.lang.Object
  extended by org.jpos.util.FSDMsg
All Implemented Interfaces:
java.lang.Cloneable, Loggeable

public class FSDMsg
extends java.lang.Object
implements Loggeable, java.lang.Cloneable

General purpose, Field Separator delimited message.

How to use

The message format (or schema) is defined in xml files containing a schema element, with an optional id attribute, and multiple field elements. A field element is made up of the following attributes:

id
The name of the field. This is used in calls to set(String, String). It should be unique amongst the fields in an FSDMsg.
length
The maximum length of the data allowed in this field. Fixed length fields will be padded to this length. A zero length is allowed, and can be useful to define extra separator characters in the message.
type
The type of the included data, including an optional separator for marking the end of the field and the beginning of the next one. The data type is defined by the first char of the type, and the separator is defined by the following chars. If a field separator is specified, then no padding is done on values for this field.
key
If this optional attribute has a value of "true", then fields from another schema, specified by the value, are appended to this schema.

Possible types are:

A
Alphanumeric. Padding if any is done with spaces to the right.
B
Binary. Padding, if any, is done with zeros to the left.
K
Constant. The value is specified by the field content. No padding is done.
N
Numeric. Padding, if any, is done with zeros to the left.

Supported field separators are:

FS
Field separator using '034' as the separator.
US
Field separator using '037' as the separator.
GS
Field separator using '035' as the separator.
RS
Field separator using '036' as the separator.
PIPE
Field separator using '|' as the separator.
EOF
End of Field - no separator character is emitted, but also no padding is done.

Key fields allow you to specify a tree of possible message formats. The key fields are the fork points of the tree. Multiple key fields are supported. It is also possible to have more key fields specified in appended schemas.

Since:
1.4.7
Author:
Alejandro Revila, Mark Salter, Dave Bergert

Field Summary
static char EOF
           
static char FS
           
static char GS
           
static char PIPE
           
static char RS
           
static char US
           
 
Constructor Summary
FSDMsg(java.lang.String basePath)
          Creates a FSDMsg with a specific base path for the message format schema.
FSDMsg(java.lang.String basePath, java.lang.String baseSchema)
          Creates a FSDMsg with a specific base path for the message format schema, and a base schema name.
 
Method Summary
 java.lang.Object clone()
           
 void copy(java.lang.String fieldName, FSDMsg msg)
           
 void dump(java.io.PrintStream p, java.lang.String indent)
           
 java.lang.String get(java.lang.String fieldName)
           
 java.lang.String get(java.lang.String fieldName, java.lang.String def)
           
 java.lang.String getBasePath()
           
 java.lang.String getBaseSchema()
           
 byte[] getHeader()
           
 byte[] getHexBytes(java.lang.String name)
           
 java.lang.String getHexHeader()
           
 int getInt(java.lang.String name)
           
 int getInt(java.lang.String name, int def)
           
 java.util.Map getMap()
           
 boolean hasField(java.lang.String fieldName)
           
 boolean isSeparator(byte b)
           
 java.lang.String pack()
           
 byte[] packToBytes()
           
 void set(java.lang.String name, java.lang.String value)
           
 void setHeader(byte[] h)
           
 void setMap(java.util.Map fields)
           
 void setSeparator(java.lang.String separatorName, char separator)
           
 org.jdom.Element toXML()
           
 void unpack(byte[] b)
          parse message.
 void unpack(java.io.InputStream is)
          parse message.
 void unsetSeparator(java.lang.String separatorName)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FS

public static char FS

US

public static char US

GS

public static char GS

RS

public static char RS

EOF

public static char EOF

PIPE

public static char PIPE
Constructor Detail

FSDMsg

public FSDMsg(java.lang.String basePath)
Creates a FSDMsg with a specific base path for the message format schema.

Parameters:
basePath - schema path, for example: "file:src/data/NDC-" looks for a file src/data/NDC-base.xml

FSDMsg

public FSDMsg(java.lang.String basePath,
              java.lang.String baseSchema)
Creates a FSDMsg with a specific base path for the message format schema, and a base schema name. For instance, FSDMsg("file:src/data/NDC-", "root") will look for a file: src/data/NDC-root.xml

Parameters:
basePath - schema path
baseSchema - schema name
Method Detail

getBasePath

public java.lang.String getBasePath()

getBaseSchema

public java.lang.String getBaseSchema()

setSeparator

public void setSeparator(java.lang.String separatorName,
                         char separator)

unsetSeparator

public void unsetSeparator(java.lang.String separatorName)

unpack

public void unpack(java.io.InputStream is)
            throws java.io.IOException,
                   org.jdom.JDOMException,
                   java.net.MalformedURLException
parse message. If the stream ends before the message is completely read, then the method adds an EOF field.

Parameters:
is - input stream
Throws:
java.io.IOException
org.jdom.JDOMException
java.net.MalformedURLException

unpack

public void unpack(byte[] b)
            throws java.io.IOException,
                   org.jdom.JDOMException,
                   java.net.MalformedURLException
parse message. If the stream ends before the message is completely read, then the method adds an EOF field.

Parameters:
b - message image
Throws:
java.io.IOException
org.jdom.JDOMException
java.net.MalformedURLException
ISOException

pack

public java.lang.String pack()
                      throws org.jdom.JDOMException,
                             java.net.MalformedURLException,
                             java.io.IOException,
                             ISOException
Returns:
message string
Throws:
ISOException
org.jdom.JDOMException
java.net.MalformedURLException
java.io.IOException

packToBytes

public byte[] packToBytes()
                   throws org.jdom.JDOMException,
                          java.net.MalformedURLException,
                          java.io.IOException,
                          ISOException,
                          java.io.UnsupportedEncodingException
Throws:
org.jdom.JDOMException
java.net.MalformedURLException
java.io.IOException
ISOException
java.io.UnsupportedEncodingException

isSeparator

public boolean isSeparator(byte b)

set

public void set(java.lang.String name,
                java.lang.String value)

setHeader

public void setHeader(byte[] h)

getHeader

public byte[] getHeader()

getHexHeader

public java.lang.String getHexHeader()

get

public java.lang.String get(java.lang.String fieldName)

get

public java.lang.String get(java.lang.String fieldName,
                            java.lang.String def)

copy

public void copy(java.lang.String fieldName,
                 FSDMsg msg)

getHexBytes

public byte[] getHexBytes(java.lang.String name)

getInt

public int getInt(java.lang.String name)

getInt

public int getInt(java.lang.String name,
                  int def)

toXML

public org.jdom.Element toXML()

getMap

public java.util.Map getMap()
Returns:
message's Map

setMap

public void setMap(java.util.Map fields)

dump

public void dump(java.io.PrintStream p,
                 java.lang.String indent)
Specified by:
dump in interface Loggeable

hasField

public boolean hasField(java.lang.String fieldName)

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

jPOS.org