diff options
-rw-r--r-- | ext/java/README | 10 | ||||
-rw-r--r-- | ext/java/except.php | 23 | ||||
-rw-r--r-- | ext/java/java.c | 32 | ||||
-rw-r--r-- | ext/java/reflect.java | 11 | ||||
-rw-r--r-- | ext/rpc/java/README | 10 | ||||
-rw-r--r-- | ext/rpc/java/except.php | 23 | ||||
-rw-r--r-- | ext/rpc/java/java.c | 32 | ||||
-rw-r--r-- | ext/rpc/java/reflect.java | 11 |
8 files changed, 150 insertions, 2 deletions
diff --git a/ext/java/README b/ext/java/README index 6a19f8e952..6c64dcfe40 100644 --- a/ext/java/README +++ b/ext/java/README @@ -20,7 +20,15 @@ What is PHP4 ext/java? the same syntax. Furthermore, if the java object is of type "java.lang.Class", then static members - 4) Exceptions raised result in PHP warnings, and null results. + 4) Exceptions raised result in PHP warnings, and null results. The + warnings may be eliminated by prefixing the method call with an + "@" sign. The following experimental APIs may be used to retrieve + and reset the last error: + + java_last_exception_get() + java_last_exception_clear() + + These APIs are not currently implemented in a reentrant fashion. 5) Overload resolution is in general a hard problem given the differences in types between the two languages. The PHP Java diff --git a/ext/java/except.php b/ext/java/except.php new file mode 100644 index 0000000000..a7e6a79c08 --- /dev/null +++ b/ext/java/except.php @@ -0,0 +1,23 @@ +<? + $stack=new Java("java.util.Stack"); + $stack->push(1); + + # + # Should succeed and print out "1" + # + $result = $stack->pop(); + $ex = java_last_exception_get(); + if (!$ex) print "$result\n"; + + # + # Should fail - note the "@" eliminates the warning + # + $result=@$stack->pop(); + $ex=java_last_exception_get(); + if ($ex) print $ex->toString(); + + # + # Reset last exception + # + java_last_exception_clear(); +?> diff --git a/ext/java/java.c b/ext/java/java.c index 10ee1391ce..9d0cf7516e 100644 --- a/ext/java/java.c +++ b/ext/java/java.c @@ -384,6 +384,36 @@ void java_call_function_handler /***************************************************************************/ +PHP_FUNCTION(java_last_exception_get) +{ + jlong result = 0; + jmethodID lastEx; + + (pval*)(long)result = return_value; + + lastEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "lastException", + "(J)V"); + + (*jenv)->CallStaticVoidMethod(jenv, php_reflect, lastEx, result); +} + +/***************************************************************************/ + +PHP_FUNCTION(java_last_exception_clear) +{ + jlong result = 0; + jmethodID clearEx; + + (pval*)(long)result = return_value; + + clearEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "clearException", + "()V"); + + (*jenv)->CallStaticVoidMethod(jenv, php_reflect, clearEx); +} + +/***************************************************************************/ + static pval _java_getset_property (zend_property_reference *property_reference, jobjectArray value) { @@ -475,6 +505,8 @@ PHP_MSHUTDOWN_FUNCTION(java) { } function_entry java_functions[] = { + PHP_FE(java_last_exception_get, NULL) + PHP_FE(java_last_exception_clear, NULL) {NULL, NULL, NULL} }; diff --git a/ext/java/reflect.java b/ext/java/reflect.java index 0d6347cf84..35842ea939 100644 --- a/ext/java/reflect.java +++ b/ext/java/reflect.java @@ -88,12 +88,23 @@ public class reflect { } } + static Throwable lastException = null; + + static void lastException(long result) { + setResult(result, lastException); + } + + static void clearException() { + lastException = null; + } + static void setException(long result, Throwable e) { if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException)e).getTargetException(); if (t!=null) e=t; } + lastException = e; setException(result, e.toString().getBytes()); } diff --git a/ext/rpc/java/README b/ext/rpc/java/README index 6a19f8e952..6c64dcfe40 100644 --- a/ext/rpc/java/README +++ b/ext/rpc/java/README @@ -20,7 +20,15 @@ What is PHP4 ext/java? the same syntax. Furthermore, if the java object is of type "java.lang.Class", then static members - 4) Exceptions raised result in PHP warnings, and null results. + 4) Exceptions raised result in PHP warnings, and null results. The + warnings may be eliminated by prefixing the method call with an + "@" sign. The following experimental APIs may be used to retrieve + and reset the last error: + + java_last_exception_get() + java_last_exception_clear() + + These APIs are not currently implemented in a reentrant fashion. 5) Overload resolution is in general a hard problem given the differences in types between the two languages. The PHP Java diff --git a/ext/rpc/java/except.php b/ext/rpc/java/except.php new file mode 100644 index 0000000000..a7e6a79c08 --- /dev/null +++ b/ext/rpc/java/except.php @@ -0,0 +1,23 @@ +<? + $stack=new Java("java.util.Stack"); + $stack->push(1); + + # + # Should succeed and print out "1" + # + $result = $stack->pop(); + $ex = java_last_exception_get(); + if (!$ex) print "$result\n"; + + # + # Should fail - note the "@" eliminates the warning + # + $result=@$stack->pop(); + $ex=java_last_exception_get(); + if ($ex) print $ex->toString(); + + # + # Reset last exception + # + java_last_exception_clear(); +?> diff --git a/ext/rpc/java/java.c b/ext/rpc/java/java.c index 10ee1391ce..9d0cf7516e 100644 --- a/ext/rpc/java/java.c +++ b/ext/rpc/java/java.c @@ -384,6 +384,36 @@ void java_call_function_handler /***************************************************************************/ +PHP_FUNCTION(java_last_exception_get) +{ + jlong result = 0; + jmethodID lastEx; + + (pval*)(long)result = return_value; + + lastEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "lastException", + "(J)V"); + + (*jenv)->CallStaticVoidMethod(jenv, php_reflect, lastEx, result); +} + +/***************************************************************************/ + +PHP_FUNCTION(java_last_exception_clear) +{ + jlong result = 0; + jmethodID clearEx; + + (pval*)(long)result = return_value; + + clearEx = (*jenv)->GetStaticMethodID(jenv, php_reflect, "clearException", + "()V"); + + (*jenv)->CallStaticVoidMethod(jenv, php_reflect, clearEx); +} + +/***************************************************************************/ + static pval _java_getset_property (zend_property_reference *property_reference, jobjectArray value) { @@ -475,6 +505,8 @@ PHP_MSHUTDOWN_FUNCTION(java) { } function_entry java_functions[] = { + PHP_FE(java_last_exception_get, NULL) + PHP_FE(java_last_exception_clear, NULL) {NULL, NULL, NULL} }; diff --git a/ext/rpc/java/reflect.java b/ext/rpc/java/reflect.java index 0d6347cf84..35842ea939 100644 --- a/ext/rpc/java/reflect.java +++ b/ext/rpc/java/reflect.java @@ -88,12 +88,23 @@ public class reflect { } } + static Throwable lastException = null; + + static void lastException(long result) { + setResult(result, lastException); + } + + static void clearException() { + lastException = null; + } + static void setException(long result, Throwable e) { if (e instanceof InvocationTargetException) { Throwable t = ((InvocationTargetException)e).getTargetException(); if (t!=null) e=t; } + lastException = e; setException(result, e.toString().getBytes()); } |