public abstract class StreamFactory extends Object
BeanReader
, BeanWriter
, Unmarshaller
and Marshaller
instances.
The default StreamFactory implementation can be safely shared across multiple threads.
BeanReader
,
BeanWriter
,
Unmarshaller
,
Marshaller
Constructor and Description |
---|
StreamFactory()
Constructs a new StreamFactory.
|
Modifier and Type | Method and Description |
---|---|
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.
|
abstract void |
define(StreamBuilder builder)
Defines a new stream mapping.
|
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.
|
public BeanReader createReader(String name, String filename) throws IllegalArgumentException, BeanReaderIOException
name
- the name of the stream in the mapping filefilename
- the name of the file to readBeanReader
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support reading an input streamBeanReaderIOException
- if the file could not be opened for readingpublic BeanReader createReader(String name, File file) throws IllegalArgumentException, BeanReaderIOException
name
- the name of the stream in the mapping filefile
- the File
to readBeanReader
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support reading an input streamBeanReaderIOException
- if the file could not be opened for readingpublic BeanReader createReader(String name, Reader in) throws IllegalArgumentException
name
- the name of the stream in the mapping filein
- the input stream to read fromBeanReader
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support reading an input streampublic abstract BeanReader createReader(String name, Reader in, Locale locale) throws IllegalArgumentException
name
- the name of the stream in the mapping filein
- the input stream to read fromlocale
- the Locale
used to format error messages, or null to use Locale.getDefault()
BeanReader
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support reading an input streampublic Unmarshaller createUnmarshaller(String name) throws IllegalArgumentException
Unmarshaller
for unmarshalling records.name
- the name of the stream in the mapping fileUnmarshaller
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support unmarshallingpublic abstract Unmarshaller createUnmarshaller(String name, Locale locale)
Unmarshaller
for unmarshalling records.name
- the name of the stream in the mapping filelocale
- the Locale
used to format error messages, or null to use Locale.getDefault()
Unmarshaller
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support unmarshallingpublic BeanWriter createWriter(String name, File file) throws IllegalArgumentException, BeanWriterIOException
name
- the name of the stream in the mapping filefile
- the file to write toBeanWriter
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support writing to an output streamBeanWriterIOException
- if the file could not be opened for writingpublic abstract BeanWriter createWriter(String name, Writer out) throws IllegalArgumentException
name
- the name of the stream in the mapping fileout
- the output stream to write toBeanWriter
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support writing to an output streampublic abstract Marshaller createMarshaller(String name) throws IllegalArgumentException
Marshaller
for marshalling bean objects.name
- the name of the stream in the mapping fileMarshaller
IllegalArgumentException
- if there is no stream configured for the given name, or
if the stream mapping mode does not support marshallingpublic abstract void define(StreamBuilder builder) throws BeanIOConfigurationException
builder
- the StreamBuilder
BeanIOConfigurationException
- if the stream builder is not validpublic void loadResource(String resource) throws BeanIOException, BeanIOConfigurationException
resource
- the configuration resource nameBeanIOException
- if an IOException
or other fatal error is caught while loading the fileBeanIOConfigurationException
- if the mapping file is not found or invalidpublic void loadResource(String resource, Properties properties) throws BeanIOException, BeanIOConfigurationException
resource
- the configuration resource nameproperties
- user Properties
for property substitutionBeanIOException
- if an IOException
or other fatal error is caught while loading the fileBeanIOConfigurationException
- if the mapping file is not found or invalidpublic void load(String filename) throws BeanIOException, BeanIOConfigurationException
filename
- the name of the BeanIO configuration file to loadBeanIOException
- if an IOException
or other fatal error is caught while loading the fileBeanIOConfigurationException
- if the mapping file is invalidpublic void load(String filename, Properties properties) throws BeanIOException, BeanIOConfigurationException
filename
- the name of the BeanIO configuration file to loadproperties
- user Properties
for property substitutionBeanIOException
- if an IOException
or other fatal error is caught while loading the fileBeanIOConfigurationException
- if the mapping file is invalidpublic void load(File file) throws BeanIOException, BeanIOConfigurationException
file
- the BeanIO configuration file to loadBeanIOException
- if an IOException
or other fatal error is caught while loading the fileBeanIOConfigurationException
- if the mapping file is invalidpublic void load(File file, Properties properties) throws BeanIOException, BeanIOConfigurationException
file
- the BeanIO configuration file to loadproperties
- user Properties
for property substitutionBeanIOException
- if an IOException
or other fatal error is caught while loading the fileBeanIOConfigurationException
- if the mapping file is invalidpublic void load(InputStream in) throws IOException, BeanIOConfigurationException
in
- the input stream to read the mapping file fromBeanIOException
- if an IOException
or other fatal error is caught while reading the input streamBeanIOConfigurationException
- if the mapping file is invalidIOException
public abstract void load(InputStream in, Properties properties) throws IOException, BeanIOConfigurationException
in
- the input stream to read the mapping file fromproperties
- user Properties
for property substitutionBeanIOException
- if an IOException
or other fatal error is caught while reading the input streamBeanIOConfigurationException
- if the mapping file is invalidIOException
public static StreamFactory newInstance() throws BeanIOException
BeanIOException
- if a StreamFactory could not be createdSettings
public static StreamFactory newInstance(ClassLoader classLoader) throws BeanIOException
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.BeanIOException
- if a StreamFactory could not be createdSettings
public abstract boolean isMapped(String streamName)
streamName
- the stream name to test for existenceprotected void init()
protected ClassLoader getClassLoader()
ClassLoader
to useprotected void setClassLoader(ClassLoader cl)
cl
- the ClassLoader
to use