gnu.java.util.prefs

Class GConfBasedPreferences


public class GConfBasedPreferences
extends AbstractPreferences

This is a GConf based preference implementation which writes the preferences as GConf key-value pairs. System Root is defined to be the "/system" directory of GConf for the current user, while User Root is "/apps/java". These defaults can be modified by defining two system properties:

User Root:

 gnu.java.util.prefs.gconf.user_root
 


and System Root:

 gnu.java.util.prefs.gconf.system_root
 

Field Summary

Fields inherited from class java.util.prefs.AbstractPreferences

lock, newNode

Fields inherited from class java.util.prefs.Preferences

MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH

Constructor Summary

GConfBasedPreferences()
Creates a preference root user node.
GConfBasedPreferences(boolean isUser)
Creates a preference root node.
GConfBasedPreferences(AbstractPreferences parent, String name, boolean isUser)
Creates a new preference node given a parent node and a name, which has to be relative to its parent.

Method Summary

protected AbstractPreferences
childSpi(String name)
Returns a child node with the given name.
protected String[]
childrenNamesSpi()
Returns an array of names of the children of this preference node.
void
flush()
Suggest a flush to the backend.
protected void
flushSpi()
Request a flush.
protected String
getSpi(String key)
Returns the value of the given key.
boolean
isUserNode()
Returns true if this preference node is a user node, false if is a system preference node.
protected String[]
keysSpi()
Returns all of the key in this preference node.
protected void
putSpi(String key, String value)
Stores the given key-value pair into this preference node.
protected void
removeNodeSpi()
Removes this preference node, including all its children.
protected void
removeSpi(String key)
Removes the given key from this preference node.
void
sync()
Suggest a sync to the backend.
protected void
syncSpi()
Request a sync.

Methods inherited from class java.util.prefs.AbstractPreferences

absolutePath, addNodeChangeListener, addPreferenceChangeListener, cachedChildren, childSpi, childrenNames, childrenNamesSpi, clear, exportNode, exportSubtree, flush, flushSpi, get, getBoolean, getByteArray, getChild, getDouble, getFloat, getInt, getLong, getSpi, isRemoved, isUserNode, keys, keysSpi, name, node, nodeExists, parent, put, putBoolean, putByteArray, putDouble, putFloat, putInt, putLong, putSpi, remove, removeNode, removeNodeChangeListener, removeNodeSpi, removePreferenceChangeListener, removeSpi, sync, syncSpi, toString

Methods inherited from class java.util.prefs.Preferences

absolutePath, addNodeChangeListener, addPreferenceChangeListener, childrenNames, clear, exportNode, exportSubtree, flush, get, getBoolean, getByteArray, getDouble, getFloat, getInt, getLong, importPreferences, isUserNode, keys, name, node, nodeExists, parent, put, putBoolean, putByteArray, putDouble, putFloat, putInt, putLong, remove, removeNode, removeNodeChangeListener, removePreferenceChangeListener, sync, systemNodeForPackage, systemRoot, toString, userNodeForPackage, userRoot

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

GConfBasedPreferences

public GConfBasedPreferences()
Creates a preference root user node.

GConfBasedPreferences

public GConfBasedPreferences(boolean isUser)
Creates a preference root node. When isUser is true it will be user node otherwise it will be a system node.

GConfBasedPreferences

public GConfBasedPreferences(AbstractPreferences parent,
                             String name,
                             boolean isUser)
Creates a new preference node given a parent node and a name, which has to be relative to its parent. When isUser is true it will be user node otherwise it will be a system node.
Parameters:
parent - The parent node of this newly created node.
name - A name relative to the parent node.
isUser - Set to true initializes this node to be a user node, false initialize it to be a system node.

Method Details

childSpi

protected AbstractPreferences childSpi(String name)
Returns a child node with the given name. If the child node does not exists, it will be created.
Overrides:
childSpi in interface AbstractPreferences
Parameters:
name - The name of the requested node.
Returns:
A new reference to the node, creating the node if it is necessary.

childrenNamesSpi

protected String[] childrenNamesSpi()
            throws BackingStoreException
Returns an array of names of the children of this preference node. If the current node does not have children, the returned array will be of size 0 (that is, not null).
Overrides:
childrenNamesSpi in interface AbstractPreferences
Returns:
A String array of names of children of the current node.
Throws:
BackingStoreException - if this operation cannot be completed.

flush

public void flush()
            throws BackingStoreException
Suggest a flush to the backend. Actually, this is only a suggestion as GConf handles this for us asynchronously. More over, both sync and flush have the same meaning in this class, so calling sync has exactly the same effect.
Overrides:
flush in interface AbstractPreferences
Throws:
BackingStoreException - if this operation cannot be completed.
See Also:
sync()

flushSpi

protected void flushSpi()
            throws BackingStoreException
Request a flush.
Overrides:
flushSpi in interface AbstractPreferences
Throws:
BackingStoreException - if this operation cannot be completed.
See Also:
flush()

getSpi

protected String getSpi(String key)
Returns the value of the given key. If the keys does not have a value, or there is an error in the backing store, null is returned instead.
Overrides:
getSpi in interface AbstractPreferences
Parameters:
key - The key to retrieve.
Returns:
The value associated with the given key.

isUserNode

public boolean isUserNode()
Returns true if this preference node is a user node, false if is a system preference node.
Overrides:
isUserNode in interface AbstractPreferences
Returns:
true if this preference node is a user node, false if is a system preference node.

keysSpi

protected String[] keysSpi()
            throws BackingStoreException
Returns all of the key in this preference node. If the current node does not have preferences, the returned array will be of size zero.
Overrides:
keysSpi in interface AbstractPreferences
Returns:
A String array of keys stored under the current node.
Throws:
BackingStoreException - if this operation cannot be completed.

putSpi

protected void putSpi(String key,
                      String value)
Stores the given key-value pair into this preference node.
Overrides:
putSpi in interface AbstractPreferences
Parameters:
key - The key of this preference.
value - The value of this preference.

removeNodeSpi

protected void removeNodeSpi()
            throws BackingStoreException
Removes this preference node, including all its children. Also removes the preferences associated.
Overrides:
removeNodeSpi in interface AbstractPreferences

removeSpi

protected void removeSpi(String key)
Removes the given key from this preference node. If the key does not exist, no operation is performed.
Overrides:
removeSpi in interface AbstractPreferences
Parameters:
key - The key to remove.

sync

public void sync()
            throws BackingStoreException
Suggest a sync to the backend. Actually, this is only a suggestion as GConf handles this for us asynchronously. More over, both sync and flush have the same meaning in this class, so calling flush has exactly the same effect.
Overrides:
sync in interface AbstractPreferences
Throws:
BackingStoreException - if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
See Also:
flush()

syncSpi

protected void syncSpi()
            throws BackingStoreException
Request a sync.
Overrides:
syncSpi in interface AbstractPreferences
Throws:
BackingStoreException - if this operation cannot be completed due to a failure in the backing store, or inability to communicate with it.
See Also:
sync()

GConfBasedPreferences.java -- GConf based Preferences implementation Copyright (C) 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.