
nz.net.ultraq.preferences.xml.XMLPreferencesFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of preferences-xml Show documentation
Show all versions of preferences-xml Show documentation
An implementation of the Java Preferences API (java.util.prefs) to store preferences in an XML file, in a subdirectory of a Java program's working directory.
package nz.net.ultraq.preferences.xml;
import java.util.prefs.Preferences;
import java.util.prefs.PreferencesFactory;
/**
* Implementation of the PreferencesFactory interface of the
* Preferences API, creates and returns an XML file-based preferences
* implementation for use with the Preferences API.
*
* @author Emanuel Rabina
*/
public class XMLPreferencesFactory implements PreferencesFactory {
private static final String username = System.getProperty("user.name").replace(" ", "").toLowerCase();
private static Preferences SYSTEM_ROOT;
private static Preferences USER_ROOT;
/**
* {@inheritDoc}
*/
@Override
public synchronized Preferences systemRoot() {
if (SYSTEM_ROOT == null) {
SYSTEM_ROOT = new XMLPreferences(username);
}
return SYSTEM_ROOT;
}
/**
* {@inheritDoc}
*/
@Override
public synchronized Preferences userRoot() {
if (USER_ROOT == null) {
USER_ROOT = new XMLPreferences(username);
}
return USER_ROOT;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy