bibliothek.extension.gui.dock.preference
Class PreferenceStorage

java.lang.Object
  extended by bibliothek.extension.gui.dock.preference.PreferenceStorage

public class PreferenceStorage
extends Object

A preference storage can store the contents of one or of many PreferenceModels. It uses the unique Paths that each preference must have. In order to read or write preferences some PreferenceFactorys are used.

Author:
Benjamin Sigg

Constructor Summary
PreferenceStorage()
          Creates a new preference storage with some default factories set.
 
Method Summary
 void addFactory(Path type, PreferenceFactory<?> factory)
          Adds a new factory to this storage, the factory will be responsible to write or read some kind of preferences.
 void clear()
          Removes all preferences from this storage
 void load(PreferenceModel model, boolean missingToNull)
          Gets through all the preferences of model and changes their values according to the values stored in this storage.
 void read(DataInputStream in)
          Reads the contents of this storage from a stream.
 void readXML(XElement element)
          Reads the contents of this storage from element.
 void store(PreferenceModel model)
          Stores all the preferences of model in this storage.
 void write(DataOutputStream out)
          Writes all values currently stored in this storage to out.
 void writeXML(XElement element)
          Writes the contents of this storage into element, adds new elements to element but does not change the attributes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PreferenceStorage

public PreferenceStorage()
Creates a new preference storage with some default factories set.

Method Detail

addFactory

public void addFactory(Path type,
                       PreferenceFactory<?> factory)
Adds a new factory to this storage, the factory will be responsible to write or read some kind of preferences. If there is already a factory for type, then the old factory will be replaced by factory

Parameters:
type - the type of values factory handles, this path is most times just the name of some class. Node: there is a set of standard paths defined in Path
factory - the new factory

store

public void store(PreferenceModel model)
Stores all the preferences of model in this storage. This storage uses the paths of the preferences to store each value individually. If there is already a value for some path, then that value gets replaced.

Parameters:
model - the model to read out

load

public void load(PreferenceModel model,
                 boolean missingToNull)
Gets through all the preferences of model and changes their values according to the values stored in this storage.

Parameters:
missingToNull - whether missing values should be set to null. If not set, then missing values remain just unchanged.
model - the model to write into

write

public void write(DataOutputStream out)
           throws IOException
Writes all values currently stored in this storage to out.

Parameters:
out - the stream to write into
Throws:
IOException - if the stream is not writable or if there is a factory missing for some type

read

public void read(DataInputStream in)
          throws IOException
Reads the contents of this storage from a stream. Note that this method does not clear the storage, if there are values in this storage that are not in the stream, then these values remain.

Parameters:
in - the stream to read from
Throws:
IOException - if in can't be read

writeXML

public void writeXML(XElement element)
Writes the contents of this storage into element, adds new elements to element but does not change the attributes. If a factory for some element is missing, then this element will not be stored.

Parameters:
element - the element to write into

readXML

public void readXML(XElement element)
Reads the contents of this storage from element. Note that this method does not clear the storage, if there are values in this storage that are not in element, then these values remain. If there is a PreferenceFactory missing for some type, then this value will silently be left out.

Parameters:
element - the element to read from
Throws:
XException - if element is malformed

clear

public void clear()
Removes all preferences from this storage