diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-21 16:51:33 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-22 19:25:32 +0300 |
commit | e345e1820aa0e0fe551cca86d6d28b906beb8937 (patch) | |
tree | a063cfb43b58c931a891c1454dd3a4fead1f05fa /client | |
parent | b3a2c24e88456d958af9804f940ff9bfc2621fae (diff) | |
download | vaadin-framework-e345e1820aa0e0fe551cca86d6d28b906beb8937.tar.gz vaadin-framework-e345e1820aa0e0fe551cca86d6d28b906beb8937.zip |
Use ConnectorBundle for ServerRpc handling (#9371)
Diffstat (limited to 'client')
10 files changed, 145 insertions, 82 deletions
diff --git a/client/src/com/vaadin/Vaadin.gwt.xml b/client/src/com/vaadin/Vaadin.gwt.xml index e25c812e5b..fe9643232e 100644 --- a/client/src/com/vaadin/Vaadin.gwt.xml +++ b/client/src/com/vaadin/Vaadin.gwt.xml @@ -41,20 +41,6 @@ class="com.vaadin.terminal.gwt.client.ui.dd.VAcceptCriterionFactory" /> </generate-with> - <!-- Generate client side proxies for client to server RPC interfaces --> - <generate-with - class="com.vaadin.terminal.gwt.widgetsetutils.RpcProxyGenerator"> - <when-type-assignable - class="com.vaadin.shared.communication.ServerRpc" /> - </generate-with> - - <!-- Generate client side proxies for client to server RPC interfaces --> - <generate-with - class="com.vaadin.terminal.gwt.widgetsetutils.RpcProxyCreatorGenerator"> - <when-type-assignable - class="com.vaadin.terminal.gwt.client.communication.RpcProxy.RpcProxyCreator" /> - </generate-with> - <generate-with class="com.vaadin.terminal.gwt.widgetsetutils.ConnectorBundleLoaderFactory"> <when-type-assignable class="com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader" /> </generate-with> diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 8ba8f0afab..9b58eb1295 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -208,6 +208,9 @@ public class ApplicationConnection { } public ApplicationConnection() { + // Assuming Root data is eagerly loaded + ConnectorBundleLoader.get().loadBundle( + ConnectorBundleLoader.EAGER_BUNDLE_NAME, null); rootConnector = GWT.create(RootConnector.class); rpcManager = GWT.create(RpcManager.class); layoutManager = GWT.create(LayoutManager.class); @@ -241,10 +244,6 @@ public class ApplicationConnection { initializeClientHooks(); - // Assuming Root data is eagerly loaded - ConnectorBundleLoader.get().loadBundle( - ConnectorBundleLoader.EAGER_BUNDLE_NAME, null); - rootConnector.init(cnf.getRootPanelId(), this); showLoadingIndicator(); } diff --git a/client/src/com/vaadin/terminal/gwt/client/communication/InitializableServerRpc.java b/client/src/com/vaadin/terminal/gwt/client/communication/InitializableServerRpc.java deleted file mode 100644 index 65887bf62e..0000000000 --- a/client/src/com/vaadin/terminal/gwt/client/communication/InitializableServerRpc.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2011 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.terminal.gwt.client.communication; - -import com.vaadin.shared.communication.ServerRpc; -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/client/src/com/vaadin/terminal/gwt/client/communication/RpcManager.java b/client/src/com/vaadin/terminal/gwt/client/communication/RpcManager.java index 45939eb54e..5b9bcff6a4 100644 --- a/client/src/com/vaadin/terminal/gwt/client/communication/RpcManager.java +++ b/client/src/com/vaadin/terminal/gwt/client/communication/RpcManager.java @@ -76,14 +76,14 @@ public class RpcManager { public Type[] getParameterTypes(MethodInvocation invocation) { Method method = getMethod(invocation); - Type[] parameterTypes = method.getParameterTypes(); - if (parameterTypes == null) { + try { + Type[] parameterTypes = method.getParameterTypes(); + return parameterTypes; + } catch (NoDataException e) { throw new IllegalStateException("There is no information about " + method.getSignature() - + ". Did you remember to compile the right widgetset?"); - + + ". Did you remember to compile the right widgetset?", e); } - return parameterTypes; } public void parseAndApplyInvocation(JSONArray rpcCall, diff --git a/client/src/com/vaadin/terminal/gwt/client/communication/RpcProxy.java b/client/src/com/vaadin/terminal/gwt/client/communication/RpcProxy.java index 226594adc6..e9dc6ab7fd 100644 --- a/client/src/com/vaadin/terminal/gwt/client/communication/RpcProxy.java +++ b/client/src/com/vaadin/terminal/gwt/client/communication/RpcProxy.java @@ -15,9 +15,13 @@ */ package com.vaadin.terminal.gwt.client.communication; -import com.google.gwt.core.client.GWT; +import com.vaadin.shared.communication.MethodInvocation; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.terminal.gwt.client.ServerConnector; +import com.vaadin.terminal.gwt.client.metadata.InvokationHandler; +import com.vaadin.terminal.gwt.client.metadata.Method; +import com.vaadin.terminal.gwt.client.metadata.NoDataException; +import com.vaadin.terminal.gwt.client.metadata.TypeData; /** * Class for creating proxy instances for Client to Server RPC. @@ -26,25 +30,38 @@ import com.vaadin.terminal.gwt.client.ServerConnector; */ public class RpcProxy { - private static RpcProxyCreator impl = GWT.create(RpcProxyCreator.class); - - /** - * Create a proxy class for the given Rpc interface and assign it to the - * given connector. - * - * @param rpcInterface - * The rpc interface to construct a proxy for - * @param connector - * The connector this proxy is connected to - * @return A proxy class used for calling Rpc methods. - */ public static <T extends ServerRpc> T create(Class<T> rpcInterface, ServerConnector connector) { - return impl.create(rpcInterface, connector); + try { + return (T) TypeData.getType(rpcInterface).createProxy( + new RpcInvokationHandler(rpcInterface, connector)); + } catch (NoDataException e) { + throw new IllegalStateException("There is no information about " + + rpcInterface + + ". Did you forget to compile the widgetset?"); + } } - public interface RpcProxyCreator { - <T extends ServerRpc> T create(Class<T> rpcInterface, - ServerConnector connector); + private static final class RpcInvokationHandler implements + InvokationHandler { + private final Class<?> rpcInterface; + private final ServerConnector connector; + + private RpcInvokationHandler(Class<?> rpcInterface, + ServerConnector connector) { + this.rpcInterface = rpcInterface; + this.connector = connector; + } + + @Override + public Object invoke(Object target, Method method, Object[] params) { + MethodInvocation invocation = new MethodInvocation( + connector.getConnectorId(), rpcInterface.getName(), + method.getName(), params); + connector.getConnection().addMethodInvocationToQueue(invocation, + method.isDelayed(), method.isLastonly()); + // No RPC iface should have a return value + return null; + } } } diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/InvokationHandler.java b/client/src/com/vaadin/terminal/gwt/client/metadata/InvokationHandler.java new file mode 100644 index 0000000000..2b1153ad97 --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/InvokationHandler.java @@ -0,0 +1,21 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal.gwt.client.metadata; + +public interface InvokationHandler { + public Object invoke(Object target, Method method, Object[] params); +} diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/Method.java b/client/src/com/vaadin/terminal/gwt/client/metadata/Method.java index 588e736da3..527e8a29d2 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/Method.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Method.java @@ -56,8 +56,16 @@ public class Method { return getSignature().hashCode(); } - public Type[] getParameterTypes() { + public Type[] getParameterTypes() throws NoDataException { return TypeDataStore.getParamTypes(this); } + public boolean isDelayed() { + return TypeDataStore.isDelayed(this); + } + + public boolean isLastonly() { + return TypeDataStore.isLastonly(this); + } + } diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/ProxyHandler.java b/client/src/com/vaadin/terminal/gwt/client/metadata/ProxyHandler.java new file mode 100644 index 0000000000..cc8168a8ff --- /dev/null +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/ProxyHandler.java @@ -0,0 +1,23 @@ +/* + * Copyright 2011 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.terminal.gwt.client.metadata; + +public interface ProxyHandler { + + Object createProxy(InvokationHandler invokationHandler); + +} diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java b/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java index dfd504983c..2dc5182845 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java @@ -76,4 +76,10 @@ public class Type { return getSignature().hashCode(); } + public Object createProxy(InvokationHandler invokationHandler) + throws NoDataException { + return TypeDataStore.get().getProxyHandler(this) + .createProxy(invokationHandler); + } + } diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java index 4b99250465..f056e46d2d 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java @@ -5,13 +5,20 @@ package com.vaadin.terminal.gwt.client.metadata; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; public class TypeDataStore { private static final String CONSTRUCTOR_NAME = "!new"; private final Map<String, Class<?>> identifiers = new HashMap<String, Class<?>>(); + private final Map<Type, ProxyHandler> proxyHandlers = new HashMap<Type, ProxyHandler>(); + + private final Set<Method> delayedMethods = new HashSet<Method>(); + private final Set<Method> lastonlyMethods = new HashSet<Method>(); + private final Map<Method, Type> returnTypes = new HashMap<Method, Type>(); private final Map<Method, Invoker> invokers = new HashMap<Method, Invoker>(); private final Map<Method, Type[]> paramTypes = new HashMap<Method, Type[]>(); @@ -94,8 +101,13 @@ public class TypeDataStore { invokers.put(new Method(getType(type), methodName), invoker); } - public static Type[] getParamTypes(Method method) { - return get().paramTypes.get(method); + public static Type[] getParamTypes(Method method) throws NoDataException { + Type[] types = get().paramTypes.get(method); + if (types == null) { + throw new NoDataException("There are no parameter type data for " + + method.getSignature()); + } + return types; } public void setParamTypes(Class<?> type, String methodName, @@ -106,4 +118,34 @@ public class TypeDataStore { public static boolean hasIdentifier(String identifier) { return get().identifiers.containsKey(identifier); } + + public static ProxyHandler getProxyHandler(Type type) + throws NoDataException { + ProxyHandler proxyHandler = get().proxyHandlers.get(type); + if (proxyHandler == null) { + throw new NoDataException("No proxy handler for " + + type.getSignature()); + } + return proxyHandler; + } + + public void setProxyHandler(Class<?> type, ProxyHandler proxyHandler) { + proxyHandlers.put(getType(type), proxyHandler); + } + + public static boolean isDelayed(Method method) { + return get().delayedMethods.contains(method); + } + + public void setDelayed(Class<?> type, String methodName) { + delayedMethods.add(getType(type).getMethod(methodName)); + } + + public static boolean isLastonly(Method method) { + return get().lastonlyMethods.contains(method); + } + + public void setLastonly(Class<?> clazz, String methodName) { + lastonlyMethods.add(getType(clazz).getMethod(methodName)); + } } |