From: Artur Signell Date: Wed, 11 Apr 2012 14:06:34 +0000 (+0300) Subject: Simplified initialization of ServerRpc proxies X-Git-Tag: 7.0.0.alpha2~86 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5689234f5db140a4bedd7636c4b0635126b27d61;p=vaadin-framework.git Simplified initialization of ServerRpc proxies 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 --- 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 index 0000000000..6cc448785f --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/communication/FieldRpc.java @@ -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 index 0000000000..0270de316e --- /dev/null +++ b/src/com/vaadin/terminal/gwt/client/communication/InitializableServerRpc.java @@ -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 diff --git a/src/com/vaadin/terminal/gwt/client/communication/ServerRpc.java b/src/com/vaadin/terminal/gwt/client/communication/ServerRpc.java index 36f23a0cc1..664c4a391c 100644 --- a/src/com/vaadin/terminal/gwt/client/communication/ServerRpc.java +++ b/src/com/vaadin/terminal/gwt/client/communication/ServerRpc.java @@ -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); - } } diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyCreatorGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyCreatorGenerator.java index 62cdae397c..040715fccf 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyCreatorGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyCreatorGenerator.java @@ -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(); } diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java index 58b04b42e5..3b83edaf25 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/RpcProxyGenerator.java @@ -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[] {");