|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectucar.util.prefs.XMLStore
public class XMLStore
This implements an XML-based backing store for PreferencesExt. XMLStores can be chained together to provide independent collections of "stored defaults", eg store1 -> store2 -> store3. In this case, a call to getXXX( key) first looks in store1, and if not found, then in store2, etc. A call to putXXX(key, value) first checks to see if the (key, value) pair already exists in any of the chained stores; if not, then it is added to store1. Normally, only store1 would be changed and saved.
A chain of stored defaults might look like:
try {
XMLStore store3 = XMLStore.createFromResource("/auxdata/system.xml", null);
XMLStore store2 = XMLStore.createFromFile("/usr/local/metapps/GDV/site.xml", store3);
XMLStore store1 = XMLStore.createFromFile("/home/username/.GDV/user.xml", store2);
PreferencesExt prefs = store1.getPreferences();
} catch (IOException e) {
System.out.println("XMLStore Creation failed "+e);
}
If you plan to call Preferences.userRoot(), you must explicilty set it, eg:
PreferencesExt.setUserRoot( prefs);
Before exiting the application, in order to save changes, you must call:
try {
store1.save();
} catch (IOException e) {
System.out.println("XMLStore Save failed "+e);
}
PreferencesExt,
Preferences| Constructor Summary | |
|---|---|
XMLStore()
|
|
| Method Summary | |
|---|---|
static XMLStore |
createFromFile(String fileName,
XMLStore storedDefaults)
Create an XMLStore reading from the specified filename. |
static XMLStore |
createFromInputStream(InputStream is1,
InputStream is2,
XMLStore storedDefaults)
Create an XMLStore reading from an input stream. |
static XMLStore |
createFromResource(String resourceName,
XMLStore storedDefaults)
Create a read-only XMLStore reading from the specified resource, opened as a Resource stream using the XMLStore ClassLoader. |
PreferencesExt |
getPreferences()
Get the root Preferences node. |
static String |
makeStandardFilename(String appName,
String storeName)
Convenience routine for creating an XMLStore file in a standard place. |
void |
save()
Save the current state of the Preferences tree to disk, using the original filename. |
void |
save(OutputStream out)
Save the current state of the Preferences tree to the given OutputStream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public XMLStore()
| Method Detail |
|---|
public static XMLStore createFromFile(String fileName,
XMLStore storedDefaults)
throws IOException
fileName - The XMLStore is stored in this files.storedDefaults - This contains the "stored defaults", or null if none.
IOException - on error
public static XMLStore createFromInputStream(InputStream is1,
InputStream is2,
XMLStore storedDefaults)
throws IOException
is1 - the first copy of the input stream.is2 - the second copy of the input stream.storedDefaults - This contains the "stored defaults", or null if none.
IOException - on error
public static XMLStore createFromResource(String resourceName,
XMLStore storedDefaults)
throws IOException
resourceName - The XMLStore is stored in this resource. By convention it has .xml suffix.storedDefaults - This contains the "stored defaults", or null if none.
IOException - if Resource not found or error reading it
public static String makeStandardFilename(String appName,
String storeName)
Initialize:
appName - application namestoreName - store name
public PreferencesExt getPreferences()
public void save()
throws IOException
UnsupportedOperationException: - if XMLStore was created from createFromResource.
IOException - on read error
public void save(OutputStream out)
throws IOException
IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||