]> granicus.if.org Git - php/commitdiff
Added support for arrays
authorSam Ruby <rubys@php.net>
Sun, 20 Feb 2000 12:09:34 +0000 (12:09 +0000)
committerSam Ruby <rubys@php.net>
Sun, 20 Feb 2000 12:09:34 +0000 (12:09 +0000)
Better support for instances of non-public classes (based on a suggestion
by Patrick Beard of NetScape)

ext/java/java.c
ext/java/reflect.java
ext/rpc/java/java.c
ext/rpc/java/reflect.java

index 0cdd8ad8cbed4b6249569cf10e08c6a05c347455..f1f5cb17d7f5d1c8aa4181bdb9257f90505461c8 100644 (file)
@@ -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)
 {
index 52d39857db2554667db7f2ac4ad6fb753f1b06d5..3dafcf719a70d8a2be31c1d4dfa69d63068d972f 100644 (file)
@@ -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) &&
index 0cdd8ad8cbed4b6249569cf10e08c6a05c347455..f1f5cb17d7f5d1c8aa4181bdb9257f90505461c8 100644 (file)
@@ -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)
 {
index 52d39857db2554667db7f2ac4ad6fb753f1b06d5..3dafcf719a70d8a2be31c1d4dfa69d63068d972f 100644 (file)
@@ -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) &&