]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed Serialization issues and cleaned up RPC invocation handler code
authorArtur Signell <artur@vaadin.com>
Thu, 22 Mar 2012 12:11:13 +0000 (14:11 +0200)
committerArtur Signell <artur@vaadin.com>
Thu, 22 Mar 2012 18:07:28 +0000 (20:07 +0200)
src/com/vaadin/terminal/gwt/client/Connector.java
src/com/vaadin/terminal/gwt/client/communication/URLReference.java
src/com/vaadin/ui/AbstractComponent.java

index 59bcdd6bfe030dac27fb98c48c6ba31276fce9a9..22cdbdb4cd4c2d4046cdd89d6d02f93860475c74 100644 (file)
@@ -3,6 +3,8 @@
  */
 package com.vaadin.terminal.gwt.client;
 
+import java.io.Serializable;
+
 import com.vaadin.terminal.gwt.client.communication.SharedState;
 
 /**
@@ -13,7 +15,7 @@ import com.vaadin.terminal.gwt.client.communication.SharedState;
  * @since 7.0.0
  * 
  */
-public interface Connector {
+public interface Connector extends Serializable {
     /**
      * Gets the current shared state of the connector.
      * 
index ae99390f432d1239ac3fcf0022a3c5d5d37d3b19..569c4eff47641060a09340517ccc2dc11795609d 100644 (file)
@@ -3,7 +3,9 @@
  */
 package com.vaadin.terminal.gwt.client.communication;
 
-public class URLReference {
+import java.io.Serializable;
+
+public class URLReference implements Serializable {
 
     private String URL;
 
index b1edc0dd4350367f3a205d7df289ec81b22780fd..f0f861c906760372237598a4f7e1c068ae90e542 100644 (file)
@@ -5,6 +5,7 @@
 package com.vaadin.ui;
 
 import java.io.Serializable;
+import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
@@ -1636,22 +1637,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         // create, initialize and return a dynamic proxy for RPC
         try {
             if (!rpcProxyMap.containsKey(rpcInterface)) {
-                InvocationHandler handler = new InvocationHandler() {
-                    public Object invoke(Object proxy, Method method,
-                            Object[] args) throws Throwable {
-                        addMethodInvocationToQueue(rpcInterface.getName()
-                                .replaceAll("\\$", "."), method.getName(), args);
-                        // TODO no need to do full repaint if only RPC calls
-                        requestRepaint();
-                        return null;
-                    }
-                };
-                Class<?> proxyClass = Proxy.getProxyClass(
-                        rpcInterface.getClassLoader(),
-                        new Class[] { rpcInterface });
-                T rpcProxy = (T) proxyClass.getConstructor(
-                        new Class[] { InvocationHandler.class }).newInstance(
-                        new Object[] { handler });
+                Class<T> proxyClass = (Class) Proxy.getProxyClass(
+                        rpcInterface.getClassLoader(), rpcInterface);
+                Constructor<T> constructor = proxyClass
+                        .getConstructor(InvocationHandler.class);
+                T rpcProxy = constructor.newInstance(new RpcInvoicationHandler(
+                        rpcInterface));
                 // cache the proxy
                 rpcProxyMap.put(rpcInterface, rpcProxy);
             }
@@ -1662,6 +1653,25 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         }
     }
 
+    private class RpcInvoicationHandler implements InvocationHandler,
+            Serializable {
+
+        private String rpcInterfaceName;
+
+        public RpcInvoicationHandler(Class<?> rpcInterface) {
+            rpcInterfaceName = rpcInterface.getName().replaceAll("\\$", ".");
+        }
+
+        public Object invoke(Object proxy, Method method, Object[] args)
+                throws Throwable {
+            addMethodInvocationToQueue(rpcInterfaceName, method.getName(), args);
+            // TODO no need to do full repaint if only RPC calls
+            requestRepaint();
+            return null;
+        }
+
+    }
+
     /**
      * For internal use: adds a method invocation to the pending RPC call queue.
      *