summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario Torre <neugens@limasoftware.net>2006-07-08 22:28:16 +0000
committerMario Torre <neugens@limasoftware.net>2006-07-08 22:28:16 +0000
commit64292d87e369943782d1d4990a88bff5b3d40f02 (patch)
tree00d76a7af558d3e3f0bbc1a3d2086afdcf2772b6
parent73a7fb1e52208fddcacea93e5e34f0d22d9fb2c9 (diff)
downloadclasspath-64292d87e369943782d1d4990a88bff5b3d40f02.tar.gz
2006-07-09 Mario Torre <neugens@limasoftware.net>
* native/jni/gconf-peer/GConfNativePeer.c: Fixed indentation to be more compliant to the GNU coding guidelines. (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset): Added explicit test for errors in the GConf backend. (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string): Added explicit test for errors in the GConf backend. Fixed Segmentation Fault when non valid key names are given as input. (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string): likewise. (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists): Added explicit test for errors in the GConf backend. * gnu/java/util/prefs/gconf/GConfNativePeer.java: Added javadoc comments for all native methods. (nodeExist): removed test to check for valid absolute path name for nodes. (startWatchingNode): likewise. (stopWatchingNode): likewise. (setString): likewise, plus fixed javadoc comments. (unset): likekwise. (getKey): likewise. (getKeys): likewise, also fixed javadoc comments. (getChildrenNodes): likewise. * gnu/java/util/prefs/GConfBasedPreferences.java: changed DEFAULT_USER_ROOT to /apps/classpath. (constructor): Test to check for a valid absolute path for nodes is now in the contructor for that node, instead of being on each method of the backend. (getGConfKey): removed empty new line.
-rw-r--r--ChangeLog33
-rw-r--r--gnu/java/util/prefs/GConfBasedPreferences.java14
-rw-r--r--gnu/java/util/prefs/gconf/GConfNativePeer.java114
-rw-r--r--native/jni/gconf-peer/GConfNativePeer.c623
4 files changed, 454 insertions, 330 deletions
diff --git a/ChangeLog b/ChangeLog
index 69ec0ae14..3a5edf3bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2006-07-09 Mario Torre <neugens@limasoftware.net>
+
+ * native/jni/gconf-peer/GConfNativePeer.c:
+ Fixed indentation to be more compliant to the GNU coding
+ guidelines.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset):
+ Added explicit test for errors in the GConf backend.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string):
+ Added explicit test for errors in the GConf backend.
+ Fixed Segmentation Fault when non valid key names are
+ given as input.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string):
+ likewise.
+ (Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists):
+ Added explicit test for errors in the GConf backend.
+ * gnu/java/util/prefs/gconf/GConfNativePeer.java:
+ Added javadoc comments for all native methods.
+ (nodeExist): removed test to check for valid absolute path name
+ for nodes.
+ (startWatchingNode): likewise.
+ (stopWatchingNode): likewise.
+ (setString): likewise, plus fixed javadoc comments.
+ (unset): likekwise.
+ (getKey): likewise.
+ (getKeys): likewise, also fixed javadoc comments.
+ (getChildrenNodes): likewise.
+ * gnu/java/util/prefs/GConfBasedPreferences.java:
+ changed DEFAULT_USER_ROOT to /apps/classpath.
+ (constructor): Test to check for a valid absolute path for nodes
+ is now in the contructor for that node, instead of being on
+ each method of the backend.
+ (getGConfKey): removed empty new line.
+
2006-07-08 Mark Wielaard <mark@klomp.org>
* .classpath: Add gnu/java/awt/peer/x/ to excludes.
diff --git a/gnu/java/util/prefs/GConfBasedPreferences.java b/gnu/java/util/prefs/GConfBasedPreferences.java
index cbedac5c8..5702751cf 100644
--- a/gnu/java/util/prefs/GConfBasedPreferences.java
+++ b/gnu/java/util/prefs/GConfBasedPreferences.java
@@ -72,6 +72,7 @@ import java.util.prefs.BackingStoreException;
* <br />
*
* @author Mario Torre <neugens@limasoftware.net>
+ * @version 1.0.1
*/
public class GConfBasedPreferences
extends AbstractPreferences
@@ -84,7 +85,7 @@ public class GConfBasedPreferences
private static GConfNativePeer backend = new GConfNativePeer();
/** Default user root path */
- private static final String DEFAULT_USER_ROOT = "/apps/java";
+ private static final String DEFAULT_USER_ROOT = "/apps/classpath";
/** Default system root path */
private static final String DEFAULT_SYSTEM_ROOT = "/system";
@@ -129,7 +130,13 @@ public class GConfBasedPreferences
this.isUser = isUser;
// stores the fully qualified name of this node
- this.node = this.getRealRoot(isUser) + this.absolutePath();
+ String absolutePath = this.absolutePath();
+ if (absolutePath != null && absolutePath.endsWith("/"))
+ {
+ absolutePath = absolutePath.substring(0, absolutePath.length() - 1);
+ }
+
+ this.node = this.getRealRoot(isUser) + absolutePath;
boolean nodeExist = backend.nodeExist(this.node);
@@ -356,9 +363,8 @@ public class GConfBasedPreferences
*/
private String getGConfKey(String key)
{
-
String nodeName = "";
-
+
if (this.node.endsWith("/"))
{
nodeName = this.node + key;
diff --git a/gnu/java/util/prefs/gconf/GConfNativePeer.java b/gnu/java/util/prefs/gconf/GConfNativePeer.java
index 8d773f916..f1cb62787 100644
--- a/gnu/java/util/prefs/gconf/GConfNativePeer.java
+++ b/gnu/java/util/prefs/gconf/GConfNativePeer.java
@@ -45,7 +45,7 @@ import java.util.prefs.BackingStoreException;
* Native peer for GConf based preference backend.
*
* @author Mario Torre <neugens@limasoftware.net>
- * @version 1.0
+ * @version 1.0.1
*/
public final class GConfNativePeer
{
@@ -73,10 +73,6 @@ public final class GConfNativePeer
*/
public boolean nodeExist(String node)
{
- if (node.endsWith("/"))
- {
- node = node.substring(0, node.length() - 1);
- }
return gconf_client_dir_exists(node);
}
@@ -89,10 +85,6 @@ public final class GConfNativePeer
*/
public void startWatchingNode(String node)
{
- if (node.endsWith("/"))
- {
- node = node.substring(0, node.length() - 1);
- }
gconf_client_add_dir(node);
}
@@ -105,16 +97,14 @@ public final class GConfNativePeer
*/
public void stopWatchingNode(String node)
{
- if (node.endsWith("/"))
- {
- node = node.substring(0, node.length() - 1);
- }
gconf_client_remove_dir(node);
}
/**
* Change the value of key to val. Automatically creates the key if it didn't
* exist before (ie it was unset or it only had a default value).
+ * Key names must be valid GConf key names, that is, there can be more
+ * restrictions than for normal Preference Backend.
*
* @param key the key to alter (or add).
* @param value the new value for this key.
@@ -122,10 +112,6 @@ public final class GConfNativePeer
*/
public boolean setString(String key, String value)
{
- if (key.endsWith("/"))
- {
- key = key.substring(0, key.length() - 1);
- }
return gconf_client_set_string(key, value);
}
@@ -139,10 +125,6 @@ public final class GConfNativePeer
*/
public boolean unset(String key)
{
- if (key.endsWith("/"))
- {
- key = key.substring(0, key.length() - 1);
- }
return gconf_client_unset(key);
}
@@ -154,16 +136,12 @@ public final class GConfNativePeer
*/
public String getKey(String key)
{
- if (key.endsWith("/"))
- {
- key = key.substring(0, key.length() - 1);
- }
return gconf_client_get_string(key);
}
/**
* Lists the key in the given node. Does not list subnodes. Keys names are the
- * stripped names (name relative to the current node) of the kyes stored in
+ * stripped names (name relative to the current node) of the keys stored in
* this node.
*
* @param node the node where keys are stored.
@@ -172,10 +150,6 @@ public final class GConfNativePeer
*/
public List getKeys(String node) throws BackingStoreException
{
- if (node.endsWith("/"))
- {
- node = node.substring(0, node.length() - 1);
- }
return gconf_client_gconf_client_all_keys(node);
}
@@ -188,10 +162,6 @@ public final class GConfNativePeer
*/
public List getChildrenNodes(String node) throws BackingStoreException
{
- if (node.endsWith("/"))
- {
- node = node.substring(0, node.length() - 1);
- }
return gconf_client_gconf_client_all_nodes(node);
}
@@ -226,33 +196,99 @@ public final class GConfNativePeer
* the main java class.
*/
- /** */
+ /**
+ * Initialize the GConf native peer and enable the object cache.
+ * It is meant to be used by the static initializer.
+ */
native static final private void init_id_cache();
+ /**
+ * Initialize the GConf native peer. This is meant to be used by the
+ * class constructor.
+ */
native static final private void init_class();
+ /**
+ * Class finalizer.
+ */
native static final private void finalize_class();
+ /**
+ * Queries the GConf database to see if the given node exists, returning
+ * true if the node exist, false otherwise.
+ *
+ * @param node the node to query for existence.
+ * @return true if the node exist, false otherwise.
+ */
native static final protected boolean gconf_client_dir_exists(String node);
+ /**
+ * Adds the given node to the list of nodes that GConf watches for
+ * changes.
+ *
+ * @param node the node to watch for changes.
+ */
native static final protected void gconf_client_add_dir(String node);
+ /**
+ * Removes the given node from the list of nodes that GConf watches for
+ * changes.
+ *
+ * @param node the node to remove from from the list of watched nodes.
+ */
native static final protected void gconf_client_remove_dir(String node);
+ /**
+ * Sets the given key/value pair into the GConf database.
+ * The key must be a valid GConf key.
+ *
+ * @param key the key to store in the GConf database
+ * @param value the value to associate to the given key.
+ * @return true if the change has effect, false otherwise.
+ */
native static final protected boolean gconf_client_set_string(String key,
String value);
+ /**
+ * Returns the key associated to the given key. Null is returned if the
+ * key is not valid.
+ *
+ * @param key the key to return the value of.
+ * @return The value associated to the given key, or null.
+ */
native static final protected String gconf_client_get_string(String key);
+ /**
+ * Usets the given key, removing the key from the database.
+ *
+ * @param key the key to remove.
+ * @return true if the operation success, false otherwise.
+ */
native static final protected boolean gconf_client_unset(String key);
+ /**
+ * Suggest to the GConf native peer a sync with the database.
+ *
+ */
native static final protected void gconf_client_suggest_sync();
- native static final protected List gconf_client_gconf_client_all_nodes(
- String node);
+ /**
+ * Returns a list of all nodes under the given node.
+ *
+ * @param node the source node.
+ * @return A list of nodes under the given source node.
+ */
+ native
+ static final protected List gconf_client_gconf_client_all_nodes(String node);
- native static final protected List gconf_client_gconf_client_all_keys(
- String node);
+ /**
+ * Returns a list of all keys stored in the given node.
+ *
+ * @param node the source node.
+ * @return A list of all keys stored in the given node.
+ */
+ native
+ static final protected List gconf_client_gconf_client_all_keys(String node);
static
{
diff --git a/native/jni/gconf-peer/GConfNativePeer.c b/native/jni/gconf-peer/GConfNativePeer.c
index 55989f059..bc8f78067 100644
--- a/native/jni/gconf-peer/GConfNativePeer.c
+++ b/native/jni/gconf-peer/GConfNativePeer.c
@@ -78,24 +78,24 @@ static void init_gconf_client (void);
/**
* Throws a new runtime exception after a failure, with the given message.
*/
-static void throw_exception (JNIEnv *env, const char *msg);
+static void throw_exception (JNIEnv * env, const char *msg);
/**
* Throws the given exception after a failure, with the given message.
*/
static void
-throw_exception_by_name (JNIEnv *env, const char *name, const char *msg);
+throw_exception_by_name (JNIEnv * env, const char *name, const char *msg);
/**
* Return a reference to a java.util.ArrayList class.
*/
-static gboolean set_jlist_class (JNIEnv *env);
+static gboolean set_jlist_class (JNIEnv * env);
/**
* Builds a new reference to a new java.util.ArrayList instace.
* The instance should be freed by the caller after use.
*/
-static jclass get_jlist_reference (JNIEnv *env, jclass jlist_class);
+static jclass get_jlist_reference (JNIEnv * env, jclass jlist_class);
/* ***** END: PRIVATE FUNCTIONS DELCARATION ***** */
@@ -108,16 +108,17 @@ static jclass get_jlist_reference (JNIEnv *env, jclass jlist_class);
*/
JNIEXPORT void
JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class
- (JNIEnv *env, jclass clazz)
+ (JNIEnv *env, jclass clazz)
{
- if (reference_count == 0) {
- Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache
- (env, clazz);
- return;
- }
-
- reference_count++;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class */
+ if (reference_count == 0)
+ {
+ Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache
+ (env, clazz);
+ return;
+ }
+
+ reference_count++;
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -126,27 +127,29 @@ JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1class
*/
JNIEXPORT void
JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache
- (JNIEnv *env, jclass clazz __attribute__ ((unused)))
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)))
{
- reference_count++;
+ reference_count++;
- init_gconf_client ();
-
- /* if client is null, there is probably an out or memory */
- if (client == NULL) {
- /* release the string and throw a runtime exception */
- throw_exception (env,
- "Unable to initialize GConfClient in native code\n");
- return;
- }
-
- /* ***** java.util.ArrayList ***** */
- if (set_jlist_class (env) == FALSE) {
- throw_exception (env,
- "Unable to get valid reference to java.util.List in native code\n");
- return;
- }
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache */
+ init_gconf_client ();
+
+ /* if client is null, there is probably an out of memory */
+ if (client == NULL)
+ {
+ /* release the string and throw a runtime exception */
+ throw_exception (env,
+ "Unable to initialize GConfClient in native code\n");
+ return;
+ }
+
+ /* ***** java.util.ArrayList ***** */
+ if (set_jlist_class (env) == FALSE)
+ {
+ throw_exception (env,
+ "Unable to get valid reference to java.util.List in native code\n");
+ return;
+ }
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -155,58 +158,63 @@ JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_init_1id_1cache
*/
JNIEXPORT jobject JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1keys
- (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
{
- const char *dir = NULL;
- GError *err = NULL;
- GSList *entries = NULL;
- GSList *tmp;
-
- /* java.util.ArrayList */
- jobject jlist = NULL;
-
- dir = JCL_jstring_to_cstring(env, node);
- if (dir == NULL) {
- return NULL;
- }
-
- entries = gconf_client_all_entries (client, dir, &err);
- if (err != NULL) {
- throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
- err->message);
- g_error_free (err);
- err = NULL;
-
- JCL_free_cstring(env, node, dir);
- return NULL;
- }
-
- jlist = get_jlist_reference (env, jlist_class);
- if (jlist == NULL) {
- throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
- "Unable to get java.util.List reference in native code\n");
- JCL_free_cstring(env, node, dir);
- g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
- g_slist_free (entries);
- return NULL;
- }
-
- tmp = entries;
- while (tmp != NULL) {
- const char *_val = gconf_entry_get_key(tmp->data);
- _val = strrchr (_val, '/'); ++_val;
- (*env)->CallBooleanMethod(env, jlist, jlist_add_id,
- (*env)->NewStringUTF(env, _val));
- tmp = g_slist_next (tmp);
- }
-
- /* clean up things */
- JCL_free_cstring(env, node, dir);
- g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
- g_slist_free (entries);
-
- return jlist;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1keys */
+ const char *dir = NULL;
+ GError *err = NULL;
+ GSList *entries = NULL;
+ GSList *tmp;
+
+ /* java.util.ArrayList */
+ jobject jlist = NULL;
+
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
+ {
+ return NULL;
+ }
+
+ entries = gconf_client_all_entries (client, dir, &err);
+ if (err != NULL)
+ {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ err->message);
+ g_error_free (err);
+ err = NULL;
+
+ JCL_free_cstring (env, node, dir);
+ return NULL;
+ }
+
+ jlist = get_jlist_reference (env, jlist_class);
+ if (jlist == NULL)
+ {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ "Unable to get java.util.List reference in native code\n");
+ JCL_free_cstring (env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+ return NULL;
+ }
+
+ tmp = entries;
+ while (tmp != NULL)
+ {
+ const char *_val = gconf_entry_get_key (tmp->data);
+ _val = strrchr (_val, '/');
+ ++_val;
+ (*env)->CallBooleanMethod (env, jlist, jlist_add_id,
+ (*env)->NewStringUTF (env, _val));
+ tmp = g_slist_next (tmp);
+ }
+
+ /* clean up things */
+ JCL_free_cstring (env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+
+ return jlist;
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -215,57 +223,62 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all
*/
JNIEXPORT jobject JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1nodes
- (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
{
- const char *dir = NULL;
- GError *err = NULL;
- GSList *entries = NULL;
- GSList *tmp;
-
- /* java.util.ArrayList */
- jobject jlist = NULL;
-
- dir = JCL_jstring_to_cstring(env, node);
- if (dir == NULL) {
- return NULL;
- }
-
- entries = gconf_client_all_dirs (client, dir, &err);
- if (err != NULL) {
- throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
- err->message);
- g_error_free (err);
- err = NULL;
- JCL_free_cstring(env, node, dir);
- return NULL;
- }
-
- jlist = get_jlist_reference (env, jlist_class);
- if (jlist == NULL) {
- throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
- "Unable to get java.util.List reference in native code\n");
- JCL_free_cstring(env, node, dir);
- g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
- g_slist_free (entries);
- return NULL;
- }
-
- tmp = entries;
- while (tmp != NULL) {
- const char *_val = tmp->data;
- _val = strrchr (_val, '/'); ++_val;
- (*env)->CallBooleanMethod(env, jlist, jlist_add_id,
- (*env)->NewStringUTF(env, _val));
- tmp = g_slist_next (tmp);
- }
-
- /* clean up things */
- JCL_free_cstring(env, node, dir);
- g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
- g_slist_free (entries);
-
- return jlist;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all_1nodes */
+ const char *dir = NULL;
+ GError *err = NULL;
+ GSList *entries = NULL;
+ GSList *tmp;
+
+ /* java.util.ArrayList */
+ jobject jlist = NULL;
+
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
+ {
+ return NULL;
+ }
+
+ entries = gconf_client_all_dirs (client, dir, &err);
+ if (err != NULL)
+ {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ err->message);
+ g_error_free (err);
+ err = NULL;
+ JCL_free_cstring (env, node, dir);
+ return NULL;
+ }
+
+ jlist = get_jlist_reference (env, jlist_class);
+ if (jlist == NULL)
+ {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ "Unable to get java.util.List reference in native code\n");
+ JCL_free_cstring (env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+ return NULL;
+ }
+
+ tmp = entries;
+ while (tmp != NULL)
+ {
+ const char *_val = tmp->data;
+ _val = strrchr (_val, '/');
+ ++_val;
+ (*env)->CallBooleanMethod (env, jlist, jlist_add_id,
+ (*env)->NewStringUTF (env, _val));
+ tmp = g_slist_next (tmp);
+ }
+
+ /* clean up things */
+ JCL_free_cstring (env, node, dir);
+ g_slist_foreach (entries, (GFunc) gconf_entry_free, NULL);
+ g_slist_free (entries);
+
+ return jlist;
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -274,18 +287,19 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1gconf_1client_1all
*/
JNIEXPORT void JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1suggest_1sync
- (JNIEnv *env, jclass clazz __attribute__ ((unused)))
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)))
{
- GError *err = NULL;
-
- gconf_client_suggest_sync (client, &err);
- if (err != NULL) {
- throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
- err->message);
- g_error_free (err);
- err = NULL;
- }
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1suggest_1sync */
+ GError *err = NULL;
+
+ gconf_client_suggest_sync (client, &err);
+ if (err != NULL)
+ {
+ throw_exception_by_name (env, "java/util/prefs/BackingStoreException",
+ err->message);
+ g_error_free (err);
+ err = NULL;
+ }
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -294,22 +308,30 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1suggest_1sync
*/
JNIEXPORT jboolean JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset
- (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key)
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key)
{
- const char *_key = NULL;
- gboolean result = JNI_FALSE;
-
- _key = JCL_jstring_to_cstring(env, key);
- if (_key == NULL) {
- return JNI_FALSE;
- }
-
- result = gconf_client_unset (client, _key, NULL);
-
- JCL_free_cstring(env, key, _key);
+ const char *_key = NULL;
+ gboolean result = JNI_FALSE;
+ GError *err = NULL;
+
+ _key = JCL_jstring_to_cstring (env, key);
+ if (_key == NULL)
+ {
+ return JNI_FALSE;
+ }
+
+ result = gconf_client_unset (client, _key, &err);
+ if (err != NULL)
+ {
+ result = JNI_FALSE;
+ g_error_free (err);
+ err = NULL;
+ }
+
+ JCL_free_cstring (env, key, _key);
- return result;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset */
+ return result;
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -318,25 +340,36 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1unset
*/
JNIEXPORT jstring JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string
- (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key)
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring key)
{
- const char *_key = NULL;
- const char *_value = NULL;
- jstring result = NULL;
-
- _key = JCL_jstring_to_cstring(env, key);
- if (_key == NULL) {
- return NULL;
- }
-
- _value = gconf_client_get_string (client, _key, NULL);
- JCL_free_cstring(env, key, _key);
-
- result = (*env)->NewStringUTF (env, _value);
- g_free ((gpointer) _value);
-
- return result;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string */
+ const char *_key = NULL;
+ const char *_value = NULL;
+ GError *err = NULL;
+ jstring result = NULL;
+
+ _key = JCL_jstring_to_cstring (env, key);
+ if (_key == NULL)
+ {
+ return NULL;
+ }
+
+ _value = gconf_client_get_string (client, _key, &err);
+ JCL_free_cstring (env, key, _key);
+ if (err != NULL)
+ {
+ /* just in case */
+ if (_value != NULL) g_free ((gpointer) _value);
+ g_error_free (err);
+ err = NULL;
+
+ return NULL;
+ }
+
+ result = (*env)->NewStringUTF (env, _value);
+ g_free ((gpointer) _value);
+
+ return result;
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -345,28 +378,36 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1get_1string
*/
JNIEXPORT jboolean JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string
- (JNIEnv *env, jclass clazz __attribute__ ((unused)),
- jstring key, jstring value)
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)),
+ jstring key, jstring value)
{
- const char *_key = NULL;
- const char *_value = NULL;
-
- gboolean result = JNI_FALSE;
-
- /* load an UTF string from the virtual machine. */
- _key = JCL_jstring_to_cstring (env, key);
- _value = JCL_jstring_to_cstring (env, value);
- if (_key == NULL && _value == NULL) {
- return JNI_FALSE;
- }
-
- result = gconf_client_set_string (client, _key, _value, NULL);
-
- JCL_free_cstring (env, key, _key);
- JCL_free_cstring (env, value, _value);
-
- return (jboolean) result;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string */
+ const char *_key = NULL;
+ const char *_value = NULL;
+ GError *err = NULL;
+
+ gboolean result = JNI_FALSE;
+
+ /* load an UTF string from the virtual machine. */
+ _key = JCL_jstring_to_cstring (env, key);
+ _value = JCL_jstring_to_cstring (env, value);
+ if (_key == NULL && _value == NULL)
+ {
+ return JNI_FALSE;
+ }
+
+ result = gconf_client_set_string (client, _key, _value, &err);
+ if (err != NULL)
+ {
+ g_error_free (err);
+ err = NULL;
+ result = JNI_FALSE;
+ }
+
+ JCL_free_cstring (env, key, _key);
+ JCL_free_cstring (env, value, _value);
+
+ return (jboolean) result;
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -375,18 +416,18 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1set_1string
*/
JNIEXPORT void JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1remove_1dir
- (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
{
- const char *dir = NULL;
-
- dir = JCL_jstring_to_cstring (env, node);
- if (dir == NULL)
- return;
-
- gconf_client_remove_dir (client, dir, NULL);
-
- JCL_free_cstring (env, node, dir);
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1remove_1dir */
+ const char *dir = NULL;
+
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
+ return;
+
+ gconf_client_remove_dir (client, dir, NULL);
+
+ JCL_free_cstring (env, node, dir);
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -395,19 +436,19 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1remove_1dir
*/
JNIEXPORT void JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir
- (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
{
- const char *dir = NULL;
+ const char *dir = NULL;
- dir = JCL_jstring_to_cstring (env, node);
- if (dir == NULL)
- return;
-
- /* ignore errors */
- gconf_client_add_dir (client, dir, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
+ return;
- JCL_free_cstring (env, node, dir);
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir */
+ /* ignore errors */
+ gconf_client_add_dir (client, dir, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
+
+ JCL_free_cstring (env, node, dir);
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -416,22 +457,25 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1add_1dir
*/
JNIEXPORT jboolean JNICALL
Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists
- (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
-{
- const char *dir = NULL;
- jboolean value = JNI_FALSE;
-
- dir = JCL_jstring_to_cstring (env, node);
- if (dir == NULL)
- return value;
-
- /* we ignore errors here */
- value = gconf_client_dir_exists (client, dir, NULL);
-
- JCL_free_cstring (env, node, dir);
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)), jstring node)
+{
+ const char *dir = NULL;
+ GError *err = NULL;
+ jboolean value = JNI_FALSE;
+ dir = JCL_jstring_to_cstring (env, node);
+ if (dir == NULL)
return value;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists */
+
+ /* on error return false */
+ value = gconf_client_dir_exists (client, dir, &err);
+ if (err != NULL)
+ value = JNI_FALSE;
+
+ JCL_free_cstring (env, node, dir);
+
+ return value;
+}
/*
* Class: gnu_java_util_prefs_gconf_GConfNativePeer
@@ -440,23 +484,24 @@ Java_gnu_java_util_prefs_gconf_GConfNativePeer_gconf_1client_1dir_1exists
*/
JNIEXPORT void
JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class
- (JNIEnv *env, jclass clazz __attribute__ ((unused)))
+ (JNIEnv *env, jclass clazz __attribute__ ((unused)))
{
- if (reference_count == 0) {
- /* last reference, free all resources and return */
- g_object_unref (G_OBJECT (client));
-
- (*env)->DeleteGlobalRef (env, jlist_class);
-
- jlist_class = NULL;
- jlist_init_id = NULL;
- jlist_add_id = NULL;
-
- return;
- }
-
- reference_count--;
-} /* Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class */
+ if (reference_count == 0)
+ {
+ /* last reference, free all resources and return */
+ g_object_unref (G_OBJECT (client));
+
+ (*env)->DeleteGlobalRef (env, jlist_class);
+
+ jlist_class = NULL;
+ jlist_init_id = NULL;
+ jlist_add_id = NULL;
+
+ return;
+ }
+
+ reference_count--;
+}
/* ***** END: NATIVE FUNCTIONS ***** */
@@ -464,55 +509,59 @@ JNICALL Java_gnu_java_util_prefs_gconf_GConfNativePeer_finalize_1class
static void throw_exception (JNIEnv *env, const char *msg)
{
- throw_exception_by_name (env, "java/lang/RuntimeException", msg);
-} /* throw_exception */
+ throw_exception_by_name (env, "java/lang/RuntimeException", msg);
+}
static void
throw_exception_by_name (JNIEnv *env, const char *name, const char *msg)
-{
- JCL_ThrowException(env, name, msg);
-} /* throw_exception */
+{
+ JCL_ThrowException (env, name, msg);
+}
static void init_gconf_client (void)
-{
- client = gconf_client_get_default ();
- g_type_init();
-} /* init_gconf_client */
+{
+ client = gconf_client_get_default ();
+ g_type_init ();
+}
static gboolean set_jlist_class (JNIEnv *env)
{
- jclass local_jlist_class = NULL;
-
- /* gets a reference to the ArrayList class */
- local_jlist_class = JCL_FindClass (env, "java/util/ArrayList");
- if (local_jlist_class == NULL) {
- return FALSE;
- }
-
- jlist_class = (*env)->NewGlobalRef(env, local_jlist_class);
- (*env)->DeleteLocalRef(env, local_jlist_class);
- if (jlist_class == NULL) {
- return FALSE;
- }
-
- /* and initialize it */
- jlist_init_id = (*env)->GetMethodID (env, jlist_class, "<init>", "()V");
- if (jlist_init_id == NULL) {
- return FALSE;
- }
-
- jlist_add_id = (*env)->GetMethodID (env, jlist_class, "add",
- "(Ljava/lang/Object;)Z");
- if (jlist_add_id == NULL) {
- return FALSE;
- }
-
- return TRUE;
-} /* set_jlist_class */
+ jclass local_jlist_class = NULL;
+
+ /* gets a reference to the ArrayList class */
+ local_jlist_class = JCL_FindClass (env, "java/util/ArrayList");
+ if (local_jlist_class == NULL)
+ {
+ return FALSE;
+ }
+
+ jlist_class = (*env)->NewGlobalRef (env, local_jlist_class);
+ (*env)->DeleteLocalRef (env, local_jlist_class);
+ if (jlist_class == NULL)
+ {
+ return FALSE;
+ }
+
+ /* and initialize it */
+ jlist_init_id = (*env)->GetMethodID (env, jlist_class, "<init>", "()V");
+ if (jlist_init_id == NULL)
+ {
+ return FALSE;
+ }
+
+ jlist_add_id = (*env)->GetMethodID (env, jlist_class, "add",
+ "(Ljava/lang/Object;)Z");
+ if (jlist_add_id == NULL)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
static jobject get_jlist_reference (JNIEnv *env, jclass jlist_class)
{
- return (*env)->NewObject(env, jlist_class, jlist_init_id);
-} /* get_jlist_reference */
+ return (*env)->NewObject (env, jlist_class, jlist_init_id);
+}
/* ***** END: PRIVATE FUNCTIONS IMPLEMENTATION ***** */