cvs: /php4/ext/java java.c reflect.java
| From: | Sam Ruby | Date: | Sun, 20 Feb 2000 12:10:04 +0000 |
| Subject: | cvs: /php4/ext/java java.c reflect.java | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-10518@lists.php.net to get a copy of this message | ||
rubys Sun Feb 20 04:10:04 2000 EDT
Modified files:
/php4/ext/java java.c reflect.java
Log:
Added support for arrays
Better support for instances of non-public classes (based on a suggestion
by Patrick Beard of NetScape)
Index: php4/ext/java/java.c
diff -u php4/ext/java/java.c:1.13 php4/ext/java/java.c:1.14
--- php4/ext/java/java.c:1.13 Sat Feb 19 15:21:32 2000
+++ php4/ext/java/java.c Sun Feb 20 04:09:33 2000
@@ -513,6 +513,22 @@
&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: php4/ext/java/reflect.java
diff -u php4/ext/java/reflect.java:1.5 php4/ext/java/reflect.java:1.6
--- php4/ext/java/reflect.java:1.5 Wed Feb 16 22:44:12 2000
+++ php4/ext/java/reflect.java Sun Feb 20 04:09:33 2000
@@ -43,6 +43,8 @@
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 @@
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 @@
(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) &&