Package com.ibm.di.parser
Class ParserImpl
- java.lang.Object
-
- com.ibm.di.parser.ParserImpl
-
- All Implemented Interfaces:
ParserInterface,VersionInfoInterface
- Direct Known Subclasses:
CSVParser,Dsmlv2Parser,FixedRecordParser,HTTPParser,JSONParser,LDIFParser,LineReader,ScriptParser,SimpleParser,XMLParser,XMLParser2,XMLSaxParser,XSLbasedXMLParser
public abstract class ParserImpl extends java.lang.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
Fields Modifier and Type Field Description protected boolean_debugTrueif debug is enabled;falseotherwise.protected ParserConfigmyConfigurationThe parser's configuration.
-
Constructor Summary
Constructors Constructor Description ParserImpl()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseParser()Close parser and deallocate resources.voiddebug(java.lang.String msg)Writes a message to the log if debug mode is set.booleandebugMode()Returns current status of the debugMode flag.voidflush()This method is called by some hosting components to flush any in-memory data to the current output stream.static java.lang.ObjectgetClassInstance(java.lang.String className)Create a parser instance.java.lang.ObjectgetContext()Return the context in which this parser is running (e.g.booleangetDebug()Returns current status of the debugMode flag.java.io.InputStreamgetInputStream()Return current input-stream object.java.io.OutputStreamgetOutputStream()Return current output-stream object.java.lang.StringgetParam(java.lang.String param)Return configuration value.ParserInterfacegetParser()Return the chained parser (future implementation).java.io.BufferedReadergetReader()Return current reader object.java.io.BufferedWritergetWriter()Return current writer object.voidinitParser()Perform initialization of parser.booleanisDeltaSupported()Returns true if this connector is able to perform delta updatesvoidlogmsg(java.lang.String msg)Writes a message to the log.java.lang.ObjectquerySchema(java.lang.Object source)Discover the schema for the Parser.voidregisterScriptBeans(ScriptEngine se)Register objects in the script engine.voidsetConfiguration(ParserConfig config)Set the parser configuration.voidsetContext(java.lang.Object context)Set the context in which the parser runs.voidsetDebug(boolean debug)Sets the status of the debugMode flag.voidsetInputStream(java.io.InputStream is)Set the parser input stream.voidsetInputStream(java.io.Reader is)Use Reader object for input.voidsetInputStream(java.lang.String is)Use a string as input.voidsetOutputStream(java.io.OutputStream os)Set the parser output stream.voidsetOutputStream(java.io.Writer os)Use Writer object for output.voidsetParam(java.lang.String param, java.lang.String value)Set parser configuration value.voidsetParser(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
The parser's configuration.
-
_debug
protected volatile boolean _debug
Trueif debug is enabled;falseotherwise. May be accessed by different threads.
-
-
Method Detail
-
getContext
public java.lang.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 build-in method but sub-classes may use the context object to communicate with the "housing" object. This object is typically a connector. If the object using this class is not setting the context then the return value is null.- Specified by:
getContextin interfaceParserInterface- Returns:
- The object housing this parser
-
setContext
public void setContext(java.lang.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:
setContextin interfaceParserInterface- Parameters:
context- The context object
-
setParser
public void setParser(ParserInterface parser)
Set the chained parser (future implementation).- Specified by:
setParserin interfaceParserInterface- Parameters:
parser- The chained parser
-
getParser
public ParserInterface getParser()
Return the chained parser (future implementation).- Specified by:
getParserin interfaceParserInterface- Returns:
- The chained parser
-
setParam
public void setParam(java.lang.String param, java.lang.String value)Set parser configuration value.- Specified by:
setParamin interfaceParserInterface- Parameters:
param- The parameter namevalue- The parameter value
-
getParam
public java.lang.String getParam(java.lang.String param)
Return configuration value.- Specified by:
getParamin interfaceParserInterface- 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:
setConfigurationin interfaceParserInterface- Parameters:
config- The configuration object
-
setInputStream
public void setInputStream(java.io.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:
setInputStreamin interfaceParserInterface- Parameters:
is- The InputStream object (e.g. FileInputStream, SocketInputStream etc. ..)
-
setOutputStream
public void setOutputStream(java.io.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:
setOutputStreamin interfaceParserInterface- Parameters:
os- The OutputStream object (e.g. FileOutputStream, SocketOutputStream etc. ..)
-
setInputStream
public void setInputStream(java.lang.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:
setInputStreamin interfaceParserInterface- Parameters:
is- String to read data from
-
setInputStream
public void setInputStream(java.io.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:
setInputStreamin interfaceParserInterface- Parameters:
is- Reader object
-
setOutputStream
public void setOutputStream(java.io.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:
setOutputStreamin interfaceParserInterface- Parameters:
os- Writer object
-
getReader
public java.io.BufferedReader getReader()
Return current reader object.- Specified by:
getReaderin interfaceParserInterface- Returns:
- The reader object being used for input
-
getWriter
public java.io.BufferedWriter getWriter()
Return current writer object.- Specified by:
getWriterin interfaceParserInterface- Returns:
- The writer object being used for output
-
getInputStream
public java.io.InputStream getInputStream()
Return current input-stream object. This may be null if the parser was initialized with a Reader object.- Returns:
- The inputstream object being used for input
-
getOutputStream
public java.io.OutputStream getOutputStream()
Return current output-stream object. This may be null if the parser was initialized with a Writer object.- Returns:
- The outputstream object being used for output
-
initParser
public void initParser() throws java.lang.ExceptionPerform initialization of parser.- Specified by:
initParserin interfaceParserInterface- Throws:
java.lang.Exception- if an error occurs.
-
closeParser
public void closeParser() throws java.lang.ExceptionClose parser and deallocate resources. This method closes the input and output streams.- Specified by:
closeParserin interfaceParserInterface- Throws:
java.lang.Exception- if an error occurs.
-
getClassInstance
public static java.lang.Object getClassInstance(java.lang.String className) throws java.lang.ExceptionCreate 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:
java.lang.Exception-- if the
classNamecould not be found.- if the constructor is not visible to the sender.
- if the instance could not be created.
- if the
-
logmsg
public void logmsg(java.lang.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(java.lang.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. May be called by different threads.- Returns:
trueif debug mode is enabled,falseotherwise.
-
getDebug
public boolean getDebug()
Returns current status of the debugMode flag. May be called by different threads.- Specified by:
getDebugin interfaceParserInterface- Returns:
- True if debug mode is enabled, false otherwise.
-
setDebug
public void setDebug(boolean debug)
Sets the status of the debugMode flag. May be called by different threads.- Specified by:
setDebugin interfaceParserInterface- Parameters:
debug- True if debug mode is enabled, false otherwise.
-
registerScriptBeans
public void registerScriptBeans(ScriptEngine se) throws java.lang.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:
registerScriptBeansin interfaceParserInterface- Parameters:
se- The script engine- Throws:
java.lang.Exception
-
flush
public void flush() throws java.lang.ExceptionThis method is called by some hosting components to flush any in-memory data to the current output stream.- Specified by:
flushin interfaceParserInterface- Throws:
java.lang.Exception
-
isDeltaSupported
public boolean isDeltaSupported()
Returns true if this connector is able to perform delta updates- Specified by:
isDeltaSupportedin interfaceParserInterface- Returns:
false
-
querySchema
public java.lang.Object querySchema(java.lang.Object source) throws java.lang.ExceptionDiscover the schema for the Parser. For example, a XML Parser could return a representation of the XML Schema or the DTD referenced in a XML file.- Specified by:
querySchemain interfaceParserInterface- Parameters:
source- The object on which to discover schema- Returns:
- A Vector of com.ibm.di.entry.Entry objects describing each entity
- Throws:
java.lang.Exception- If an I/O error occurs
-
-