com.ibm.di.parser
Class ParserImpl

java.lang.Object
  extended by com.ibm.di.parser.ParserImpl
All Implemented Interfaces:
ParserInterface, VersionInfoInterface
Direct Known Subclasses:
CSVParser, Dsmlv2Parser, FixedRecordParser, HTTPParser, LDIFParser, LineReader, ScriptParser, SimpleParser, SPMLv2Parser, XMLParser, XMLSaxParser, XSLbasedXMLParser

public abstract class ParserImpl
extends Object
implements ParserInterface, VersionInfoInterface

The ParserImpl class provides the base class for parser implementations. This class provides common methods and properties that apply to all parsers.


Field Summary
protected  boolean _debug
           
protected  ParserConfig myConfiguration
           
 
Constructor Summary
ParserImpl()
           
 
Method Summary
 void closeParser()
          Close parser and deallocate resources.
 void debug(String msg)
          Writes a message to the log if debug mode is set.
 boolean debugMode()
          Returns current status of the debugMode flag.
 void flush()
          Flush any data to the output stream.
static Object getClassInstance(String className)
          Create a parser instance.
 Object getContext()
          Return the context in which this parser is running (e.g.
 boolean getDebug()
          Returns current status of the debugMode flag.
 InputStream getInputStream()
          Return current input-stream object.
 OutputStream getOutputStream()
          Return current output-stream object.
 String getParam(String param)
          Return configuration value.
 ParserInterface getParser()
          Return the chained parser (future implementation).
 BufferedReader getReader()
          Return current reader object.
 BufferedWriter getWriter()
          Return current writer object.
 void initParser()
          Perform initialization of parser.
 boolean isDeltaSupported()
          Returns true if this connector is able to perform delta updates
 void logmsg(String msg)
          Writes a message to the log.
 void registerScriptBeans(ScriptEngine se)
          Register objects in the script engine.
 void setConfiguration(ParserConfig config)
          Set the parser configuration.
 void setContext(Object context)
          Set the context in which the parser runs.
 void setDebug(boolean debug)
          Sets the status of the debugMode flag.
 void setInputStream(InputStream is)
          Set the parser input stream.
 void setInputStream(Reader is)
          Use Reader object for input.
 void setInputStream(String is)
          Use a string as input.
 void setOutputStream(OutputStream os)
          Set the parser output stream.
 void setOutputStream(Writer os)
          Use Writer object for output.
 void setParam(String param, String value)
          Set parser configuration value.
 void setParser(ParserInterface parser)
          Set the chained parser (future implementation).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ibm.di.parser.ParserInterface
readEntry, writeEntry
 
Methods inherited from interface com.ibm.di.server.VersionInfoInterface
getVersion
 

Field Detail

myConfiguration

protected ParserConfig myConfiguration

_debug

protected boolean _debug
Constructor Detail

ParserImpl

public ParserImpl()
Method Detail

getContext

public Object getContext()
Return the context in which this parser is running (e.g. AssemblyLine object). The context is called upon when the parser needs to access resources outside it's scope. The logmsg method is one such builtin method but sub-classes may use the context object to communicate with the "housing" object. This object is typically a connector or an EventHandler. If the object using this class is not setting the context then the return value is null.

Specified by:
getContext in interface ParserInterface
Returns:
The object housing this parser

setContext

public void setContext(Object context)
Set the context in which the parser runs. This method is optionally called by any object that wants to make itself visible to the parser.

Specified by:
setContext in interface ParserInterface
Parameters:
context - The context object

setParser

public void setParser(ParserInterface parser)
Set the chained parser (future implementation).

Specified by:
setParser in interface ParserInterface
Parameters:
parser - The chained parser

getParser

public ParserInterface getParser()
Return the chained parser (future implementation).

Specified by:
getParser in interface ParserInterface
Returns:
The chained parser

setParam

public void setParam(String param,
                     String value)
Set parser configuration value.

Specified by:
setParam in interface ParserInterface
Parameters:
param - The parameter name
value - The parameter value

getParam

public String getParam(String param)
Return configuration value.

Specified by:
getParam in interface ParserInterface
Parameters:
param - The name of the parameter to return
Returns:
The value associated with the parameter or null.

setConfiguration

public void setConfiguration(ParserConfig config)
Set the parser configuration. This method is called by instantiating classes to provide the parser with a configuration object.

Specified by:
setConfiguration in interface ParserInterface
Parameters:
config - The configuration object

setInputStream

public void setInputStream(InputStream is)
Set the parser input stream. This method sets the input stream object from which the parser will read it's data. If the configuration has an encryptionKey parameter set, then this method will make an instance of the EncryptedReader to decrypt the underlying input stream. If no encryptionKey is specified then an instance of java.io.BufferedReader is used to provide buffered access to the input stream. Also, if the characterSet configuration parameter is set the input stream is read/decoded according the character set specified by that parameter.

Specified by:
setInputStream in interface ParserInterface
Parameters:
is - The InputStream object (e.g. FileInputStream, SocketInputStream etc. ..)

setOutputStream

public void setOutputStream(OutputStream os)
Set the parser output stream. This method sets the output stream object to which the parser will write it's data. If the configuration has an encryptionKey parameter set, then this method will make an instance of the EncryptedWriter to encrypt data to the underlying output stream. If no encryptionKey is specified then an instance of java.io.BufferedWriter is used to provide buffered access to the output stream. Also, if the characterSet configuration parameter is set the output stream is written according the character set specified by that parameter.

Specified by:
setOutputStream in interface ParserInterface
Parameters:
os - The OutputStream object (e.g. FileOutputStream, SocketOutputStream etc. ..)

setInputStream

public void setInputStream(String is)
Use a string as input. This method creates an instance of the StringReader class to read data from a String rather than an input stream.

Specified by:
setInputStream in interface ParserInterface
Parameters:
is - String to read data from

setInputStream

public void setInputStream(Reader is)
Use Reader object for input. This method creates an instance of the BufferedReader class providing the is reader object as input. Use this method to pass an already created instance of any Reader class (e.g. FileReader, StringReader ...). If the encryptionKey parameter is set an instance of the EncryptedReader is used on top of the provided Reader to decrypt the input stream.

Specified by:
setInputStream in interface ParserInterface
Parameters:
is - Reader object

setOutputStream

public void setOutputStream(Writer os)
Use Writer object for output. This method creates an instance of the BufferedWriter class providing the os writer object as input. Use this method to pass an already created instance of any Writer class (e.g. FileReader, StringReader ...). If the encryptionKey parameter is set an instance of the EncryptedWriter is used on top of the provided Writer to encrypt the output stream.

Specified by:
setOutputStream in interface ParserInterface
Parameters:
os - Writer object

getReader

public BufferedReader getReader()
Return current reader object.

Specified by:
getReader in interface ParserInterface
Returns:
The reader object being used for input

getWriter

public BufferedWriter getWriter()
Return current writer object.

Specified by:
getWriter in interface ParserInterface
Returns:
The writer object being used for output

getInputStream

public InputStream getInputStream()
Return current input-stream object. This may be null if the parser was initialied with a Reader object.

Returns:
The inputstream object being used for input

getOutputStream

public OutputStream getOutputStream()
Return current output-stream object. This may be null if the parser was initialied with a Writer object.

Returns:
The outputstream object being used for output

initParser

public void initParser()
                throws Exception
Perform initialization of parser.

Specified by:
initParser in interface ParserInterface
Throws:
Exception

closeParser

public void closeParser()
                 throws Exception
Close parser and deallocate resources. This method closes the input and output streams.

Specified by:
closeParser in interface ParserInterface
Throws:
Exception

getClassInstance

public static Object getClassInstance(String className)
                               throws Exception
Create a parser instance. This method dynamically creates a new instance of a parser class based on the class name provided.

Parameters:
className - The complete Java class name
Returns:
The parser class instance
Throws:
Exception

logmsg

public void logmsg(String msg)
Writes a message to the log. If the parser has a context then the context is examined for a known class (like connector, switchboard) and then calls the context's logmsg method. If no context exists or the context object type is unknown nothing is done.

Parameters:
msg - The log message

debug

public void debug(String msg)
Writes a message to the log if debug mode is set.

Parameters:
msg - The log message

debugMode

public boolean debugMode()
Returns current status of the debugMode flag.

Returns:
True if debug mode is enabled, false otherwise.

getDebug

public boolean getDebug()
Returns current status of the debugMode flag.

Specified by:
getDebug in interface ParserInterface
Returns:
True if debug mode is enabled, false otherwise.

setDebug

public void setDebug(boolean debug)
Sets the status of the debugMode flag.

Specified by:
setDebug in interface ParserInterface
Parameters:
debug - True if debug mode is enabled, false otherwise.

registerScriptBeans

public void registerScriptBeans(ScriptEngine se)
                         throws Exception
Register objects in the script engine. This method may be called by a hosting object to let the parser register objects in the script engine. This allows the user to access parser specific objects using predefined names in the scripting environment. The default implementation is to declare parser as a reference to the parser class instance.

Specified by:
registerScriptBeans in interface ParserInterface
Parameters:
se - The script engine
Throws:
Exception

flush

public void flush()
           throws Exception
Flush any data to the output stream.

Specified by:
flush in interface ParserInterface
Throws:
Exception

isDeltaSupported

public boolean isDeltaSupported()
Returns true if this connector is able to perform delta updates

Specified by:
isDeltaSupported in interface ParserInterface
Returns:
true if delta updates are supported, false otherwise