de.dante.extex.scanner.stream
Class TokenStreamFactory

java.lang.Object
  extended byde.dante.util.framework.AbstractFactory
      extended byde.dante.extex.scanner.stream.TokenStreamFactory
All Implemented Interfaces:
Configurable, LogEnabled, OpenFileObservable, OpenReaderObservable, OpenStringObservable, RegistrarObserver

public class TokenStreamFactory
extends AbstractFactory
implements OpenFileObservable, OpenStringObservable, OpenReaderObservable

This is the factory to provide an instance of a TokenStream. Like any good factory it is controlled by its configuration.

Configuration

Mainly the configuration needs to specify which class to use for the TokenStream. The name of the class is given as the argument class as shown below.

   <Scanner class="the.pack.age.TheClass"/>
 

The class given must implement the interface TokenStream. In addition an appropriate constructor is required:

     public TheClass(Configuration config, Reader reader, Boolean isFile,
          final String theSource) throws IOException
 

If the Token stream is fed from a file then the additional parameter buffersize is taken into account. This parameter is optional. Its usage can look as follows:

   <Scanner class="the.pack.age.TheClass"
         buffersize="0"/>
 
The value given is a number. If this number is positive then it is interpreted as the size of the buffer for the file reading operation. If it is 0 or empty then no buffer will be used. If it is negative, then the default buffer size will be used.

In addition to the class for the Token stream the reader class can be specified for the case that reading from a file is requested. In this case the mapping from bytes to characters according to an encoding. The name is given as the parameter reader as shown below:

   <Scanner class="the.pack.age.TheClass"
         reader="another.pack.age.TheReaderClass"/>
 

Note that the attribute reader is optional. If none is given or the value is the empty string then java.io.InputStreamReader is used instead.

Observable Events

Observers can be registered for several events:

file
This event is triggered by the request for a TokenStream fed from a file. It is deferred until the file has been found and opened. The name of the file is passed as argument to the observer.
reader
This event is triggered by the request for a TokenStream fed from an arbitrary Reader. The reader is passed as argument to the observer.
string
This event is triggered by the request for a TokenStream fed from a String. The string is passed as argument to the observer.

Version:
$Revision: 1.38 $
Author:
Gerd Neugebauer, Michael Niedermair

Constructor Summary
TokenStreamFactory(Configuration theConfiguration, java.lang.String tag)
          Creates a new object.
 
Method Summary
 ResourceFinder getResourceFinder()
          Returns the file finder.
 TokenStream newInstance(java.lang.CharSequence line)
          Provide a new instance of a token stream reading from a string.
 TokenStream newInstance(java.io.Reader reader)
          Provide a new instance of a token stream reading from a Reader.
 TokenStream newInstance(java.lang.String name, java.lang.String type, java.lang.String encoding)
          Provide a new instance of a token stream reading from a file or other resource.
 void register(StreamDecorator decorator)
          Register a input stream decorator to be applied for each token stream originated at a resource.
 void registerObserver(OpenFileObserver observer)
          Register an expand observer for later use.
 void registerObserver(OpenReaderObserver observer)
          Register an open reader observer for later use.
 void registerObserver(OpenStringObserver observer)
          Register an expand observer for later use.
 void setOptions(TokenStreamOptions options)
          Setter for options.
 void setResourceFinder(ResourceFinder finder)
          Setter for the file finder.
 
Methods inherited from class de.dante.util.framework.AbstractFactory
configure, configure, createInstance, createInstance, createInstance, createInstanceForConfiguration, createInstanceForConfiguration, createInstanceForConfiguration, enableLogging, enableLogging, getConfiguration, getLogger, reconnect, selectConfiguration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TokenStreamFactory

public TokenStreamFactory(Configuration theConfiguration,
                          java.lang.String tag)
                   throws ConfigurationException
Creates a new object.

Parameters:
theConfiguration - the configuration to use
tag - the tag name of the sub-configuration to use
Throws:
ConfigurationException - in case of an error in the configuration
Method Detail

getResourceFinder

public ResourceFinder getResourceFinder()
Returns the file finder.

Returns:
Returns the file finder.

newInstance

public TokenStream newInstance(java.lang.CharSequence line)
                        throws ConfigurationException
Provide a new instance of a token stream reading from a string.

Parameters:
line - the line of input to read from
Returns:
the new instance
Throws:
ConfigurationException - in case of an error in the configuration

newInstance

public TokenStream newInstance(java.io.Reader reader)
                        throws ConfigurationException
Provide a new instance of a token stream reading from a Reader.

Parameters:
reader - the reader to get new characters from
Returns:
the new instance
Throws:
ConfigurationException - in case of an error in the configuration

newInstance

public TokenStream newInstance(java.lang.String name,
                               java.lang.String type,
                               java.lang.String encoding)
                        throws ConfigurationException
Provide a new instance of a token stream reading from a file or other resource.

Parameters:
name - the name of the file to be read
type - the type of the file to be read
encoding - the name of the encoding to use
Returns:
the new instance or null if the resource could not be located
Throws:
ConfigurationException - in case of an error in the configuration

register

public void register(StreamDecorator decorator)
Register a input stream decorator to be applied for each token stream originated at a resource.

Parameters:
decorator - the additional decorator

registerObserver

public void registerObserver(OpenFileObserver observer)
Description copied from interface: OpenFileObservable
Register an expand observer for later use.

Specified by:
registerObserver in interface OpenFileObservable
Parameters:
observer - the observer to be registered
See Also:
OpenFileObservable.registerObserver( de.dante.extex.scanner.stream.observer.file.OpenFileObserver)

registerObserver

public void registerObserver(OpenReaderObserver observer)
Description copied from interface: OpenReaderObservable
Register an open reader observer for later use.

Specified by:
registerObserver in interface OpenReaderObservable
Parameters:
observer - the observer to be registered
See Also:
OpenReaderObservable.registerObserver( de.dante.extex.scanner.stream.observer.reader.OpenReaderObserver)

registerObserver

public void registerObserver(OpenStringObserver observer)
Description copied from interface: OpenStringObservable
Register an expand observer for later use.

Specified by:
registerObserver in interface OpenStringObservable
Parameters:
observer - the observer to be registered
See Also:
OpenStringObservable.registerObserver( de.dante.extex.scanner.stream.observer.string.OpenStringObserver)

setOptions

public void setOptions(TokenStreamOptions options)
Setter for options.

Parameters:
options - the options to set.

setResourceFinder

public void setResourceFinder(ResourceFinder finder)
Setter for the file finder.

Parameters:
finder - the new file finder