Revision: 2776
          http://vexi.svn.sourceforge.net/vexi/?rev=2776&view=rev
Author:   mkpg2
Date:     2008-01-31 08:08:03 -0800 (Thu, 31 Jan 2008)

Log Message:
-----------
Fixes to JSProxy

Modified Paths:
--------------
    trunk/core/org.ibex.js/src/org/ibex/js/JSProxy.java
    trunk/core/org.ibex.js/src_junit/org/ibex/js/TestJSProxy.java
    trunk/core/org.ibex.js/src_junit/test/js/exec/rpc/json/jsonexample.js

Modified: trunk/core/org.ibex.js/src/org/ibex/js/JSProxy.java
===================================================================
--- trunk/core/org.ibex.js/src/org/ibex/js/JSProxy.java 2008-01-31 15:25:34 UTC 
(rev 2775)
+++ trunk/core/org.ibex.js/src/org/ibex/js/JSProxy.java 2008-01-31 16:08:03 UTC 
(rev 2776)
@@ -13,6 +13,7 @@
     
     Map methods = new HashMap();
     
+    
     final Set keySet;
     
     final Keys keysObj = new Keys(this){
@@ -52,9 +53,14 @@
                  methods.get(key);
         if(m==null) throw new JSExn("Method '" + method + "' doesn't take " + 
jsargs.length + " args");
         Object[] args = new Object[jsargs.length];
+        Class[] types = m.getParameterTypes();
         for(int i=0; i<args.length; i++){
             args[i] = convertRequest(jsargs[i]);
+            // FEATURE - show js types not java ones
+            if(args[i]!=null && !(types[i].isInstance(args[i]))) 
+               throw new JSExn("Arg " + i + " incompatible. Expected 
"+types[i]+", got " + args[i].getClass());
         }
+        
         try {
                try{
                        Object r = m.invoke(proxee, args);
@@ -70,10 +76,11 @@
         }
     }
     
-    protected Object convertRequest(JS js) throws JSExn{
+    static public Object convertRequest(JS js) throws JSExn{
         // VERIFY - can js send every type even if the value
        // doesn't put it in that types range (double, but no
        // decimal, long with a small value ...)
+       if(js == null) return null;
        if(js instanceof JSNumber){
                if(js instanceof JSNumber.D)
                        return Double.valueOf(JSU.toDouble(js));
@@ -108,7 +115,7 @@
         throw new JSExn("Cannot convert request: " + js);
     }
     
-    protected JS convertResponse(Object o) throws JSExn{
+    static public JS convertResponse(Object o) throws JSExn{
         if(o instanceof Object[]){
             Object[] o_ =(Object[])o;
             JSArray r = new JSArray(o_.length);

Modified: trunk/core/org.ibex.js/src_junit/org/ibex/js/TestJSProxy.java
===================================================================
--- trunk/core/org.ibex.js/src_junit/org/ibex/js/TestJSProxy.java       
2008-01-31 15:25:34 UTC (rev 2775)
+++ trunk/core/org.ibex.js/src_junit/org/ibex/js/TestJSProxy.java       
2008-01-31 16:08:03 UTC (rev 2776)
@@ -54,6 +54,19 @@
         }
     }
        
+       public void testWrongArgType() throws Exception {
+        JSProxy js = new JSProxy("proxee",Interfase.class,new Proxee());
+        try{
+               js.call(JSU.S("add"), new JS[]{JSU.S("foo")});
+               fail("Expected exception");
+        }catch(JSExn e){/*expected*/
+               Throwable cause = (Throwable) e.getCause();
+               assertEquals(null,cause);
+               Log.warn(TestJSProxy.class, e);
+        }
+    }
+       
+       
        public void testJavaException() throws Exception {
         JSProxy js = new JSProxy("proxee",Interfase.class,new Proxee());
         try{

Modified: trunk/core/org.ibex.js/src_junit/test/js/exec/rpc/json/jsonexample.js
===================================================================
--- trunk/core/org.ibex.js/src_junit/test/js/exec/rpc/json/jsonexample.js       
2008-01-31 15:25:34 UTC (rev 2775)
+++ trunk/core/org.ibex.js/src_junit/test/js/exec/rpc/json/jsonexample.js       
2008-01-31 16:08:03 UTC (rev 2776)
@@ -4,21 +4,20 @@
 
 var json = 
 '{'+
-'  "name": "Simon Willison",'+
-'  "age": 25,'+
+'  "name": "Reverand Green",'+
+'  "age": 38,'+
 '  "height": 1.68,'+
 '  "urls": ['+
-'    "http:\/\/simonwillison.net\/",'+
-'    "http:\/\/www.flickr.com\/photos/simon\/",'+
-'    "http:\/\/simon.incutio.com\/"'+
+'    "http:\/\/www.bbc.co.uk\/",'+
+'    "http:\/\/www.bishopsonline.com\/"'+
 '  ]'+
 '}';
 
 var assertObj = function(o){
-   assertEquals("Simon Willison",o.name);
-   assertEquals(25,o.age);
+   assertEquals("Reverand Green",o.name);
+   assertEquals(38,o.age);
    assertEquals(1.68,o.height);
-   assertEquals(3,o.urls.length);
+   assertEquals(2,o.urls.length);
    
 }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to