public class TLcyBlobWorkspaceCodec extends ALcyWorkspaceCodec implements ILcdInputStreamFactoryCapable, ILcdOutputStreamFactoryCapable
Extension of ALcyWorkspaceCodec
that only uses a single OutputStream
and
a single InputStream
to store/restore workspaces.
This makes it a good class to use if you want for example save a workspace to a file (see TLcyFileWorkspaceCodec
)
or to a database.
In both those cases, having a single InputStream
or OutputStream
facilitates things.
Where the super class creates all little streams to store/restore the workspace using retrieveInputStream(String)
and retrieveOutputStream(String)
, this implementation merges all those little streams into one big stream.
The single stream is created by the ILcdInputStreamFactory
(for decoding) or the
ILcdOutputStreamFactory
(for encoding).
Those factories can be set using setInputStreamFactory(ILcdInputStreamFactory)
and setOutputStreamFactory(ILcdOutputStreamFactory)
.
Modifier | Constructor and Description |
---|---|
protected |
TLcyBlobWorkspaceCodec(ILcyLucyEnv aLucyEnv,
TLcyWorkspaceManager aWorkspaceManager,
ILcdInputStreamFactory aInputStreamFactory,
ILcdOutputStreamFactory aOutputStreamFactory)
Creates a new
TLcyBlobWorkspaceCodec instance. |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecodeWorkspace(String aSourceName)
Returns true if the given aSourceName can be decoded.
|
boolean |
canDecodeWorkspace(String aSourceName,
List<String> aReasonsSFCT)
Returns true if the given source name can be decoded, false otherwise.
|
boolean |
canEncodeWorkspace(String aDestinationName)
Returns true if the workspace can be encoded to the given
aDestinationName |
void |
decodeWorkspace(String aSourceName)
Decodes the workspace.
|
String[] |
decodeWorkspaceDelegateCodecIDs(String aSourceName)
Decodes the workspace codec delegate UID's used by the given workspace.
|
void |
encodeWorkspace(String aDestinationName)
Encodes the workspace.
|
ILcdInputStreamFactory |
getInputStreamFactory()
Returns the input stream factory that is used.
|
ILcdOutputStreamFactory |
getOutputStreamFactory()
Returns the output stream factory that is used.
|
protected InputStream |
retrieveInputStream(String aUID)
Returns an
InputStream for the given aUID. |
protected OutputStream |
retrieveOutputStream(String aUID)
Returns an
OutputStream for the given aUID. |
void |
setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
Sets the input stream factory to be used.
|
void |
setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
Sets the output stream factory to be used.
|
addPropertyChangeListener, addPropertyChangeListener, canEncodeReference, canEncodeReference, checkApplicationHeader, createApplicationHeader, decodeFromInputStream, decodePath, decodeReference, encodeObject, encodePath, encodeReference, encodeReference, firePropertyChange, flushWorkspaceStorageName, getLogListener, getParentComponent, getStatusListener, getWorkspaceManager, getWorkspaceStorageName, removePropertyChangeListener, removePropertyChangeListener, setLogListener, setParentComponent, setStatusListener
protected TLcyBlobWorkspaceCodec(ILcyLucyEnv aLucyEnv, TLcyWorkspaceManager aWorkspaceManager, ILcdInputStreamFactory aInputStreamFactory, ILcdOutputStreamFactory aOutputStreamFactory)
TLcyBlobWorkspaceCodec
instance.aLucyEnv
- The Lucy back-endaWorkspaceManager
- The workspace manageraInputStreamFactory
- The input stream factoryaOutputStreamFactory
- The output stream factorypublic void setInputStreamFactory(ILcdInputStreamFactory aInputStreamFactory)
ILcdInputStreamFactoryCapable
setInputStreamFactory
in interface ILcdInputStreamFactoryCapable
aInputStreamFactory
- the input stream factory to be used.public ILcdInputStreamFactory getInputStreamFactory()
ILcdInputStreamFactoryCapable
getInputStreamFactory
in interface ILcdInputStreamFactoryCapable
public void setOutputStreamFactory(ILcdOutputStreamFactory aOutputStreamFactory)
ILcdOutputStreamFactoryCapable
setOutputStreamFactory
in interface ILcdOutputStreamFactoryCapable
aOutputStreamFactory
- the output stream factory to be used.public ILcdOutputStreamFactory getOutputStreamFactory()
ILcdOutputStreamFactoryCapable
getOutputStreamFactory
in interface ILcdOutputStreamFactoryCapable
public boolean canDecodeWorkspace(String aSourceName)
ALcyWorkspaceCodec
canDecodeWorkspace
in class ALcyWorkspaceCodec
aSourceName
- The source name to check.public boolean canDecodeWorkspace(String aSourceName, List<String> aReasonsSFCT)
ALcyWorkspaceCodec
Returns true if the given source name can be decoded, false otherwise.
The second argument of the method is a list of strings which can be used to pass
a description to the caller of this method.
For example when a workspace cannot be decoded for a certain reason,
a description of that reason can be added to the list of strings.
canDecodeWorkspace
in class ALcyWorkspaceCodec
aSourceName
- The source name to checkaReasonsSFCT
- A side-effect parameter to which this method may add reasons on why it returned true
or false
true
if the given source name can be decoded, false
otherwisepublic String[] decodeWorkspaceDelegateCodecIDs(String aSourceName) throws IOException
ALcyWorkspaceCodec
decodeWorkspaceDelegateCodecIDs
in class ALcyWorkspaceCodec
aSourceName
- The source name of the workspace. It is up to subclasses of this class to
interpret this string, e.g. as a file name.IOException
- if the workspace file is not compatible with this application, or if a fatal I/O exception occursALcyWorkspaceCodecDelegate.getUID()
public void decodeWorkspace(String aSourceName) throws IOException, TLcyWorkspaceAbortedException
ALcyWorkspaceCodec
TLcyWorkspaceManager.decodeWorkspace(String)
must be used.
Decoding the workspace means all encoded parts will be decoded by the
correct ALcyWorkspaceCodecDelegate
. The UID is used to find the correct
ALcyWorkspaceCodecDelegate
. When such an ALcyWorkspaceCodecDelegate
is decoding its part, it might need to restore an object reference (e.g. to an ILcdGXYLayer).
It can do so using ALcyWorkspaceCodec.decodeReference(String)
.
decodeWorkspace
in class ALcyWorkspaceCodec
aSourceName
- The source name of the workspace. It is up to subclasses of this class to
interpret this string, e.g. as a file name.IOException
- In case of fatal IO failure.TLcyWorkspaceAbortedException
- In case the operation is aborted, e.g. because the user canceled it.public boolean canEncodeWorkspace(String aDestinationName)
aDestinationName
The default implementation assumes that the UI enforces a valid destination name,
and simply returns true
independent of the value of aDestinationName
.
canEncodeWorkspace
in class ALcyWorkspaceCodec
aDestinationName
- The destination name to check.aDestinationName
public void encodeWorkspace(String aDestinationName) throws IOException, TLcyWorkspaceAbortedException
ALcyWorkspaceCodec
TLcyWorkspaceManager.encodeWorkspace(String)
must be used.
Encoding the workspace means all registered ALcyWorkspaceCodecDelegate
s will be asked to encode their part. When a
ALcyWorkspaceCodecDelegate
is encoding its part, it might need to store an object
reference (e.g. a reference to an ILcdGXYLayer). It can do so using ALcyWorkspaceCodec.encodeReference(Object)
.
This method must only be used if ALcyWorkspaceCodec.canEncodeWorkspace(String)
for the same
aDestinationName returns true.encodeWorkspace
in class ALcyWorkspaceCodec
aDestinationName
- The destination name of the workspace. It is up to subclasses to
interpret this string, e.g. as a file name.IOException
- In case of fatal IO failure.TLcyWorkspaceAbortedException
- In case the operation is aborted, e.g. because the user canceled
it.protected OutputStream retrieveOutputStream(String aUID) throws IOException
ALcyWorkspaceCodec
OutputStream
for the given aUID. The returned OutputStream
should be a new instance for every UID, as several streams might be open at the same time, and
data can be written to any of those open streams. This method is used several times during
workspace endoding: the stream for every UID represents one little part of the workspace.
During decoding, retrieveInputStream(aUID)
must return an InputStream
that refers to the same data block as the one written to the corresponding
OutputStream
.
Subclasses can implement this method in various ways: they can store every stream in a separate
file, they can store all streams in one single file, they can store the streams in a database,
...retrieveOutputStream
in class ALcyWorkspaceCodec
aUID
- The identifier to retrieve an OutputStream
for.OutputStream
IOException
- In case of fatal IO failure.ALcyWorkspaceCodec.retrieveInputStream(String)
protected InputStream retrieveInputStream(String aUID) throws IOException
ALcyWorkspaceCodec
InputStream
for the given aUID. The returned InputStream
should be a new instance for every UID, as several streams might be open at the same time, and
data can be read from any of those open streams. It is assumed that every stream can be read
until end of stream. This method is used several times during workspace dedoding: the stream
for every UID represents one little part of the workspace.
This method must return an InputStream
referring to the same data block as the
data that was written to the OutputStream
created by
ALcyWorkspaceCodec.retrieveOutputStream(String)
for the same aUID.
Subclasses can implement this method in various ways: they can retrieve every stream from a
separate file, they can retrieve all streams from one single file, they can retrieve the
streams from a database, ...retrieveInputStream
in class ALcyWorkspaceCodec
aUID
- The identifier to retrieve an OutputStream
for.OutputStream
IOException
- In case of fatal IO failure.ALcyWorkspaceCodec.retrieveInputStream(String)