summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/java/java.c16
-rw-r--r--ext/java/reflect.java39
-rw-r--r--ext/rpc/java/java.c16
-rw-r--r--ext/rpc/java/reflect.java39
4 files changed, 78 insertions, 32 deletions
diff --git a/ext/java/java.c b/ext/java/java.c
index 0cdd8ad8cb..f1f5cb17d7 100644
--- a/ext/java/java.c
+++ b/ext/java/java.c
@@ -513,6 +513,22 @@ JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromObject
&handle, sizeof(pval *), NULL);
}
+JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromArray
+ (JNIEnv *jenv, jclass self, jlong result)
+{
+ array_init( (pval*)(long)result );
+}
+
+JNIEXPORT jlong JNICALL Java_net_php_reflect_nextElement
+ (JNIEnv *jenv, jclass self, jlong array)
+{
+ pval *result;
+ pval *handle = (pval*)(long)array;
+ ALLOC_ZVAL(result);
+ zend_hash_next_index_insert(handle->value.ht, &result, sizeof(zval *), NULL);
+ return (jlong)(long)result;
+}
+
JNIEXPORT void JNICALL Java_net_php_reflect_setException
(JNIEnv *jenv, jclass self, jlong result, jstring value)
{
diff --git a/ext/java/reflect.java b/ext/java/reflect.java
index 52d39857db..3dafcf719a 100644
--- a/ext/java/reflect.java
+++ b/ext/java/reflect.java
@@ -43,6 +43,8 @@ class reflect {
private static native void setResultFromDouble(long result, double value);
private static native void setResultFromBoolean(long result, boolean value);
private static native void setResultFromObject(long result, Object value);
+ private static native void setResultFromArray(long result);
+ private static native long nextElement(long array);
private static native void setException(long result, String value);
public static native void setEnv();
@@ -71,6 +73,14 @@ class reflect {
setResultFromBoolean(result, ((Boolean)value).booleanValue());
+ } else if (value.getClass().isArray()) {
+
+ long length = Array.getLength(value);
+ setResultFromArray(result);
+ for (int i=0; i<length; i++) {
+ setResult(nextElement(result), Array.get(value, i));
+ }
+
} else {
setResultFromObject(result, value);
@@ -198,27 +208,24 @@ class reflect {
(Object object, String method, Object args[], long result)
{
- // Apparently, if a class is not declared "public" it is illegal to
- // access a method of this class via Invoke. We can't work around
- // all such cases, but enumeration does appear to be a common case.
- if (object instanceof Enumeration && args.length == 0) {
-
- if (method.equalsIgnoreCase("hasMoreElements")) {
- setResultFromBoolean(result, ((Enumeration)object).hasMoreElements());
- return;
- }
-
- if (method.equalsIgnoreCase("nextElement")) {
- setResultFromObject(result, ((Enumeration)object).nextElement());
- return;
- }
- }
-
try {
Vector matches = new Vector();
// gather
for (Class jclass = object.getClass();;jclass=(Class)object) {
+ while (!Modifier.isPublic(jclass.getModifiers())) {
+ // OK, some joker gave us an instance of a non-public class
+ // This often occurs in the case of enumerators
+ // Substitute the first public interface in its place,
+ // and barring that, try the superclass
+ Class interfaces[] = jclass.getInterfaces();
+ jclass=jclass.getSuperclass();
+ for (int i=interfaces.length; i-->0;) {
+ if (Modifier.isPublic(interfaces[i].getModifiers())) {
+ jclass=interfaces[i];
+ }
+ }
+ }
Method methods[] = jclass.getMethods();
for (int i=0; i<methods.length; i++) {
if (methods[i].getName().equalsIgnoreCase(method) &&
diff --git a/ext/rpc/java/java.c b/ext/rpc/java/java.c
index 0cdd8ad8cb..f1f5cb17d7 100644
--- a/ext/rpc/java/java.c
+++ b/ext/rpc/java/java.c
@@ -513,6 +513,22 @@ JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromObject
&handle, sizeof(pval *), NULL);
}
+JNIEXPORT void JNICALL Java_net_php_reflect_setResultFromArray
+ (JNIEnv *jenv, jclass self, jlong result)
+{
+ array_init( (pval*)(long)result );
+}
+
+JNIEXPORT jlong JNICALL Java_net_php_reflect_nextElement
+ (JNIEnv *jenv, jclass self, jlong array)
+{
+ pval *result;
+ pval *handle = (pval*)(long)array;
+ ALLOC_ZVAL(result);
+ zend_hash_next_index_insert(handle->value.ht, &result, sizeof(zval *), NULL);
+ return (jlong)(long)result;
+}
+
JNIEXPORT void JNICALL Java_net_php_reflect_setException
(JNIEnv *jenv, jclass self, jlong result, jstring value)
{
diff --git a/ext/rpc/java/reflect.java b/ext/rpc/java/reflect.java
index 52d39857db..3dafcf719a 100644
--- a/ext/rpc/java/reflect.java
+++ b/ext/rpc/java/reflect.java
@@ -43,6 +43,8 @@ class reflect {
private static native void setResultFromDouble(long result, double value);
private static native void setResultFromBoolean(long result, boolean value);
private static native void setResultFromObject(long result, Object value);
+ private static native void setResultFromArray(long result);
+ private static native long nextElement(long array);
private static native void setException(long result, String value);
public static native void setEnv();
@@ -71,6 +73,14 @@ class reflect {
setResultFromBoolean(result, ((Boolean)value).booleanValue());
+ } else if (value.getClass().isArray()) {
+
+ long length = Array.getLength(value);
+ setResultFromArray(result);
+ for (int i=0; i<length; i++) {
+ setResult(nextElement(result), Array.get(value, i));
+ }
+
} else {
setResultFromObject(result, value);
@@ -198,27 +208,24 @@ class reflect {
(Object object, String method, Object args[], long result)
{
- // Apparently, if a class is not declared "public" it is illegal to
- // access a method of this class via Invoke. We can't work around
- // all such cases, but enumeration does appear to be a common case.
- if (object instanceof Enumeration && args.length == 0) {
-
- if (method.equalsIgnoreCase("hasMoreElements")) {
- setResultFromBoolean(result, ((Enumeration)object).hasMoreElements());
- return;
- }
-
- if (method.equalsIgnoreCase("nextElement")) {
- setResultFromObject(result, ((Enumeration)object).nextElement());
- return;
- }
- }
-
try {
Vector matches = new Vector();
// gather
for (Class jclass = object.getClass();;jclass=(Class)object) {
+ while (!Modifier.isPublic(jclass.getModifiers())) {
+ // OK, some joker gave us an instance of a non-public class
+ // This often occurs in the case of enumerators
+ // Substitute the first public interface in its place,
+ // and barring that, try the superclass
+ Class interfaces[] = jclass.getInterfaces();
+ jclass=jclass.getSuperclass();
+ for (int i=interfaces.length; i-->0;) {
+ if (Modifier.isPublic(interfaces[i].getModifiers())) {
+ jclass=interfaces[i];
+ }
+ }
+ }
Method methods[] = jclass.getMethods();
for (int i=0; i<methods.length; i++) {
if (methods[i].getName().equalsIgnoreCase(method) &&