org.jpos.util
Class FSDMsg

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

public class FSDMsg
extends Object
implements Loggeable, 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.
separator
An optional attribute containing the separator for the field. This is the preferred method of specifying the separator. See the list of optional

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
Group separator using '035' as the separator.
RS
Row separator using '036' as the separator.
PIPE
Field separator using '|' as the separator.
EOF
End of File - no separator character is emitted, but also no padding is done. Also if the end of file is reached parsing a message, then no exception is thrown.
DS
A dummy separator. This is similar to EOF, but the message stream must not end before it is allowed.
EOM
End of message separator. This reads all bytes available in the stream.

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 EOM
           
static char FS
           
static char GS
           
static char PIPE
           
static char RS
           
static char US
           
 
Constructor Summary
FSDMsg(String basePath)
          Creates a FSDMsg with a specific base path for the message format schema.
FSDMsg(String basePath, String baseSchema)
          Creates a FSDMsg with a specific base path for the message format schema, and a base schema name.
 
Method Summary
 Object clone()
           
 void copy(String fieldName, FSDMsg msg)
           
 void dump(PrintStream p, String indent)
           
 String get(String fieldName)
           
 String get(String fieldName, String def)
           
protected  String get(String id, String type, int length, String defValue, String separator)
           
 String getBasePath()
           
 String getBaseSchema()
           
 byte[] getHeader()
           
 byte[] getHexBytes(String name)
           
 String getHexHeader()
           
 int getInt(String name)
           
 int getInt(String name, int def)
           
 Map getMap()
           
protected  org.jdom.Element getSchema()
           
protected  org.jdom.Element getSchema(String message)
           
protected  org.jdom.Element getSchema(String prefix, String suffix, String defSuffix)
           
 boolean hasField(String fieldName)
           
 boolean isSeparator(byte b)
           
 void merge(FSDMsg m)
           
 String pack()
           
protected  void pack(org.jdom.Element schema, StringBuffer sb)
           
 byte[] packToBytes()
           
protected  String read(InputStream is, int len, String type, String separator)
           
protected  String readField(InputStream is, String fieldName, int len, String type, String separator)
           
 void set(String name, String value)
           
 void setHeader(byte[] h)
           
 void setMap(Map fields)
           
 void setSeparator(String separatorName, char separator)
           
 org.jdom.Element toXML()
           
 void unpack(byte[] b)
          parse message.
 void unpack(InputStream is)
          parse message.
protected  void unpack(InputStream is, org.jdom.Element schema)
           
 void unsetSeparator(String separatorName)
           
 
Methods inherited from class java.lang.Object
equals, finalize, 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

EOM

public static char EOM
Constructor Detail

FSDMsg

public FSDMsg(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(String basePath,
              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 String getBasePath()

getBaseSchema

public String getBaseSchema()

setSeparator

public void setSeparator(String separatorName,
                         char separator)

unsetSeparator

public void unsetSeparator(String separatorName)

unpack

public void unpack(InputStream is)
            throws IOException,
                   org.jdom.JDOMException,
                   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:
IOException
org.jdom.JDOMException
MalformedURLException

unpack

public void unpack(byte[] b)
            throws IOException,
                   org.jdom.JDOMException,
                   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:
IOException
org.jdom.JDOMException
MalformedURLException
ISOException

pack

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

packToBytes

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

get

protected String get(String id,
                     String type,
                     int length,
                     String defValue,
                     String separator)
              throws ISOException
Throws:
ISOException

isSeparator

public boolean isSeparator(byte b)

pack

protected void pack(org.jdom.Element schema,
                    StringBuffer sb)
             throws org.jdom.JDOMException,
                    MalformedURLException,
                    IOException,
                    ISOException
Throws:
org.jdom.JDOMException
MalformedURLException
IOException
ISOException

unpack

protected void unpack(InputStream is,
                      org.jdom.Element schema)
               throws IOException,
                      org.jdom.JDOMException,
                      MalformedURLException
Throws:
IOException
org.jdom.JDOMException
MalformedURLException

read

protected String read(InputStream is,
                      int len,
                      String type,
                      String separator)
               throws IOException
Throws:
IOException

readField

protected String readField(InputStream is,
                           String fieldName,
                           int len,
                           String type,
                           String separator)
                    throws IOException
Throws:
IOException

set

public void set(String name,
                String value)

setHeader

public void setHeader(byte[] h)

getHeader

public byte[] getHeader()

getHexHeader

public String getHexHeader()

get

public String get(String fieldName)

get

public String get(String fieldName,
                  String def)

copy

public void copy(String fieldName,
                 FSDMsg msg)

getHexBytes

public byte[] getHexBytes(String name)

getInt

public int getInt(String name)

getInt

public int getInt(String name,
                  int def)

toXML

public org.jdom.Element toXML()

getSchema

protected org.jdom.Element getSchema()
                              throws org.jdom.JDOMException,
                                     IOException
Throws:
org.jdom.JDOMException
IOException

getSchema

protected org.jdom.Element getSchema(String message)
                              throws org.jdom.JDOMException,
                                     IOException
Throws:
org.jdom.JDOMException
IOException

getSchema

protected org.jdom.Element getSchema(String prefix,
                                     String suffix,
                                     String defSuffix)
                              throws org.jdom.JDOMException,
                                     IOException
Throws:
org.jdom.JDOMException
IOException

getMap

public Map getMap()
Returns:
message's Map

setMap

public void setMap(Map fields)

dump

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

hasField

public boolean hasField(String fieldName)

clone

public Object clone()
Overrides:
clone in class Object

merge

public void merge(FSDMsg m)


Copyright © 1998-2012 jPOS.org. All Rights Reserved.