org.openadaptor.adaptor
Class SimpleReaderDelegate

java.lang.Object
  extended by org.openadaptor.adaptor.SimpleReaderDelegate
All Implemented Interfaces:
ReaderDelegate, DOMessageReaderDelegate

public class SimpleReaderDelegate
extends java.lang.Object
implements ReaderDelegate

SimpleReaderDelegate is a class that can potentially be used by all Reader based Sources (e.g. FileSource, JMSSource), or independently, for example, by a J2EE message-driven-bean.

It is a meld of AbstractReader and DOXML reader code (from SimpleComponent) and includes the code to create a security manager (from SimpleController).

Some further re-factoring may be introduced in future releases.

From dealbus 2.1 onwards all Sources can have an assigned DOStringWriter DOStringWriters are use to delegate the work of converting string records to DataObjects. If a Source does not have a DOStringWriter then it is either interfacing to a specific API (eg: jdbc) or using the built in doconverter to read the internal dealbus formats.

Use the following property to assign an instance of a DOStringReader class

    DOStringReader      class name of a org.openadaptor.dostrings.DOStringReader
 

Interpretation of record formats is delegated to the DOStringReader assigned to this source.

Developers that wish to process strings with custom formats cam simply implement a new DOStringReader and assign this via the Source properties.

If SimpleReaderDelegate has no defined DOStringReader it uses the built in XMLFormatter.

The SimpleReaderDelegate supports the ability to ignore an arbitary number of headerlines and a much more powerful ability to specify regular expressions for comment lines and record lines. @see #init for properties and further explanation.

You need to refer to the assigned DOStringReader for the properties supported. The properties for this class are as follows

 BatchSize               Number of records (DataObjects) per DataObject array
 IgnoreHeaderLines       Number of header lines to expected, and ignore
 CommentRegExpN          A regular expression pattern for a comment line
 RecordRegExpN           A regular expression for a record line
 UseAlternateDOXMLReader If true, uses different, but considerably slower,
                         algorithm to read DO XML documents. This algorithm
                         was formerly used by FileSource as a workaround
                         to a problem reading very high volume multi-document
                         DO XML format files. [Optional, default false]
 

If no Record regular expressions are defined then all lines are candiates for a record. If there are one or more Record regular expressions then a line is only a record if it matches one. If there are one or more comment regular expressions then a line is not a record if it matches one.

See also the properties supported by getXMLFormatter().

The openadaptor SecurityManager properties are also supported.

The MDBAdaptorListener class has been tested using

Note: With the JavaSoft J2EE reference implementation there may be permissioning restrictions which prevent proper functioning of the TestSecurityManager in its current form. You may need to adjust your J2EE security policy settings to permit dynamic add of security providers and to permit access to the filesystem location containing the openadaptor security configuration files.

For example, the TestSecurityManager assumes it can add cryptix as a provider dynamically. Default J2EE permissions may prohibit this. Even if cryptix is already added as a provider in the java.security file, the TestSecurityManager also assumes it can read security configuration properties from the filesystem. Again, default J2EE permissions may prohibit this.

Author:
Cut-n-Paste
See Also:
DOStringReader, DOStringReaderWriter, DelimitedStringReader, FixedWidthStringReader

Field Summary
protected  int _batch_size
          The number of records (DataObjects) to be sent in each Data Object array (0 = whole file).
protected  org.apache.oro.text.regex.Pattern[] _comment_regexps
          array of regular expressions checkers that are used to match comments / line sto ignore in the file
protected  java.lang.String _end_data
           
protected  XMLFormatter _formatter
          holds the formatter that should be used by all component to to read and write adaptor framework message (XML)
protected  int _header_lines
          The number of header lines expected in the data, these will be discarded before attempting process records or XML
protected  java.lang.String _prefix
           
protected  java.util.Properties _properties
          Reference to properties object and prefix.
protected  org.apache.oro.text.regex.Perl5Compiler _re_compiler
           
protected  org.apache.oro.text.regex.Perl5Matcher _re_matcher
          regex compiler and matcher
protected  java.io.Reader _reader
          The input reader
protected  DOMessageReaderDelegate _readerDelegate
          the next delegate for components that implement the DOMessageReaderDelegate interface
protected  org.apache.oro.text.regex.Pattern[] _record_regexps
          array of regular expressions checkers that are used to match records explictily.
protected  OASecurityManager _secManager
          security manager
protected  java.lang.String _start_data
          Tags that signify the begining and ending of the data block.
protected  DOStringReader _string_reader
          dataobject string reader assigned to this source
protected  boolean _useAlternateDOXMLReader
          char buffer used to read data object XML into when reading multi-document DO XML source using readDOXMLAlternate().
(package private) static org.apache.log4j.Logger log
           
static java.lang.String MESSAGE_WRITER_PREFIX
          component prefix for MessageWriter properties
static java.lang.String MESSAGEID_ATTR
          constant for unique identifier attribute name
 
Constructor Summary
SimpleReaderDelegate()
           
 
Method Summary
protected  void createSecurityManager(java.util.Properties props, java.lang.String prefix)
          Creates and initialises the OASecurityManager if "SecurityManager.Enabled" is "true" in the properties file.
 boolean didReceiveMessage(AbstractMessageReader sender, DataObject[] message)
          Called when unpacking an AF message.
 DOStringReader getDOStringReader()
          Returns current instance of DOStringReader Can be null.
 java.lang.String getLastUID()
          Access method for last unique id for message
 java.io.LineNumberReader getLineNumberReader()
          get Input Line Number Reader
protected  java.lang.String getProperty(java.lang.String suffix)
          Returns the value of the property suffix associated with this component.
 java.io.Reader getReader()
          get Input Stream Reader
 OASecurityManager getSecurityManager()
          Returns the handle of OASecurityManager.
protected  XMLFormatter getXMLFormatter()
          Returns an XMLFormatter instance for reading/writing DataObjects as XML.
protected  java.lang.String getXMLString()
          Internal hacky method to read a single DealBus "XML" document into a string
protected  boolean isWhitespace(java.lang.String line)
           
 DataObject[] nextDataObjectArray()
          Called by Source poll, listen or callback implementation to get next DataObject array.
protected  java.lang.String normalisePrefix(java.lang.String prefix)
          Make sure props prefix is non-null and ends with "." if not empty.
protected  DataObject[] readDOStreamReader()
          Called by nextDataObjectArray() to read from DOStreamReader input.
protected  DataObject[] readDOStringReader()
          Called by nextDataObjectArray() to read from DOStringReader input.
protected  DataObject[] readDOXML()
          Called by nextDataObjectArray() to read DO XML format input.
protected  DataObject[] readDOXMLAlternate()
          Alternative DO XML reader orginally used by FileSource to workaround a bug reading very high volume multi document DO XML format input.
 void readerCleanUp()
          Normally called by Source sourceCleanUp() method.
 void readerEOF()
          Called by nextDataObjectArray() to indicate end of reader input reached.
 void readerException(java.lang.String status, java.lang.Exception e)
          Called by nextDataObjectArray() to indicate exception condition.
 void readerStartUp()
          Initialise and allocate resources.
 void setDOStringReader(java.lang.String class_name, java.util.Properties props, java.lang.String prefix)
          Sets string reader class for this sink (see dostrings package)
 void setFromProperties(java.util.Properties props, java.lang.String prefix, java.lang.String secPrefix)
          Set state from properties object.
 void setLineNumberReader(java.io.Reader reader)
          Set Line Number Reader
 void setReader(java.io.Reader reader)
          Set Input Stream Reader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

static org.apache.log4j.Logger log

MESSAGEID_ATTR

public static final java.lang.String MESSAGEID_ATTR
constant for unique identifier attribute name

See Also:
Constant Field Values

MESSAGE_WRITER_PREFIX

public static final java.lang.String MESSAGE_WRITER_PREFIX
component prefix for MessageWriter properties

See Also:
Constant Field Values

_formatter

protected XMLFormatter _formatter
holds the formatter that should be used by all component to to read and write adaptor framework message (XML)


_readerDelegate

protected DOMessageReaderDelegate _readerDelegate
the next delegate for components that implement the DOMessageReaderDelegate interface


_reader

protected java.io.Reader _reader
The input reader


_string_reader

protected DOStringReader _string_reader
dataobject string reader assigned to this source


_batch_size

protected int _batch_size
The number of records (DataObjects) to be sent in each Data Object array (0 = whole file). This is not used if the Source is reading dealbus "XML" format as batch size will be taken from "XML" document.


_start_data

protected java.lang.String _start_data
Tags that signify the begining and ending of the data block. Lines before _start_data and after _end_data will be ignored Useful when reading old style flat files with Header and/or Trailer records


_end_data

protected java.lang.String _end_data

_header_lines

protected int _header_lines
The number of header lines expected in the data, these will be discarded before attempting process records or XML


_useAlternateDOXMLReader

protected boolean _useAlternateDOXMLReader
char buffer used to read data object XML into when reading multi-document DO XML source using readDOXMLAlternate(). Use of this method is controlled by _useAlternateDOXMLReader. The reason we are doing this is that LineNumberReader falls over if you create one based on a whole stream and pass it down to the XMLFormatter directly and repeated call it


_comment_regexps

protected org.apache.oro.text.regex.Pattern[] _comment_regexps
array of regular expressions checkers that are used to match comments / line sto ignore in the file


_record_regexps

protected org.apache.oro.text.regex.Pattern[] _record_regexps
array of regular expressions checkers that are used to match records explictily. If there is at least one of these defined then only record that match one of these and do not match a regular expression for a comment will be processed


_re_matcher

protected org.apache.oro.text.regex.Perl5Matcher _re_matcher
regex compiler and matcher


_re_compiler

protected org.apache.oro.text.regex.Perl5Compiler _re_compiler

_secManager

protected OASecurityManager _secManager
security manager


_properties

protected java.util.Properties _properties
Reference to properties object and prefix. Needed by DOXML reader code.


_prefix

protected java.lang.String _prefix
Constructor Detail

SimpleReaderDelegate

public SimpleReaderDelegate()
Method Detail

setFromProperties

public void setFromProperties(java.util.Properties props,
                              java.lang.String prefix,
                              java.lang.String secPrefix)
                       throws IbafException
Set state from properties object.

Specified by:
setFromProperties in interface ReaderDelegate
Parameters:
props - Properties object
prefix - Prefix string to search for properties
secPrefix - Prefix string to search for security manager properties
Throws:
IbafException - Thrown if initialisation fails, mandatory properties are missing or properties cannot be parsed.

readerStartUp

public void readerStartUp()
                   throws IbafException
Initialise and allocate resources.

Specified by:
readerStartUp in interface ReaderDelegate
Throws:
IbafException

readerCleanUp

public void readerCleanUp()
                   throws IbafException
Normally called by Source sourceCleanUp() method.

Specified by:
readerCleanUp in interface ReaderDelegate
Throws:
IbafException

nextDataObjectArray

public DataObject[] nextDataObjectArray()
                                 throws IbafException
Called by Source poll, listen or callback implementation to get next DataObject array.

Specified by:
nextDataObjectArray in interface ReaderDelegate
Throws:
IbafException

readDOXML

protected DataObject[] readDOXML()
                          throws IbafException
Called by nextDataObjectArray() to read DO XML format input.

Throws:
IbafException

readDOStreamReader

protected DataObject[] readDOStreamReader()
                                   throws IbafException
Called by nextDataObjectArray() to read from DOStreamReader input.

Throws:
IbafException

readDOStringReader

protected DataObject[] readDOStringReader()
                                   throws IbafException
Called by nextDataObjectArray() to read from DOStringReader input.

Throws:
IbafException

readerEOF

public void readerEOF()
Called by nextDataObjectArray() to indicate end of reader input reached.

Specified by:
readerEOF in interface ReaderDelegate

readerException

public void readerException(java.lang.String status,
                            java.lang.Exception e)
                     throws IbafException
Called by nextDataObjectArray() to indicate exception condition.

Specified by:
readerException in interface ReaderDelegate
Throws:
IbafException

setDOStringReader

public void setDOStringReader(java.lang.String class_name,
                              java.util.Properties props,
                              java.lang.String prefix)
                       throws IbafException
Sets string reader class for this sink (see dostrings package)

Specified by:
setDOStringReader in interface ReaderDelegate
Parameters:
class - name of a DOStringReader
Throws:
IbafException

getDOStringReader

public DOStringReader getDOStringReader()
Returns current instance of DOStringReader Can be null.

Specified by:
getDOStringReader in interface ReaderDelegate

setReader

public void setReader(java.io.Reader reader)
               throws IbafException
Set Input Stream Reader

Specified by:
setReader in interface ReaderDelegate
Parameters:
reader - new input stream
Throws:
IbafException - If reader is null.

setLineNumberReader

public void setLineNumberReader(java.io.Reader reader)
                         throws IbafException
Set Line Number Reader

Specified by:
setLineNumberReader in interface ReaderDelegate
Parameters:
reader - new input stream
Throws:
IbafException - If reader is null or error reading header lines

getReader

public java.io.Reader getReader()
get Input Stream Reader

Specified by:
getReader in interface ReaderDelegate

getLineNumberReader

public java.io.LineNumberReader getLineNumberReader()
get Input Line Number Reader

Specified by:
getLineNumberReader in interface ReaderDelegate

readDOXMLAlternate

protected DataObject[] readDOXMLAlternate()
                                   throws IbafException
Alternative DO XML reader orginally used by FileSource to workaround a bug reading very high volume multi document DO XML format input.

Throws:
IbafException

getXMLString

protected java.lang.String getXMLString()
                                 throws java.io.IOException
Internal hacky method to read a single DealBus "XML" document into a string

Throws:
java.io.IOException

isWhitespace

protected boolean isWhitespace(java.lang.String line)

getProperty

protected java.lang.String getProperty(java.lang.String suffix)
Returns the value of the property suffix associated with this component. The property name is formed by concatenating _propsPrefixWithDot with suffix.

Parameters:
suffix - name of property (excluding component name)
Returns:
String value for property, or null if not defined.

getSecurityManager

public OASecurityManager getSecurityManager()
Returns the handle of OASecurityManager. Called by MessageReader / MessageWriters to use Security Features to read / send the secured messages. It will be null if security is set off in the properties file.


getXMLFormatter

protected XMLFormatter getXMLFormatter()
                                throws DataObjectException
Returns an XMLFormatter instance for reading/writing DataObjects as XML.

Supports the following properties:

NOTE the asterisk indicates the default setting (if any)

Also supports the following (deprecated) properties:

Which are retained for backwards compatibility; it is recommended that you do not use them in conjunction with any of the MessageWriter.* properties as they may be overridden, giving some (apparently) unexpected results.

Throws:
DataObjectException

didReceiveMessage

public boolean didReceiveMessage(AbstractMessageReader sender,
                                 DataObject[] message)
                          throws DataObjectException
Called when unpacking an AF message. This method examines the Wrapper message, and extracts the AF UniqueID (if any) from it, which it stores in _unpackedMessageID and sets flags to say it has read it. If _readerDelegate has been set, it passes the didReceiveMessage() along to it.

Specified by:
didReceiveMessage in interface DOMessageReaderDelegate
Parameters:
sender - The DataObjectMessageReader which received message
message - message received.
Returns:
true if there is no _readerDelegate, otherwise the return value of _readerDelegate.didReceiveMessage()
Throws:
DataObjectException - If there was a problem readin

getLastUID

public java.lang.String getLastUID()
Access method for last unique id for message


createSecurityManager

protected void createSecurityManager(java.util.Properties props,
                                     java.lang.String prefix)
                              throws IbafException
Creates and initialises the OASecurityManager if "SecurityManager.Enabled" is "true" in the properties file. The default is "false" - i.e. no security.

Throws:
IbafException

normalisePrefix

protected java.lang.String normalisePrefix(java.lang.String prefix)
Make sure props prefix is non-null and ends with "." if not empty.