commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (JIRA)" <j...@apache.org>
Subject [jira] Created: (CONFIGURATION-312) WindowsConfiguration
Date Thu, 21 Feb 2008 22:56:19 GMT
WindowsConfiguration
--------------------

                 Key: CONFIGURATION-312
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-312
             Project: Commons Configuration
          Issue Type: New Feature
            Reporter: Emmanuel Bourg
             Fix For: 2.x


This is a RFE to implement a configuration backed by the windows registry.

It can be implemented using an external library such as the ICE JNI Registry :
http://www.trustice.com/java/jnireg

It could also be implemented by hacking around the private WindowsPreferences class from the
JDK (with no guarantee it will work on later versions, on other VMs, or on environments with
a SecurityManager). Here is an example using this approach and displaying the user's data
directory :

{code:java}
Preferences winPrefs = Preferences.userRoot();
Class cls = winPrefs.getClass();

Method openKey = cls.getDeclaredMethod("openKey", byte[].class, int.class, int.class);
openKey.setAccessible(true);
Method closeKey = cls.getDeclaredMethod("closeKey", int.class);
closeKey.setAccessible(true);
Method winRegQueryValue = cls.getDeclaredMethod("WindowsRegQueryValueEx", int.class, byte[].class);
winRegQueryValue.setAccessible(true);
Method winRegEnumValue = cls.getDeclaredMethod("WindowsRegEnumValue1", int.class, int.class,
int.class);
winRegEnumValue.setAccessible(true);
Method winRegQueryInfo = cls.getDeclaredMethod("WindowsRegQueryInfoKey1", int.class);
winRegQueryInfo.setAccessible(true);

Integer keyHandle = (Integer) openKey.invoke(winPrefs, toByteArray("Volatile Environment"),
KEY_READ, KEY_READ);

byte[] array = (byte[]) winRegQueryValue.invoke(winPrefs, keyHandle, toByteArray("APPDATA"));
closeKey.invoke(winPrefs, keyHandle);

System.out.println(new String(array));
{code}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message