|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.extex.framework.AbstractFactory
org.extex.scanner.stream.TokenStreamFactory
public class TokenStreamFactory
This is the factory to provide an instance of a
TokenStream. Like any good factory
it is controlled by its 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,
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.
Observers can be registered for several events:
| Field Summary |
|---|
| Fields inherited from class org.extex.framework.AbstractFactory |
|---|
DEFAULT_ATTRIBUTE, SELECT_ATTRIBUTE |
| Constructor Summary | |
|---|---|
TokenStreamFactory(java.lang.String tag)
Creates a new object. |
|
| Method Summary | |
|---|---|
void |
configure(Configuration config)
Configure an object according to a given Configuration. |
TokenStream |
getStream(java.lang.CharSequence line)
Provide a new instance of a token stream reading from a string. |
TokenStream |
getStream(java.io.Reader reader)
Provide a new instance of a token stream reading from a Reader. |
protected TokenStream |
getStream(java.io.Reader reader,
java.lang.Boolean isFile,
java.lang.String source)
Provide a new instance of a token stream reading from a Reader. |
TokenStream |
getStream(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(InputStreamInterceptor interceptor)
Register an input stream interceptor to be applied for each token stream originated at a resource. |
void |
register(OutputStreamInterceptor interceptor)
Register an output stream interceptor to be applied for each output stream. |
void |
register(ReaderInterceptor interceptor)
Register a reader interceptor to be applied for each token stream originated at a resource. |
void |
register(WriterInterceptor interceptor)
Register a writer interceptor to be applied for each writer. |
void |
registerObserver(OpenFileObserver observer)
Register an open file observer for later use. |
void |
registerObserver(OpenReaderObserver observer)
Register an open reader observer for later use. |
void |
registerObserver(OpenStringObserver observer)
Register an open string observer for later use. |
void |
registerObserver(OpenWriterObserver observer)
Register an open reader observer for later use. |
void |
setOptions(TokenStreamOptions options)
Setter for options. |
java.io.Writer |
writerStream(java.io.OutputStream stream,
java.lang.String key,
java.lang.String encoding)
Construct a Writer for an output stream. |
| Methods inherited from class org.extex.framework.AbstractFactory |
|---|
configure, createInstance, createInstance, createInstance, createInstance, createInstanceForConfiguration, createInstanceForConfiguration, createInstanceForConfiguration, enableLogging, enableLogging, getConfiguration, getLogger, getResourceFinder, reconnect, selectConfiguration, setResourceFinder |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TokenStreamFactory(java.lang.String tag)
throws ConfigurationException
tag - the tag name of the sub-configuration to use
ConfigurationException - in case of an error in the configuration| Method Detail |
|---|
public void configure(Configuration config)
throws ConfigurationException
configure in interface Configurableconfigure in class AbstractFactoryconfig - the configuration object to consider
ConfigurationException - in case that something went wrongAbstractFactory.configure(
org.extex.framework.configuration.Configuration)
public TokenStream getStream(java.lang.CharSequence line)
throws ConfigurationException
line - the line of input to read from
ConfigurationException - in case of an error in the configuration
public TokenStream getStream(java.io.Reader reader)
throws ConfigurationException
reader - the reader to get new characters from
ConfigurationException - in case of an error in the configuration
protected TokenStream getStream(java.io.Reader reader,
java.lang.Boolean isFile,
java.lang.String source)
throws ConfigurationException
reader - the reader to get new characters fromisFile - the indicator for file readerssource - the description of the source
ConfigurationException - in case of an error in the configuration
public TokenStream getStream(java.lang.String name,
java.lang.String type,
java.lang.String encoding)
throws ConfigurationException
name - the name of the file to be readtype - the type of the file to be readencoding - the name of the encoding to use
null if the resource could not
be located
ConfigurationException - in case of an error in the configurationpublic void register(InputStreamInterceptor interceptor)
interceptor - the additional interceptorpublic void register(OutputStreamInterceptor interceptor)
interceptor - the additional interceptorpublic void register(ReaderInterceptor interceptor)
interceptor - the additional interceptorpublic void register(WriterInterceptor interceptor)
interceptor - the additional interceptorpublic void registerObserver(OpenFileObserver observer)
OpenFileObservable
registerObserver in interface OpenFileObservableobserver - the observer to be registeredOpenFileObservable.registerObserver(
org.extex.scanner.stream.observer.file.OpenFileObserver)public void registerObserver(OpenReaderObserver observer)
OpenReaderObservable
registerObserver in interface OpenReaderObservableobserver - the observer to be registeredOpenReaderObservable.registerObserver(
org.extex.scanner.stream.observer.reader.OpenReaderObserver)public void registerObserver(OpenStringObserver observer)
OpenStringObservable
registerObserver in interface OpenStringObservableobserver - the observer to be registeredOpenStringObservable.registerObserver(
org.extex.scanner.stream.observer.string.OpenStringObserver)public void registerObserver(OpenWriterObserver observer)
registerObserver in interface OpenWriterObservableobserver - the observer to be registeredOpenWriterObservable.registerObserver(
org.extex.scanner.stream.observer.writer.OpenWriterObserver)public void setOptions(TokenStreamOptions options)
options - the options to set.
public java.io.Writer writerStream(java.io.OutputStream stream,
java.lang.String key,
java.lang.String encoding)
throws java.io.UnsupportedEncodingException
The encoding can be given as a hint.
stream - the stream to put bytes tokey - the name in terms of the interpreterencoding - the optional encoding. If the encoding is
null then it is ignored
java.io.UnsupportedEncodingException - in case of an error with the
encoding
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||