]> source.dussan.org Git - vaadin-framework.git/commitdiff
Simplified initialization of ServerRpc proxies
authorArtur Signell <artur@vaadin.com>
Wed, 11 Apr 2012 14:06:34 +0000 (17:06 +0300)
committerArtur Signell <artur@vaadin.com>
Thu, 12 Apr 2012 06:58:11 +0000 (09:58 +0300)
Renamed InitializableClientToServerRpc -> InitializableServerRpc and
moved it out from ServerRpc to avoid confusion (#8599)

It is now possible to use RpcProxy.create(class, Connector) before the
connector has been initialized

src/com/vaadin/terminal/gwt/client/communication/FieldRpc.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/communication/InitializableServerRpc.java [new file with mode: 0644]
src/com/vaadin/terminal/gwt/client/communication/ServerRpc.java
src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyCreatorGenerator.java
src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java

diff --git a/src/com/vaadin/terminal/gwt/client/communication/FieldRpc.java b/src/com/vaadin/terminal/gwt/client/communication/FieldRpc.java
new file mode 100644 (file)
index 0000000..6cc4487
--- /dev/null
@@ -0,0 +1,17 @@
+package com.vaadin.terminal.gwt.client.communication;
+
+
+public class FieldRpc {
+    public interface FocusServerRpc extends ServerRpc {
+        public void focus();
+    }
+
+    public interface BlurServerRpc extends ServerRpc {
+        public void blur();
+    }
+
+    public interface FocusAndBlurServerRpc extends FocusServerRpc,
+            BlurServerRpc {
+
+    }
+}
diff --git a/src/com/vaadin/terminal/gwt/client/communication/InitializableServerRpc.java b/src/com/vaadin/terminal/gwt/client/communication/InitializableServerRpc.java
new file mode 100644 (file)
index 0000000..0270de3
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.terminal.gwt.client.communication;
+
+import com.vaadin.terminal.gwt.client.ServerConnector;
+
+/**
+ * Initialization support for client to server RPC interfaces.
+ * 
+ * This is in a separate interface used by the GWT generator class. The init
+ * method is not in {@link ServerRpc} because then also server side proxies
+ * would have to implement the initialization method.
+ * 
+ * @since 7.0
+ */
+public interface InitializableServerRpc extends ServerRpc {
+    /**
+     * Associates the RPC proxy with a connector. Called by generated code.
+     * Should never be called manually.
+     * 
+     * @param connector
+     *            The connector the ServerRPC instance is assigned to.
+     */
+    public void initRpc(ServerConnector connector);
+}
\ No newline at end of file
index 36f23a0cc16634ed5fe76fde36d8ea91df27d315..664c4a391c68120707f8d49c1a5ed834f12f3964 100644 (file)
@@ -6,29 +6,10 @@ package com.vaadin.terminal.gwt.client.communication;
 
 import java.io.Serializable;
 
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
-
 /**
  * Interface to be extended by all client to server RPC interfaces.
  * 
- * The nested interface InitializableClientToServerRpc has an
- * {@link #initRpc(String, ApplicationConnection)} method, which is created
- * automatically by a GWT generator and must be called on the client side before
- * generated implementations of the interface are used to perform RPC calls.
- * 
  * @since 7.0
  */
 public interface ServerRpc extends Serializable {
-    /**
-     * Initialization support for client to server RPC interfaces.
-     * 
-     * This is in a separate interface instead of {@link ServerRpc} because
-     * otherwise also server side proxies would have to implement the
-     * initialization method.
-     * 
-     * @since 7.0
-     */
-    public interface InitializableClientToServerRpc extends ServerRpc {
-        public void initRpc(String connectorId, ApplicationConnection client);
-    }
 }
index 62cdae397c5f562eafb2f33bce666da68dbadd5a..040715fccf86b1086a5867553ff5c751929b97f5 100644 (file)
@@ -17,9 +17,9 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle;
 import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
 import com.google.gwt.user.rebind.SourceWriter;
 import com.vaadin.terminal.gwt.client.ServerConnector;
+import com.vaadin.terminal.gwt.client.communication.InitializableServerRpc;
 import com.vaadin.terminal.gwt.client.communication.RpcProxy.RpcProxyCreator;
 import com.vaadin.terminal.gwt.client.communication.ServerRpc;
-import com.vaadin.terminal.gwt.client.communication.ServerRpc.InitializableClientToServerRpc;
 
 public class RpcProxyCreatorGenerator extends Generator {
 
@@ -62,8 +62,7 @@ public class RpcProxyCreatorGenerator extends Generator {
         composer.addImport(GWT.class.getCanonicalName());
         composer.addImport(ServerRpc.class.getCanonicalName());
         composer.addImport(ServerConnector.class.getCanonicalName());
-        composer.addImport(InitializableClientToServerRpc.class
-                .getCanonicalName());
+        composer.addImport(InitializableServerRpc.class.getCanonicalName());
         composer.addImport(IllegalArgumentException.class.getCanonicalName());
         composer.addImplementedInterface(RpcProxyCreator.class
                 .getCanonicalName());
@@ -82,19 +81,13 @@ public class RpcProxyCreatorGenerator extends Generator {
         sourceWriter
                 .println("throw new IllegalArgumentException(\"RpcInterface and/or connector cannot be null\");");
         sourceWriter.outdent();
-        sourceWriter
-                .println("} else if (connector.getConnectorId() == null) {");
-        sourceWriter.indent();
-        sourceWriter
-                .println("throw new IllegalArgumentException(\"Connector must be initialized before creating Rpc instances.\");");
-        sourceWriter.outdent();
 
         JClassType initializableInterface = typeOracle.findType(ServerRpc.class
                 .getCanonicalName());
 
         for (JClassType rpcType : initializableInterface.getSubtypes()) {
             String rpcClassName = rpcType.getQualifiedSourceName();
-            if (InitializableClientToServerRpc.class.getCanonicalName().equals(
+            if (InitializableServerRpc.class.getCanonicalName().equals(
                     rpcClassName)) {
                 // InitializableClientToServerRpc is a special marker interface
                 // that should not get a generated class
@@ -105,8 +98,8 @@ public class RpcProxyCreatorGenerator extends Generator {
             sourceWriter.indent();
             sourceWriter.println(rpcClassName + " rpc = GWT.create("
                     + rpcClassName + ".class);");
-            sourceWriter
-                    .println("((InitializableClientToServerRpc) rpc).initRpc(connector.getConnectorId(), connector.getConnection());");
+            sourceWriter.println("((" + InitializableServerRpc.class.getName()
+                    + ") rpc).initRpc(connector);");
             sourceWriter.println("return (T) rpc;");
             sourceWriter.outdent();
         }
index 58b04b42e5c238b42c92c6556dbbca5d641dd14d..3b83edaf25a5f53a5e0957b1c468e24f27e28b67 100644 (file)
@@ -18,9 +18,10 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle;
 import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
 import com.google.gwt.user.rebind.SourceWriter;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ServerConnector;
+import com.vaadin.terminal.gwt.client.communication.InitializableServerRpc;
 import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
 import com.vaadin.terminal.gwt.client.communication.ServerRpc;
-import com.vaadin.terminal.gwt.client.communication.ServerRpc.InitializableClientToServerRpc;
 
 /**
  * GWT generator that creates client side proxy classes for making RPC calls
@@ -52,7 +53,7 @@ public class RpcProxyGenerator extends Generator {
                 + requestedType.getName().replaceAll("[$.]", "_");
 
         JClassType initializableInterface = typeOracle
-                .findType(InitializableClientToServerRpc.class
+                .findType(InitializableServerRpc.class
                         .getCanonicalName());
 
         ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(
@@ -96,20 +97,14 @@ public class RpcProxyGenerator extends Generator {
                 .findType(ApplicationConnection.class.getCanonicalName());
 
         // fields
-        writer.println("private String connectorId;");
-        writer.println("private "
-                + applicationConnectionClass.getQualifiedSourceName()
-                + " client;");
+        writer.println("private " + ServerConnector.class.getName()
+                + " connector;");
 
         // init method from the RPC interface
-        writer.println("public void initRpc(String connectorId, "
-                + applicationConnectionClass.getQualifiedSourceName()
-                + " client) {");
+        writer.println("public void initRpc(" + ServerConnector.class.getName()
+                + " connector) {");
         writer.indent();
-
-        writer.println("this.connectorId = connectorId;");
-        writer.println("this.client = client;");
-
+        writer.println("this.connector = connector;");
         writer.outdent();
         writer.println("}");
     }
@@ -123,7 +118,7 @@ public class RpcProxyGenerator extends Generator {
             writer.println(" {");
             writer.indent();
 
-            writer.print("client.addMethodInvocationToQueue(new MethodInvocation(connectorId, \""
+            writer.print("connector.getConnection().addMethodInvocationToQueue(new MethodInvocation(connector.getConnectorId(), \""
                     + requestedType.getQualifiedBinaryName() + "\", \"");
             writer.print(m.getName());
             writer.print("\", new Object[] {");