1 /* GConfNativePeer.java -- GConf based preference peer for native methods
2 Copyright (C) 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu
.java
.util
.prefs
.gconf
;
41 import java
.util
.List
;
42 import java
.util
.prefs
.BackingStoreException
;
45 * Native peer for GConf based preference backend.
47 * @author Mario Torre <neugens@limasoftware.net>
49 public final class GConfNativePeer
52 * Creates a new instance of GConfNativePeer
54 public GConfNativePeer()
60 * Queries whether the node <code>node</code> exists in theGConf database.
61 * Returns <code>true</code> or <code>false</code>.
63 * @param node the node to check.
65 public boolean nodeExist(String node
)
67 return gconf_dir_exists(node
);
71 * Change the value of key to val. Automatically creates the key if it didn't
72 * exist before (ie it was unset or it only had a default value).
73 * Key names must be valid GConf key names, that is, there can be more
74 * restrictions than for normal Preference Backend.
76 * @param key the key to alter (or add).
77 * @param value the new value for this key.
78 * @return true if the key was updated, false otherwise.
80 public boolean setString(String key
, String value
)
82 return gconf_set_string(key
, value
);
86 * Unsets the value of key; if key is already unset, has no effect. Depending
87 * on the GConf daemon, unsetting a key may have the side effect to remove it
88 * completely form the database.
90 * @param key the key to unset.
91 * @return true on success, false if the key was not updated.
93 public boolean unset(String key
)
95 return gconf_unset(key
);
99 * Gets the value of a configuration key.
101 * @param key the configuration key.
102 * @return the values of this key, null if the key is not valid.
104 public String
getKey(String key
)
106 return gconf_get_string(key
);
110 * Lists the key in the given node. Does not list subnodes. Keys names are the
111 * stripped names (name relative to the current node) of the keys stored in
114 * @param node the node where keys are stored.
115 * @return a java.util.List of keys. If there are no keys in the given node, a
116 * list of size 0 is returned.
118 public List
<String
> getKeys(String node
) throws BackingStoreException
120 return gconf_all_keys(node
);
124 * Lists the subnodes in <code>node</code>. The returned list contains
125 * allocated strings. Each string is the name relative tho the given node.
127 * @param node the node to get subnodes from. If there are no subnodes in the
128 * given node, a list of size 0 is returned.
130 public List
<String
> getChildrenNodes(String node
) throws BackingStoreException
132 return gconf_all_nodes(node
);
136 * Escape the given string so the it is a valid GConf name.
138 public static String
escapeString(String plain
)
140 return gconf_escape_key(plain
);
144 * Unescape a string escaped with {@link #escapeString}.
146 public static String
unescapeString(String escaped
)
148 return gconf_unescape_key(escaped
);
152 * Suggest to the backend GConf daemon to synch with the database.
154 public void suggestSync() throws BackingStoreException
156 gconf_suggest_sync();
159 protected void finalize() throws Throwable
171 /* ***** native methods ***** */
174 * Basicly, these are one to one mappings to GConfClient functions.
175 * GConfClient instances are handled by the native layer, and are hidden from
176 * the main java class.
180 * Initialize the GConf native peer and enable the object cache.
181 * It is meant to be used by the static initializer.
183 native synchronized static final private void init_id_cache();
186 * Initialize the GConf native peer. This is meant to be used by the
189 native synchronized static final private void init_class();
194 native synchronized static final private void finalize_class();
197 * Queries the GConf database to see if the given node exists, returning
198 * true if the node exist, false otherwise.
200 * @param node the node to query for existence.
201 * @return true if the node exist, false otherwise.
204 static final protected boolean gconf_dir_exists(String node
);
207 * Sets the given key/value pair into the GConf database.
208 * The key must be a valid GConf key.
210 * @param key the key to store in the GConf database
211 * @param value the value to associate to the given key.
212 * @return true if the change has effect, false otherwise.
215 static final protected boolean gconf_set_string(String key
, String value
);
218 * Returns the key associated to the given key. Null is returned if the
221 * @param key the key to return the value of.
222 * @return The value associated to the given key, or null.
225 static final protected String
gconf_get_string(String key
);
228 * Usets the given key, removing the key from the database.
230 * @param key the key to remove.
231 * @return true if the operation success, false otherwise.
233 native synchronized static final protected boolean gconf_unset(String key
);
236 * Suggest to the GConf native peer a sync with the database.
239 native synchronized static final protected void gconf_suggest_sync()
240 throws BackingStoreException
;
243 * Returns a list of all nodes under the given node.
245 * @param node the source node.
246 * @return A list of nodes under the given source node.
249 static synchronized final protected List
<String
> gconf_all_nodes(String node
)
250 throws BackingStoreException
;
253 * Returns a list of all keys stored in the given node.
255 * @param node the source node.
256 * @return A list of all keys stored in the given node.
259 static final protected List
<String
> gconf_all_keys(String node
)
260 throws BackingStoreException
;
263 * Escape the input String so that it's a valid element for GConf.
265 * @param plain the String to escape.
266 * @return An escaped String for use with GConf.
269 static final protected String
gconf_escape_key(String plain
);
272 * Converts a string escaped with gconf_escape_key back into its
275 * @param escaped key as returned by gconf_escape_key
276 * @return An unescaped key.
279 static final protected String
gconf_unescape_key(String escaped
);
283 System
.loadLibrary("gconfpeer");