You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/30 10:26:50 UTC
svn commit: r1098055 - in /commons/sandbox/runtime/trunk/src/main:
java/org/apache/commons/runtime/platform/windows/ native/os/win32/
test/org/apache/commons/runtime/
Author: mturk
Date: Sat Apr 30 08:26:50 2011
New Revision: 1098055
URL: http://svn.apache.org/viewvc?rev=1098055&view=rev
Log:
Registry methods and test suite
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java
commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestRegistry.java
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java?rev=1098055&r1=1098054&r2=1098055&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryKey.java Sat Apr 30 08:26:50 2011
@@ -206,6 +206,9 @@ public class RegistryKey implements Clos
private static native int info0(long key, String name);
private static native String gets0(long key, String name);
private static native char[] gets1(long key, String name);
+ private static native byte[] gets2(long key, String name);
+ private static native int gets3(long key, String name, int[] pval);
+ private static native int gets4(long key, String name, long[] pval);
public RegistryKey open(String name, EnumSet<RegistryKeyAccessRights> mode)
throws NullPointerException, IOException, SystemException
@@ -301,4 +304,46 @@ public class RegistryKey implements Clos
return Utils.charBlockToStringArray(rv);
}
+ public byte[] getByteArray(String valueName)
+ throws NullPointerException, IOException
+ {
+ if (valueName == null)
+ throw new NullPointerException();
+ if (hKey == 0L || hKey == -1L)
+ throw new InvalidHandleException();
+
+ byte[] rv = gets2(hKey, valueName);
+ if (rv == null)
+ throw new IOException(Errno.msg());
+ return rv;
+ }
+
+ public int getIntegerValue(String valueName)
+ throws NullPointerException, IOException
+ {
+ if (valueName == null)
+ throw new NullPointerException();
+ if (hKey == 0L || hKey == -1L)
+ throw new InvalidHandleException();
+ int[] rp = new int[1];
+ int rc = gets3(hKey, valueName, rp);
+ if (rc != 0)
+ throw new IOException(Status.describe(rc));
+ return rp[0];
+ }
+
+ public long getLongValue(String valueName)
+ throws NullPointerException, IOException
+ {
+ if (valueName == null)
+ throw new NullPointerException();
+ if (hKey == 0L || hKey == -1L)
+ throw new InvalidHandleException();
+ long[] rp = new long[1];
+ int rc = gets4(hKey, valueName, rp);
+ if (rc != 0)
+ throw new IOException(Status.describe(rc));
+ return rp[0];
+ }
+
}
Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java?rev=1098055&r1=1098054&r2=1098055&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/RegistryValueType.java Sat Apr 30 08:26:50 2011
@@ -34,43 +34,38 @@ public enum RegistryValueType
/**
* Unknown or unsupported Registry value type.
*/
- UNKNOWN( 0x00000000),
-
- /**
- * Unknown or unsupported Registry value type.
- */
- NONE( 0x00000001),
+ NONE( 0),
/**
* Binary data in any form.
*/
- BINARY( 0x00000008),
+ BINARY( 3),
/**
* A 32-bit number.
*/
- DWORD( 0x00000010),
+ DWORD( 4),
/**
* Null-terminated string that contains unexpanded references to
* environment variables (for example, {@code %PATH%"}).
*/
- EXPAND_SZ( 0x00000004),
+ EXPAND_SZ( 2),
/**
* Array of null-terminated strings, terminated by two null characters.
*/
- MULTI_SZ( 0x00000020),
+ MULTI_SZ( 7),
/**
* A 64-bit number.
*/
- QWORD( 0x00000040),
+ QWORD( 11),
/**
* Null-terminated string
*/
- SZ( 0x00000002);
+ SZ( 1);
private int value;
private RegistryValueType(int v)
@@ -89,7 +84,7 @@ public enum RegistryValueType
if (e.value == value)
return e;
}
- return UNKNOWN;
+ return NONE;
}
}
Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c?rev=1098055&r1=1098054&r2=1098055&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/registry.c Sat Apr 30 08:26:50 2011
@@ -238,3 +238,94 @@ ACR_WIN_EXPORT(jcharArray, RegistryKey,
ACR_SAVE_ERROR(rc);
return r;
}
+
+ACR_WIN_EXPORT(jbyteArray, RegistryKey, gets2)(JNI_STDARGS, jlong key, jstring name)
+{
+ jbyteArray r = 0;
+ DWORD rt = 0;
+ DWORD rs = 0;
+ int rc = ACR_EINVAL;
+ HKEY skey = 0;
+ HKEY hkey = J2P(key, HKEY);
+
+ WITH_WSTR(name) {
+ rc = RegQueryValueExW(hkey, J2S(name), 0, &rt, 0, &rs);
+ if (rc == 0) {
+ if (rt == REG_BINARY) {
+ r = (*env)->NewByteArray(env, (jsize)rs);
+ if (rs != 0) {
+ jbyte *ss = ACR_MALLOC(jbyte, rs);
+ if (ss == 0) {
+ rc = ACR_ENOMEM;
+ }
+ else {
+ rc = RegQueryValueExW(hkey, J2S(name), 0, &rt, (LPBYTE)ss, &rs);
+ if (rc == 0) {
+ (*env)->SetByteArrayRegion(env, r, 0, (jsize)rs, ss);
+ }
+ AcrFree(ss);
+ }
+ }
+ }
+ else {
+ rc = ACR_EFTYPE;
+ }
+ }
+ } DONE_WITH_STR(name);
+
+ if (rc != 0)
+ ACR_SAVE_ERROR(rc);
+ return r;
+}
+
+ACR_WIN_EXPORT(jint, RegistryKey, gets3)(JNI_STDARGS, jlong key, jstring name, jintArray pval)
+{
+ DWORD rt = 0;
+ DWORD rs = 0;
+ int rc = ACR_EINVAL;
+ HKEY skey = 0;
+ HKEY hkey = J2P(key, HKEY);
+
+ WITH_WSTR(name) {
+ rc = RegQueryValueExW(hkey, J2S(name), 0, &rt, 0, &rs);
+ if (rc == 0) {
+ if (rt == REG_DWORD && rs == 4) {
+ jint rv;
+ rc = RegQueryValueExW(hkey, J2S(name), 0, &rt, (LPBYTE)&rt, &rs);
+ if (rc == 0) {
+ (*env)->SetIntArrayRegion(env, pval, 0, 1, &rv);
+ }
+ }
+ else {
+ rc = ACR_EFTYPE;
+ }
+ }
+ } DONE_WITH_STR(name);
+ return rc;
+}
+
+ACR_WIN_EXPORT(jint, RegistryKey, gets4)(JNI_STDARGS, jlong key, jstring name, jlongArray pval)
+{
+ DWORD rt = 0;
+ DWORD rs = 0;
+ int rc = ACR_EINVAL;
+ HKEY skey = 0;
+ HKEY hkey = J2P(key, HKEY);
+
+ WITH_WSTR(name) {
+ rc = RegQueryValueExW(hkey, J2S(name), 0, &rt, 0, &rs);
+ if (rc == 0) {
+ if (rt == REG_QWORD && rs == 8) {
+ jlong rv;
+ rc = RegQueryValueExW(hkey, J2S(name), 0, &rt, (LPBYTE)&rt, &rs);
+ if (rc == 0) {
+ (*env)->SetLongArrayRegion(env, pval, 0, 1, &rv);
+ }
+ }
+ else {
+ rc = ACR_EFTYPE;
+ }
+ }
+ } DONE_WITH_STR(name);
+ return rc;
+}
Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestRegistry.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestRegistry.java?rev=1098055&r1=1098054&r2=1098055&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestRegistry.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestRegistry.java Sat Apr 30 08:26:50 2011
@@ -26,7 +26,7 @@ public class TestRegistry extends Assert
@Test(groups = { "windows" })
public void openExiting()
- throws IOException
+ throws Exception
{
RegistryKey key = RegistryKey.LocalMachine.open("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
assertNotNull(key);
@@ -37,7 +37,7 @@ public class TestRegistry extends Assert
@Test(groups = { "windows" })
public void openMsz()
- throws IOException
+ throws Exception
{
RegistryKey key = RegistryKey.LocalMachine.open("SYSTEM\\CurrentControlSet\\Control\\Session Manager");
assertNotNull(key);
@@ -48,4 +48,24 @@ public class TestRegistry extends Assert
}
}
+ @Test(groups = { "windows" })
+ public void getInteger()
+ throws Exception
+ {
+ RegistryKey key = RegistryKey.LocalMachine.open("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
+ assertNotNull(key);
+ int val = key.getIntegerValue("InstallDate");
+ assertNotNull(val == 0);
+ }
+
+ @Test(groups = { "windows" }, expectedExceptions={ IOException.class })
+ public void getIntegerFault()
+ throws Exception
+ {
+ RegistryKey key = RegistryKey.LocalMachine.open("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
+ assertNotNull(key);
+ assertEquals(key.getValueType("InstallDate"), RegistryValueType.DWORD);
+ long val = key.getLongValue("InstallDate");
+ }
+
}