public class XMLStore extends Object
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 and Description |
---|
XMLStore() |
Modifier and Type | Method and Description |
---|---|
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 void |
main(String[] args)
testing
|
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.
|
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 errorpublic 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 errorpublic 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 itpublic static String makeStandardFilename(String appName, String storeName)
Initialize:
appName
- application namestoreName
- store namepublic PreferencesExt getPreferences()
public void save() throws IOException
UnsupportedOperationException:
- if XMLStore was created from createFromResource.IOException
- on read errorpublic void save(OutputStream out) throws IOException
IOException
public static void main(String[] args) throws IOException
IOException
Copyright © 1999–2015 UCAR/Unidata. All rights reserved.