|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfi.helsinki.dacopan.scenario.ScenarioFile
public class ScenarioFile
Implements loading and saving of scenario data, including animation
sequence, settings and protocol events data. Each of the objects that
wishes to save its state to the file should implement Saveable
to provide this class with the data to be saved.
The scenario file is backed by a standard Jar archive.
Reader protocolData = ...; // protocol data from some source ScenarioFile file = new ScenarioFile(new File("myscenario.jar"), protocolData);Note: creating a new scenario file always overwrites any existing one with the same name.
The previous step created a scenario file with nothing but the protocol
events data. To save other data (e.g. settings), you must provide the
ScenarioFile instance with a collection of saveables
.
For example:
// two example classes that implement Saveable class MyClass implementsNote: theSaveable
{ private String data; // the data that will be saved public Object getData() { return data } public void setData(Object o) { this.data = (String)data; } } class MyOtherClass implementsSaveable
{ private Integer data; public Object getData() { return data } public void setData(Object o) { this.data = (String)data; } } // instances of these classes MyClass myObject = new MyClass("abc"); MyOtherClass myOtherObject = new MyOtherClass(new Integer(123)); // save them to the scenario file Collection toBeSaved = new LinkedList(); toBeSaved.add(myObject); toBeSaved.add(myOtherObject); file.save(toBeSaved);
save(Collection)
-method doesn't save the Saveable
objects themselves, but the values returned from their Saveable.getData()
-methods.
To load a scenario file, use the single-parameter constructor
that accepts a file. The constructor will throw an exception if the given file
is not a valid scenario file.
// fails with InvalidScenarioFileException
if existing is not a valid scenario file
ScenarioFile file = new ScenarioFile(existing);
To load the values saved before, you have to provide the ScenarioFile with a collection of Saveables whose values are to be loaded back along with a DataView that is to be populated with the saved protocol data. For example:
DataView emptyDataView = ...; Collection toBePopulated = new LinkedList(); toBePopulated.add(myObject); toBePopulated.add(myOtherObject); file.load(toBePopulated, emptyDataView);The
load(Collection)
-method calls the Saveable.setData(Object)
-method of each Saveable passed to it with the saved value as a parameter.
Constructor Summary | |
---|---|
ScenarioFile(java.io.File file)
Loads an existing scenario file. |
|
ScenarioFile(java.io.File file,
java.util.Collection saveables)
Saves a global settings file |
|
ScenarioFile(java.io.File file,
java.io.Reader protocolDataReader)
Creates (or overwrites existing) an empty scenario file with given protocol data. |
Method Summary | |
---|---|
java.io.File |
getArchiveFile()
Returns the actual file that contains the scenario data. |
void |
load(java.util.Collection saveables)
Populates the given collection of Saveable objects from
this scenario file. |
void |
load(java.util.Collection saveables,
DataView view,
ProgressIndicator indicator)
Populates the given collection of Saveables and the DataView from |
void |
populateView(DataView view)
Populates the given DataView with the protocol data
using XMLProtocolEventsReader . |
void |
populateView(DataView view,
ProgressIndicator indicator)
|
void |
save(java.util.Collection saveables)
Retrieves data from the given collection of Saveable objects and
saves them to this scenario file. |
protected void |
saveFile(java.io.Reader protocolDataReader,
java.util.Collection saveables)
Saves the scenario file with the protocol events data and a collection of saveables . |
void |
setObjectSerializer(ObjectSerializer serializer)
Sets the object serializer to be used when saving objects. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ScenarioFile(java.io.File file, java.io.Reader protocolDataReader) throws java.io.IOException
file
- in which to store the scenario dataprotocolDataReader
- reader that provides the protocol data of the scenario
java.io.IOException
- if creating the file failspublic ScenarioFile(java.io.File file) throws java.io.IOException, java.io.FileNotFoundException, InvalidScenarioFileException
file
- the archive file, must exist
java.io.IOException
- if loading the file fails
java.io.FileNotFoundException
- if the scenario file doesn't exist
InvalidScenarioFileException
- if the file is not a valid scenario filepublic ScenarioFile(java.io.File file, java.util.Collection saveables) throws java.io.IOException, InvalidScenarioFileException
file
- The settings filesaveables
- Collection of settings objects
java.io.IOException
- if saving fails due to I/O problems
InvalidScenarioFileException
- if the file is not a valid scenariofileMethod Detail |
---|
public void save(java.util.Collection saveables) throws java.io.IOException
Saveable
objects and
saves them to this scenario file. Any existing data is overridden.
saveables
- collection of Saveable objects
java.io.IOException
- if saving fails due to I/O problemspublic void load(java.util.Collection saveables) throws java.io.IOException
Saveable
objects from
this scenario file.
java.io.IOException
- if loading failspublic void load(java.util.Collection saveables, DataView view, ProgressIndicator indicator) throws java.io.IOException
java.io.IOException
- if loading failspublic void populateView(DataView view) throws java.io.IOException
DataView
with the protocol data
using XMLProtocolEventsReader
.
view
- to be populated
java.io.IOException
- if reading failspublic void populateView(DataView view, ProgressIndicator indicator) throws java.io.IOException
java.io.IOException
populateView(DataView)
public java.io.File getArchiveFile()
public void setObjectSerializer(ObjectSerializer serializer)
XStreamObjectSerializer
.
protected void saveFile(java.io.Reader protocolDataReader, java.util.Collection saveables) throws java.io.IOException
saveables
.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |