net.sf.xbus.protocol.records
Class RecordTypeSerializer

java.lang.Object
  extended by net.sf.xbus.protocol.records.RecordTypeSerializer

public class RecordTypeSerializer
extends java.lang.Object

RecordTypeSerializer serves for serializing records stored in a DOM tree according to a record type structure.

The DOM tree structure is described in the RecordTypeParser documentation.

The serialization result is a String.
The string structure is described by a xml file - in particular the contained record types. Such describing files are of document type InterfaceSpec declared in "InterfaceSpec.dtd". The structure of the internal DOM tree to serialise is described on the RecordTypeParser documentation page.

Author:
Lars Meßner, Stehan Düwel

Field Summary
protected  boolean checkingActivated
          Is the checking of the structrure description activated?
protected  java.lang.String contentType
          contentType contains the name for the parsed structure as it is derived from a interfaceStructure.
protected  org.w3c.dom.Node groupsSpec
          groupsSpec is a shortcut into the interfaceStructurefor the specification section of field groups.
protected  org.w3c.dom.Element headerSpec
          headerSpec is a shortcut into the interfaceStructurefor the file/string header.
protected  int interfaceContentClass
          The RecordTypeManipulator is able to treat interface file contents as strings or as byte array lists.
protected  int interfaceContentLength
          Length of interface file in sense of
(a) characters if the content is represented as string
(b) bytes if the content is represented as byte array list
protected  org.w3c.dom.Document interfaceStructure
          interfaceStructure holds the structure description used for parsing/serializing.
protected  org.w3c.dom.Element linesSpec
          linesSpec is a shortcut into the interfaceStructurefor the lines specification.
protected  java.lang.String recIdentMethod
          recIdentMethod indicates how the records with the parsed string are identified during parsing.
protected  java.lang.String recOrder
          recOrder determines in which order the differnt record types occurr in the parsed string.
protected  org.w3c.dom.Node recordTypesSpec
          recordTypesSpec is a shortcut into the interfaceStructurefor the specification section of record types.
protected  java.lang.String sourceType
          sourceType contains the name for the parsed structure as it is derived from a RecordTypeMessage.
protected  org.w3c.dom.Element trailerSpec
          trailerSpec is a shortcut into the interfaceStructurefor the file/string trailer.
 
Method Summary
protected  ByteArrayConverter getByteArrayConverter()
          Method getByteArrayConverter.
protected  int getFieldPos(org.w3c.dom.Element fieldSpec, org.w3c.dom.Node parentSpec)
          getFieldPos determines the position of a field within the surrounding record type - including header and trailer.
static RecordTypeSerializer getInstance(java.lang.String sourceType, int interfaceContentClass)
          getInstance() retrieves the an instance of RecordTypeSerializer.
 int getInterfaceContentClass()
          getInterfaceContentClass retrieves the mode (string or byte array list) in which the RecordTypeManipulator is working in.
protected  java.lang.String getInterfaceDescription(java.lang.String system)
          getInterfaceDescription extracts the name of the interface description file.
protected  org.w3c.dom.Element getRecordTypeById(java.lang.String searchedId)
          getRecordTypeByID retrieves the record type declaration within the lines section by the type identifier.
protected  int getRecordTypePositionInLines(org.w3c.dom.Element recordType)
          getRecordTypePositionInLines retrieves the position of a record type in the lines section.
protected  org.w3c.dom.Node getRecordTypeSpec(java.lang.String recordType)
          getRecordTypeSpec retrieves the record type specification from the record types section to a record type name.
 java.lang.String getSourceType()
          getSourceType retrieves the name for the parsed structure as it is derived from a RecordTypeMessage.
protected  java.lang.String getTypeIdentifier(java.lang.String idPosString, org.w3c.dom.Node recordTypeSpec)
          getTypeIdentifier retrieves the type identifier field.
 void initialize(java.lang.String system, int ifContentClass, javax.xml.parsers.DocumentBuilder builder)
          initialize sets the name for the parsed structure and the structure description used for parsing/serializing.
 java.lang.Object serialize(org.w3c.dom.Document docContent)
          serialize serializes the specified DOM tree due to the record type definition.
 byte[] serializeSingleRecord(org.w3c.dom.Document doc)
          Serializes one record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceType

protected java.lang.String sourceType
sourceType contains the name for the parsed structure as it is derived from a RecordTypeMessage. RecordTypeManipulator does not garuantee the consistency of sourceType,contentTypeand interfaceStructure.


contentType

protected java.lang.String contentType
contentType contains the name for the parsed structure as it is derived from a interfaceStructure. RecordTypeManipulator does not garuantee the consistency of contentType and sourceType


interfaceStructure

protected org.w3c.dom.Document interfaceStructure
interfaceStructure holds the structure description used for parsing/serializing. But RecordTypeManipulator does not load the structure description itself from a file nor does it garuantee the consistency of sourceTypewith interfaceStructure.


headerSpec

protected org.w3c.dom.Element headerSpec
headerSpec is a shortcut into the interfaceStructurefor the file/string header.


linesSpec

protected org.w3c.dom.Element linesSpec
linesSpec is a shortcut into the interfaceStructurefor the lines specification.


recordTypesSpec

protected org.w3c.dom.Node recordTypesSpec
recordTypesSpec is a shortcut into the interfaceStructurefor the specification section of record types.


trailerSpec

protected org.w3c.dom.Element trailerSpec
trailerSpec is a shortcut into the interfaceStructurefor the file/string trailer.


groupsSpec

protected org.w3c.dom.Node groupsSpec
groupsSpec is a shortcut into the interfaceStructurefor the specification section of field groups.


recIdentMethod

protected java.lang.String recIdentMethod
recIdentMethod indicates how the records with the parsed string are identified during parsing. Possible values are:


recOrder

protected java.lang.String recOrder
recOrder determines in which order the differnt record types occurr in the parsed string. Possible values are:


checkingActivated

protected boolean checkingActivated
Is the checking of the structrure description activated?


interfaceContentClass

protected int interfaceContentClass
The RecordTypeManipulator is able to treat interface file contents as strings or as byte array lists. interfaceContentClass contains the information which of these media is used.


interfaceContentLength

protected int interfaceContentLength
Length of interface file in sense of
(a) characters if the content is represented as string
(b) bytes if the content is represented as byte array list

Method Detail

getInstance

public static RecordTypeSerializer getInstance(java.lang.String sourceType,
                                               int interfaceContentClass)
                                        throws XException
getInstance() retrieves the an instance of RecordTypeSerializer.

Parameters:
sourceType - the name for the parsed structure as it is derived from the DOM tree with the interface content
Throws:
XException - in case of missing sourceType

getByteArrayConverter

protected ByteArrayConverter getByteArrayConverter()
                                            throws XException
Method getByteArrayConverter.

Returns:
ByteArrayConverter
Throws:
XException

serialize

public java.lang.Object serialize(org.w3c.dom.Document docContent)
                           throws XException
serialize serializes the specified DOM tree due to the record type definition.

Parameters:
docContent - the DOM tree with the interface content
Returns:
the serialized string
Throws:
XException - in case of an unexpected value

serializeSingleRecord

public byte[] serializeSingleRecord(org.w3c.dom.Document doc)
                             throws XException
Serializes one record.

Parameters:
doc -
Returns:
a byte array containing one record
Throws:
XException

getSourceType

public java.lang.String getSourceType()
getSourceType retrieves the name for the parsed structure as it is derived from a RecordTypeMessage. RecordTypeManipulator does not garuantee the consistency of sourceType,contentTypeand interfaceStructure.


getInterfaceContentClass

public int getInterfaceContentClass()
getInterfaceContentClass retrieves the mode (string or byte array list) in which the RecordTypeManipulator is working in.


getInterfaceDescription

protected java.lang.String getInterfaceDescription(java.lang.String system)
                                            throws XException
getInterfaceDescription extracts the name of the interface description file.

Parameters:
system - the origin of the message
Returns:
name of the interface description file
Throws:
XException - in case that the interface file name can not be retrieved

initialize

public void initialize(java.lang.String system,
                       int ifContentClass,
                       javax.xml.parsers.DocumentBuilder builder)
                throws XException
initialize sets the name for the parsed structure and the structure description used for parsing/serializing. The structure description is checked if this option is activated in the configuration. RecordTypeManipulator does not load the structure description itself from a file nor does it garuantee the consistency of sourceTypewith interfaceStructure.

Parameters:
system - the name for the parsed structure as it is derived from a RecordTypeMessage
ifContentClass - the mode (string or byte array list) in which the RecordTypeManipulator is working in
builder - ???
Throws:
XException - in case of an illegal structure description. In this case the description is not set!

getRecordTypePositionInLines

protected int getRecordTypePositionInLines(org.w3c.dom.Element recordType)
                                    throws XException
getRecordTypePositionInLines retrieves the position of a record type in the lines section.

Parameters:
recordType - as node in the lines section
Returns:
the position of the record type in the lines section (starting at 0) - relative to the record group if recOrder =="Structured"
Throws:
XException - in case that the record type cannot be found

getRecordTypeById

protected org.w3c.dom.Element getRecordTypeById(java.lang.String searchedId)
                                         throws XException
getRecordTypeByID retrieves the record type declaration within the lines section by the type identifier.

Parameters:
searchedId - the type identifier
Returns:
the record type declaration node in the lines section as as Element
Throws:
XException - in case that the record type cannot be found

getRecordTypeSpec

protected org.w3c.dom.Node getRecordTypeSpec(java.lang.String recordType)
                                      throws XException
getRecordTypeSpec retrieves the record type specification from the record types section to a record type name.

Parameters:
recordType - the record type name
Returns:
the record type specification as nodein the interface structure description
Throws:
XException - in case that the record type specification cannot be found

getFieldPos

protected int getFieldPos(org.w3c.dom.Element fieldSpec,
                          org.w3c.dom.Node parentSpec)
                   throws XException
getFieldPos determines the position of a field within the surrounding record type - including header and trailer.

Parameters:
fieldSpec - the field as elementnode
parentSpec - the specification of the surrounding record type
Returns:
the field position within the record type
Throws:
XException - in case of problems with the description file

getTypeIdentifier

protected java.lang.String getTypeIdentifier(java.lang.String idPosString,
                                             org.w3c.dom.Node recordTypeSpec)
                                      throws XException
getTypeIdentifier retrieves the type identifier field.

Parameters:
idPosString - the identifier position in the record line - in sense of char counting if the interface contant is treated as string; in sense of byte counting if a byte array list is used instead
recordTypeSpec - the record type specification to search in
Returns:
the name of the type identifier field - null if it could not be found
Throws:
XException - in case of problems with the description file or the identifier position