BeanIO 2.0.4

org.beanio
Class StreamFactory

java.lang.Object
  extended by org.beanio.StreamFactory
Direct Known Subclasses:
DefaultStreamFactory

public abstract class StreamFactory
extends Object

A StreamFactory is used to load BeanIO mapping files and create BeanReader, BeanWriter, Unmarshaller and Marshaller instances.

The default StreamFactory implementation can be safely shared across multiple threads.

Since:
1.0
Author:
Kevin Seim
See Also:
BeanReader, BeanWriter, Unmarshaller, Marshaller

Constructor Summary
StreamFactory()
          Constructs a new StreamFactory.
 
Method Summary
abstract  Marshaller createMarshaller(String name)
          Creates a new Marshaller for marshalling bean objects.
 BeanReader createReader(String name, File file)
          Creates a new BeanReader for reading from a file.
 BeanReader createReader(String name, Reader in)
          Creates a new BeanReader for reading from the given input stream.
abstract  BeanReader createReader(String name, Reader in, Locale locale)
          Creates a new BeanReader for reading from a stream.
 BeanReader createReader(String name, String filename)
          Creates a new BeanReader for reading from a file.
 Unmarshaller createUnmarshaller(String name)
          Creates a new Unmarshaller for unmarshalling records.
abstract  Unmarshaller createUnmarshaller(String name, Locale locale)
          Creates a new Unmarshaller for unmarshalling records.
 BeanWriter createWriter(String name, File file)
          Creates a new BeanWriter for writing to the given file.
abstract  BeanWriter createWriter(String name, Writer out)
          Creates a new BeanWriter for writing to a stream.
protected  ClassLoader getClassLoader()
          Returns the class loader to use for resolving classpath resources and bean objects declared in a mapping file.
protected  void init()
          This method is invoked after a StreamFactory is loaded and all attributes have been set.
abstract  boolean isMapped(String streamName)
          Test whether a mapping configuration exists for a named stream.
 void load(File file)
          Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.
 void load(File file, Properties properties)
          Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.
 void load(InputStream in)
          Loads a BeanIO mapping file, and adds the configured streams to this factory.
abstract  void load(InputStream in, Properties properties)
          Loads a BeanIO mapping file, and adds the configured streams to this factory.
 void load(String filename)
          Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.
 void load(String filename, Properties properties)
          Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.
 void loadResource(String resource)
          Loads a BeanIO mapping file from the application's classpath.
 void loadResource(String resource, Properties properties)
          Loads a BeanIO mapping file from the application's classpath.
static StreamFactory newInstance()
          Returns a new StreamFactory instance.
static StreamFactory newInstance(ClassLoader classLoader)
          Returns a new StreamFactory instance.
protected  void setClassLoader(ClassLoader cl)
          Sets the class loader to use for resolving classpath resources and bean objects declared in a mapping files.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamFactory

public StreamFactory()
Constructs a new StreamFactory.

Method Detail

createReader

public BeanReader createReader(String name,
                               String filename)
                        throws IllegalArgumentException,
                               BeanReaderIOException
Creates a new BeanReader for reading from a file.

Parameters:
name - the name of the stream in the mapping file
filename - the name of the file to read
Returns:
the created BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream
BeanReaderIOException - if the file could not be opened for reading

createReader

public BeanReader createReader(String name,
                               File file)
                        throws IllegalArgumentException,
                               BeanReaderIOException
Creates a new BeanReader for reading from a file.

Parameters:
name - the name of the stream in the mapping file
file - the File to read
Returns:
the created BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream
BeanReaderIOException - if the file could not be opened for reading

createReader

public BeanReader createReader(String name,
                               Reader in)
                        throws IllegalArgumentException
Creates a new BeanReader for reading from the given input stream.

Parameters:
name - the name of the stream in the mapping file
in - the input stream to read from
Returns:
the created BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream

createReader

public abstract BeanReader createReader(String name,
                                        Reader in,
                                        Locale locale)
                                 throws IllegalArgumentException
Creates a new BeanReader for reading from a stream.

Parameters:
name - the name of the stream in the mapping file
in - the input stream to read from
locale - the Locale used to format error messages, or null to use Locale.getDefault()
Returns:
the created BeanReader
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support reading an input stream

createUnmarshaller

public Unmarshaller createUnmarshaller(String name)
                                throws IllegalArgumentException
Creates a new Unmarshaller for unmarshalling records.

Parameters:
name - the name of the stream in the mapping file
Returns:
the created Unmarshaller
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support unmarshalling

createUnmarshaller

public abstract Unmarshaller createUnmarshaller(String name,
                                                Locale locale)
Creates a new Unmarshaller for unmarshalling records.

Parameters:
name - the name of the stream in the mapping file
locale - the Locale used to format error messages, or null to use Locale.getDefault()
Returns:
the created Unmarshaller
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support unmarshalling

createWriter

public BeanWriter createWriter(String name,
                               File file)
                        throws IllegalArgumentException,
                               BeanWriterIOException
Creates a new BeanWriter for writing to the given file.

Parameters:
name - the name of the stream in the mapping file
file - the file to write to
Returns:
the created BeanWriter
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support writing to an output stream
BeanWriterIOException - if the file could not be opened for writing

createWriter

public abstract BeanWriter createWriter(String name,
                                        Writer out)
                                 throws IllegalArgumentException
Creates a new BeanWriter for writing to a stream.

Parameters:
name - the name of the stream in the mapping file
out - the output stream to write to
Returns:
the created BeanWriter
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support writing to an output stream

createMarshaller

public abstract Marshaller createMarshaller(String name)
                                     throws IllegalArgumentException
Creates a new Marshaller for marshalling bean objects.

Parameters:
name - the name of the stream in the mapping file
Returns:
the created Marshaller
Throws:
IllegalArgumentException - if there is no stream configured for the given name, or if the stream mapping mode does not support marshalling

loadResource

public void loadResource(String resource)
                  throws BeanIOException,
                         BeanIOConfigurationException
Loads a BeanIO mapping file from the application's classpath.

Parameters:
resource - the configuration resource name
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the mapping file is not found or invalid

loadResource

public void loadResource(String resource,
                         Properties properties)
                  throws BeanIOException,
                         BeanIOConfigurationException
Loads a BeanIO mapping file from the application's classpath.

Parameters:
resource - the configuration resource name
properties - user Properties for property substitution
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the mapping file is not found or invalid

load

public void load(String filename)
          throws BeanIOException,
                 BeanIOConfigurationException
Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.

Parameters:
filename - the name of the BeanIO configuration file to load
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the mapping file is invalid

load

public void load(String filename,
                 Properties properties)
          throws BeanIOException,
                 BeanIOConfigurationException
Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.

Parameters:
filename - the name of the BeanIO configuration file to load
properties - user Properties for property substitution
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the mapping file is invalid

load

public void load(File file)
          throws BeanIOException,
                 BeanIOConfigurationException
Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.

Parameters:
file - the BeanIO configuration file to load
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the mapping file is invalid

load

public void load(File file,
                 Properties properties)
          throws BeanIOException,
                 BeanIOConfigurationException
Loads a BeanIO mapping file from the file system, and adds the configured streams to this factory.

Parameters:
file - the BeanIO configuration file to load
properties - user Properties for property substitution
Throws:
BeanIOException - if an IOException or other fatal error is caught while loading the file
BeanIOConfigurationException - if the mapping file is invalid

load

public void load(InputStream in)
          throws IOException,
                 BeanIOConfigurationException
Loads a BeanIO mapping file, and adds the configured streams to this factory.

Parameters:
in - the input stream to read the mapping file from
Throws:
BeanIOException - if an IOException or other fatal error is caught while reading the input stream
BeanIOConfigurationException - if the mapping file is invalid
IOException

load

public abstract void load(InputStream in,
                          Properties properties)
                   throws IOException,
                          BeanIOConfigurationException
Loads a BeanIO mapping file, and adds the configured streams to this factory.

Parameters:
in - the input stream to read the mapping file from
properties - user Properties for property substitution
Throws:
BeanIOException - if an IOException or other fatal error is caught while reading the input stream
BeanIOConfigurationException - if the mapping file is invalid
IOException

newInstance

public static StreamFactory newInstance()
                                 throws BeanIOException
Returns a new StreamFactory instance. The implementation class is resolved using the the BeanIO configuration setting org.beanio.streamFactory.

Returns:
a new StreamFactory
Throws:
BeanIOException - if a StreamFactory could not be created
See Also:
Settings

newInstance

public static StreamFactory newInstance(ClassLoader classLoader)
                                 throws BeanIOException
Returns a new StreamFactory instance. An implementation class is loaded using the the BeanIO configuration setting org.beanio.streamFactory.

Parameters:
classLoader - the ClassLoader to use to load the stream factory and all subcomponents. If null, the current thread's context class loader is used. If there is no context class loader for the thread, the class loader that loaded this class is used.
Returns:
a new StreamFactory
Throws:
BeanIOException - if a StreamFactory could not be created
Since:
2.0
See Also:
Settings

isMapped

public abstract boolean isMapped(String streamName)
Test whether a mapping configuration exists for a named stream.

Parameters:
streamName - the stream name to test for existence
Returns:
true if a mapping configuration is found for the named stream
Since:
1.2

init

protected void init()
This method is invoked after a StreamFactory is loaded and all attributes have been set.

Since:
2.0

getClassLoader

protected ClassLoader getClassLoader()
Returns the class loader to use for resolving classpath resources and bean objects declared in a mapping file.

Returns:
the ClassLoader to use
Since:
2.0

setClassLoader

protected void setClassLoader(ClassLoader cl)
Sets the class loader to use for resolving classpath resources and bean objects declared in a mapping files.

Parameters:
cl - the ClassLoader to use
Since:
2.0

BeanIO 2.0.4

Copyright © 2010-2013 Kevin Seim