From: <php...@li...> - 2009-01-17 19:02:51
|
Hi Juergen, I really don't understand the problem. I have posted a test case which does what you want. I do understand that you don't have the information to resolve the type, so that you must call the methods through the reflection API. But I don't understand why you insist using your own test case, which cannot work, because you confuse the proxy with the invocation handler. ------------------------------------- package test; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.OutputStreamWriter; import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public class TestGetInterface { /** * @param args */ public static void main(String[] args) throws Throwable { //System.setProperty("php.java.bridge.default_log_file", ""); //System.setProperty("php.java.bridge.default_log_level", "3"); new TestGetInterface().doWork(); } private ScriptEngine scriptEngine; String classA = "class A{function toString(){return '::A';} function invokeA($b){java('java.lang.reflect.Proxy')->getInvocationHandler($b)->invoke($b, "invokeB", array());}}\n"; String classB = "class B{function toString(){return '::B';} function invokeB(){echo '::B';}}\n"; String test = "<?php "+classA+classB+" $thiz=java_context()->getAttribute('thiz');\n$thiz->call(java_closure(new A()), java_closure(new B())); ?>"; private void doWork() throws Throwable { scriptEngine = new ScriptEngineManager().getEngineByName("php-invocable"); scriptEngine.put("thiz", this); ByteArrayOutputStream out; OutputStreamWriter writer; scriptEngine.getContext().setWriter(writer = new OutputStreamWriter(out = new ByteArrayOutputStream())); scriptEngine.eval(test); ((Closeable)scriptEngine).close(); writer.close(); if(!"::B".equals(out.toString())) { System.err.println("test failed"); System.exit(1); } System.out.println("test okay"); System.exit(0); } interface IA { public void invokeA(IB ccb); }; interface IB { public void invokeB(); }; public void call(Object $cca, Object $ccb) throws Throwable { ((php.java.bridge.PhpProcedure)java.lang.reflect.Proxy.getInvocationHandler($cca)).invoke($cca, "invokeA", new Object[]{$ccb}); } } -------------- > So, what did you mean with "use the same procedure as above"? Use the Java reflection API. The above example shows how to do this in PHP and in Java. Regards, Jost Boekemeier |