Class ParserImpl

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean _debug
      True if debug is enabled; false otherwise.
      protected ParserConfig myConfiguration
      The 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
      void closeParser()
      Close parser and deallocate resources.
      void debug​(java.lang.String msg)
      Writes a message to the log if debug mode is set.
      boolean debugMode()
      Returns current status of the debugMode flag.
      void flush()
      This method is called by some hosting components to flush any in-memory data to the current output stream.
      static java.lang.Object getClassInstance​(java.lang.String className)
      Create a parser instance.
      java.lang.Object getContext()
      Return the context in which this parser is running (e.g.
      boolean getDebug()
      Returns current status of the debugMode flag.
      java.io.InputStream getInputStream()
      Return current input-stream object.
      java.io.OutputStream getOutputStream()
      Return current output-stream object.
      java.lang.String getParam​(java.lang.String param)
      Return configuration value.
      ParserInterface getParser()
      Return the chained parser (future implementation).
      java.io.BufferedReader getReader()
      Return current reader object.
      java.io.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​(java.lang.String msg)
      Writes a message to the log.
      java.lang.Object querySchema​(java.lang.Object source)
      Discover the schema for the Parser.
      void registerScriptBeans​(ScriptEngine se)
      Register objects in the script engine.
      void setConfiguration​(ParserConfig config)
      Set the parser configuration.
      void setContext​(java.lang.Object context)
      Set the context in which the parser runs.
      void setDebug​(boolean debug)
      Sets the status of the debugMode flag.
      void setInputStream​(java.io.InputStream is)
      Set the parser input stream.
      void setInputStream​(java.io.Reader is)
      Use Reader object for input.
      void setInputStream​(java.lang.String is)
      Use a string as input.
      void setOutputStream​(java.io.OutputStream os)
      Set the parser output stream.
      void setOutputStream​(java.io.Writer os)
      Use Writer object for output.
      void setParam​(java.lang.String param, java.lang.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
    • Field Detail

      • myConfiguration

        protected ParserConfig myConfiguration
        The parser's configuration.
      • _debug

        protected volatile boolean _debug
        True if debug is enabled; false otherwise. May be accessed by different threads.
    • Constructor Detail

      • ParserImpl

        public ParserImpl()
        Default constructor.
    • 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:
        getContext in interface ParserInterface
        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:
        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
      • setParam

        public void setParam​(java.lang.String param,
                             java.lang.String value)
        Set parser configuration value.
        Specified by:
        setParam in interface ParserInterface
        Parameters:
        param - The parameter name
        value - The parameter value
      • getParam

        public java.lang.String getParam​(java.lang.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​(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:
        setInputStream in interface ParserInterface
        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:
        setOutputStream in interface ParserInterface
        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:
        setInputStream in interface ParserInterface
        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:
        setInputStream in interface ParserInterface
        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:
        setOutputStream in interface ParserInterface
        Parameters:
        os - Writer object
      • getReader

        public java.io.BufferedReader getReader()
        Return current reader object.
        Specified by:
        getReader in interface ParserInterface
        Returns:
        The reader object being used for input
      • getWriter

        public java.io.BufferedWriter getWriter()
        Return current writer object.
        Specified by:
        getWriter in interface ParserInterface
        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.Exception
        Perform initialization of parser.
        Specified by:
        initParser in interface ParserInterface
        Throws:
        java.lang.Exception - if an error occurs.
      • closeParser

        public void closeParser()
                         throws java.lang.Exception
        Close parser and deallocate resources. This method closes the input and output streams.
        Specified by:
        closeParser in interface ParserInterface
        Throws:
        java.lang.Exception - if an error occurs.
      • getClassInstance

        public static java.lang.Object getClassInstance​(java.lang.String className)
                                                 throws java.lang.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:
        java.lang.Exception -
      • if the className could not be found.
      • if the constructor is not visible to the sender.
      • if the instance could not be created.
      • 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:
        true if debug mode is enabled, false otherwise.
      • getDebug

        public boolean getDebug()
        Returns current status of the debugMode flag. May be called by different threads.
        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. May be called by different threads.
        Specified by:
        setDebug in interface ParserInterface
        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:
        registerScriptBeans in interface ParserInterface
        Parameters:
        se - The script engine
        Throws:
        java.lang.Exception
      • flush

        public void flush()
                   throws java.lang.Exception
        This method is called by some hosting components to flush any in-memory data to the current output stream.
        Specified by:
        flush in interface ParserInterface
        Throws:
        java.lang.Exception
      • isDeltaSupported

        public boolean isDeltaSupported()
        Returns true if this connector is able to perform delta updates
        Specified by:
        isDeltaSupported in interface ParserInterface
        Returns:
        false
      • querySchema

        public java.lang.Object querySchema​(java.lang.Object source)
                                     throws java.lang.Exception
        Discover 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:
        querySchema in interface ParserInterface
        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