summaryrefslogtreecommitdiffstats
path: root/client/src/com/vaadin/terminal
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-21 12:33:32 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-22 19:25:31 +0300
commitbcef4d5e716a275f3a3588cd9e50885129d38eb7 (patch)
tree5bc17a54d1e6a804539793e4fa2a79615b263b73 /client/src/com/vaadin/terminal
parentd51dcf18b8d7f64f763163c5965ca30b8c33070d (diff)
downloadvaadin-framework-bcef4d5e716a275f3a3588cd9e50885129d38eb7.tar.gz
vaadin-framework-bcef4d5e716a275f3a3588cd9e50885129d38eb7.zip
Use ConnectorBundle for ClientRpc handling (#9371)
Diffstat (limited to 'client/src/com/vaadin/terminal')
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java11
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/WidgetSet.java21
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/communication/RpcManager.java53
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/communication/RpcMethod.java47
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/metadata/Method.java13
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/metadata/NoDataException.java (renamed from client/src/com/vaadin/terminal/gwt/client/communication/GeneratedRpcMethodProvider.java)21
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/metadata/Property.java2
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/metadata/Type.java4
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/metadata/TypeData.java8
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java67
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java15
-rw-r--r--client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java17
12 files changed, 155 insertions, 124 deletions
diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
index 8f6697288c..8bb4f37324 100644
--- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
+++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConfiguration.java
@@ -33,6 +33,7 @@ import com.google.gwt.user.client.Window;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.terminal.gwt.client.metadata.BundleLoadCallback;
import com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader;
+import com.vaadin.terminal.gwt.client.metadata.NoDataException;
import com.vaadin.terminal.gwt.client.metadata.TypeData;
import com.vaadin.terminal.gwt.client.ui.UnknownComponentConnector;
@@ -398,8 +399,14 @@ public class ApplicationConfiguration implements EntryPoint {
Integer currentTag = Integer.valueOf(tag);
while (type == null && currentTag != null) {
String serverSideClassNameForTag = getServerSideClassNameForTag(currentTag);
- type = (Class<? extends ServerConnector>) TypeData
- .getClass(serverSideClassNameForTag);
+ if (TypeData.hasIdentifier(serverSideClassNameForTag)) {
+ try {
+ type = (Class<? extends ServerConnector>) TypeData
+ .getClass(serverSideClassNameForTag);
+ } catch (NoDataException e) {
+ throw new RuntimeException(e);
+ }
+ }
currentTag = getParentTag(currentTag.intValue());
}
if (type == null) {
diff --git a/client/src/com/vaadin/terminal/gwt/client/WidgetSet.java b/client/src/com/vaadin/terminal/gwt/client/WidgetSet.java
index 776436f5f0..8245371161 100644
--- a/client/src/com/vaadin/terminal/gwt/client/WidgetSet.java
+++ b/client/src/com/vaadin/terminal/gwt/client/WidgetSet.java
@@ -20,6 +20,7 @@ import com.google.gwt.core.client.GWT;
import com.vaadin.terminal.gwt.client.communication.HasJavaScriptConnectorHelper;
import com.vaadin.terminal.gwt.client.metadata.BundleLoadCallback;
import com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader;
+import com.vaadin.terminal.gwt.client.metadata.NoDataException;
import com.vaadin.terminal.gwt.client.metadata.TypeData;
import com.vaadin.terminal.gwt.client.ui.UnknownComponentConnector;
@@ -60,13 +61,21 @@ public class WidgetSet {
/*
* let the auto generated code instantiate this type
*/
- ServerConnector connector = (ServerConnector) TypeData.getType(
- classType).createInstance();
- if (connector instanceof HasJavaScriptConnectorHelper) {
- ((HasJavaScriptConnectorHelper) connector)
- .getJavascriptConnectorHelper().setTag(tag);
+ try {
+ ServerConnector connector = (ServerConnector) TypeData.getType(
+ classType).createInstance();
+ if (connector instanceof HasJavaScriptConnectorHelper) {
+ ((HasJavaScriptConnectorHelper) connector)
+ .getJavascriptConnectorHelper().setTag(tag);
+ }
+ return connector;
+ } catch (NoDataException e) {
+ throw new IllegalStateException(
+ "There is no information about "
+ + classType
+ + ". Did you remember to compile the right widgetset?",
+ e);
}
- return connector;
}
}
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 537cc34185..45939eb54e 100644
--- a/client/src/com/vaadin/terminal/gwt/client/communication/RpcManager.java
+++ b/client/src/com/vaadin/terminal/gwt/client/communication/RpcManager.java
@@ -17,10 +17,7 @@
package com.vaadin.terminal.gwt.client.communication;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONString;
import com.vaadin.shared.communication.ClientRpc;
@@ -29,6 +26,8 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.ServerConnector;
import com.vaadin.terminal.gwt.client.VConsole;
+import com.vaadin.terminal.gwt.client.metadata.Method;
+import com.vaadin.terminal.gwt.client.metadata.NoDataException;
import com.vaadin.terminal.gwt.client.metadata.Type;
/**
@@ -42,19 +41,6 @@ import com.vaadin.terminal.gwt.client.metadata.Type;
*/
public class RpcManager {
- private final Map<String, RpcMethod> methodMap = new HashMap<String, RpcMethod>();
-
- public RpcManager() {
- GeneratedRpcMethodProvider provider = GWT
- .create(GeneratedRpcMethodProvider.class);
- Collection<RpcMethod> methods = provider.getGeneratedRpcMethods();
- for (RpcMethod rpcMethod : methods) {
- methodMap.put(
- rpcMethod.getInterfaceName() + "."
- + rpcMethod.getMethodName(), rpcMethod);
- }
- }
-
/**
* Perform server to client RPC invocation.
*
@@ -63,24 +49,25 @@ public class RpcManager {
*/
public void applyInvocation(MethodInvocation invocation,
ServerConnector connector) {
- String signature = getSignature(invocation);
+ Method method = getMethod(invocation);
- RpcMethod rpcMethod = getRpcMethod(signature);
Collection<ClientRpc> implementations = connector
.getRpcImplementations(invocation.getInterfaceName());
- for (ClientRpc clientRpc : implementations) {
- rpcMethod.applyInvocation(clientRpc, invocation.getParameters());
+ try {
+ for (ClientRpc clientRpc : implementations) {
+ method.invoke(clientRpc, invocation.getParameters());
+ }
+ } catch (NoDataException e) {
+ throw new IllegalStateException("There is no information about "
+ + method.getSignature()
+ + ". Did you remember to compile the right widgetset?", e);
}
}
- private RpcMethod getRpcMethod(String signature) {
- RpcMethod rpcMethod = methodMap.get(signature);
- if (rpcMethod == null) {
- throw new IllegalStateException("There is no information about "
- + signature
- + ". Did you remember to compile the right widgetset?");
- }
- return rpcMethod;
+ private Method getMethod(MethodInvocation invocation) {
+ Type type = new Type(invocation.getInterfaceName(), null);
+ Method method = type.getMethod(invocation.getMethodName());
+ return method;
}
private static String getSignature(MethodInvocation invocation) {
@@ -88,7 +75,15 @@ public class RpcManager {
}
public Type[] getParameterTypes(MethodInvocation invocation) {
- return getRpcMethod(getSignature(invocation)).getParameterTypes();
+ Method method = getMethod(invocation);
+ Type[] parameterTypes = method.getParameterTypes();
+ if (parameterTypes == null) {
+ throw new IllegalStateException("There is no information about "
+ + method.getSignature()
+ + ". Did you remember to compile the right widgetset?");
+
+ }
+ return parameterTypes;
}
public void parseAndApplyInvocation(JSONArray rpcCall,
diff --git a/client/src/com/vaadin/terminal/gwt/client/communication/RpcMethod.java b/client/src/com/vaadin/terminal/gwt/client/communication/RpcMethod.java
deleted file mode 100644
index 1759fbb97f..0000000000
--- a/client/src/com/vaadin/terminal/gwt/client/communication/RpcMethod.java
+++ /dev/null
@@ -1,47 +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.ClientRpc;
-import com.vaadin.terminal.gwt.client.metadata.Type;
-
-public abstract class RpcMethod {
- private String interfaceName;
- private String methodName;
- private Type[] parameterTypes;
-
- public RpcMethod(String interfaceName, String methodName,
- Type... parameterTypes) {
- this.interfaceName = interfaceName;
- this.methodName = methodName;
- this.parameterTypes = parameterTypes;
- }
-
- public String getInterfaceName() {
- return interfaceName;
- }
-
- public String getMethodName() {
- return methodName;
- }
-
- public Type[] getParameterTypes() {
- return parameterTypes;
- }
-
- public abstract void applyInvocation(ClientRpc target, Object... parameters);
-
-}
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 f164bc4bcf..588e736da3 100644
--- a/client/src/com/vaadin/terminal/gwt/client/metadata/Method.java
+++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Method.java
@@ -22,11 +22,11 @@ public class Method {
return name;
}
- public Type getReturnType() {
+ public Type getReturnType() throws NoDataException {
return TypeDataStore.getReturnType(this);
}
- public void invoke(Object target, Object... params) {
+ public void invoke(Object target, Object... params) throws NoDataException {
TypeDataStore.getInvoker(this).invoke(target, params);
}
@@ -47,8 +47,17 @@ public class Method {
}
@Override
+ public String toString() {
+ return getSignature();
+ }
+
+ @Override
public int hashCode() {
return getSignature().hashCode();
}
+ public Type[] getParameterTypes() {
+ return TypeDataStore.getParamTypes(this);
+ }
+
}
diff --git a/client/src/com/vaadin/terminal/gwt/client/communication/GeneratedRpcMethodProvider.java b/client/src/com/vaadin/terminal/gwt/client/metadata/NoDataException.java
index e865dbc1b1..717b92edaf 100644
--- a/client/src/com/vaadin/terminal/gwt/client/communication/GeneratedRpcMethodProvider.java
+++ b/client/src/com/vaadin/terminal/gwt/client/metadata/NoDataException.java
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2011 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -13,20 +13,13 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.vaadin.terminal.gwt.client.communication;
-import java.util.Collection;
+package com.vaadin.terminal.gwt.client.metadata;
-/**
- * Provides runtime data about client side RPC calls received from the server to
- * the client-side code.
- *
- * A GWT generator is used to create an implementation of this class at
- * run-time.
- *
- * @since 7.0
- */
-public interface GeneratedRpcMethodProvider {
+public class NoDataException extends Exception {
+
+ public NoDataException(String message) {
+ super(message);
+ }
- public Collection<RpcMethod> getGeneratedRpcMethods();
}
diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java b/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java
index 5f2b1ffb41..30d864a43f 100644
--- a/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java
+++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java
@@ -13,7 +13,7 @@ public class Property {
this.name = name;
}
- public Object getValue(Object bean) {
+ public Object getValue(Object bean) throws NoDataException {
return TypeDataStore.getGetter(this).invoke(bean, null);
}
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 4fab296441..dfd504983c 100644
--- a/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java
+++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Type.java
@@ -25,7 +25,7 @@ public class Type {
return parameterTypes;
}
- public Object createInstance() {
+ public Object createInstance() throws NoDataException {
Invoker invoker = TypeDataStore.getConstructor(this);
return invoker.invoke(null, null);
}
@@ -40,7 +40,7 @@ public class Type {
public String getSignature() {
String string = name;
- if (parameterTypes != null) {
+ if (parameterTypes != null && parameterTypes.length != 0) {
string += '<';
for (int i = 0; i < parameterTypes.length; i++) {
if (i != 0) {
diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeData.java b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeData.java
index 6ee0b4ede0..ec2a8f191c 100644
--- a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeData.java
+++ b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeData.java
@@ -10,11 +10,11 @@ public class TypeData {
return TypeDataStore.getType(type);
}
- public static Type getType(String identifier) {
- return TypeDataStore.getType(getClass(identifier));
+ public static Class<?> getClass(String identifier) throws NoDataException {
+ return TypeDataStore.getClass(identifier);
}
- public static Class<?> getClass(String identifier) {
- return TypeDataStore.getClass(identifier);
+ public static boolean hasIdentifier(String identifier) {
+ return TypeDataStore.hasIdentifier(identifier);
}
}
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 4b224721e6..4b99250465 100644
--- a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java
+++ b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java
@@ -14,6 +14,7 @@ public class TypeDataStore {
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[]>();
private final Map<Property, Invoker> getters = new HashMap<Property, Invoker>();
private final Map<Property, String> delegateToWidget = new HashMap<Property, String>();
@@ -26,28 +27,55 @@ public class TypeDataStore {
identifiers.put(identifier, type);
}
- public static Class<?> getClass(String identifier) {
- return get().identifiers.get(identifier);
+ public static Class<?> getClass(String identifier) throws NoDataException {
+ Class<?> class1 = get().identifiers.get(identifier);
+ if (class1 == null) {
+ throw new NoDataException("There is not class for identifier "
+ + identifier);
+ }
+ return class1;
}
public static Type getType(Class<?> clazz) {
return new Type(clazz);
}
- public static Type getReturnType(Method method) {
- return get().returnTypes.get(method);
+ public static Type getReturnType(Method method) throws NoDataException {
+ Type type = get().returnTypes.get(method);
+ if (type == null) {
+ throw new NoDataException("There is return type for "
+ + method.getSignature());
+ }
+ return type;
}
- public static Invoker getInvoker(Method method) {
- return get().invokers.get(method);
+ public static Invoker getInvoker(Method method) throws NoDataException {
+ Invoker invoker = get().invokers.get(method);
+ if (invoker == null) {
+ throw new NoDataException("There is invoker for "
+ + method.getSignature());
+ }
+ return invoker;
}
- public static Invoker getConstructor(Type type) {
- return get().invokers.get(new Method(type, CONSTRUCTOR_NAME));
+ public static Invoker getConstructor(Type type) throws NoDataException {
+ Invoker invoker = get().invokers
+ .get(new Method(type, CONSTRUCTOR_NAME));
+ if (invoker == null) {
+ throw new NoDataException("There is constructor for "
+ + type.getSignature());
+ }
+ return invoker;
}
- public static Invoker getGetter(Property property) {
- return get().getters.get(property);
+ public static Invoker getGetter(Property property) throws NoDataException {
+ Invoker getter = get().getters.get(property);
+ if (getter == null) {
+ throw new NoDataException("There is getter for "
+ + property.getSignature());
+ }
+
+ return getter;
}
public static String getDelegateToWidget(Property property) {
@@ -59,6 +87,23 @@ public class TypeDataStore {
}
public void setConstructor(Class<?> type, Invoker constructor) {
- invokers.put(new Method(getType(type), CONSTRUCTOR_NAME), constructor);
+ setInvoker(type, CONSTRUCTOR_NAME, constructor);
+ }
+
+ public void setInvoker(Class<?> type, String methodName, Invoker invoker) {
+ invokers.put(new Method(getType(type), methodName), invoker);
+ }
+
+ public static Type[] getParamTypes(Method method) {
+ return get().paramTypes.get(method);
+ }
+
+ public void setParamTypes(Class<?> type, String methodName,
+ Type[] paramTypes) {
+ this.paramTypes.put(new Method(getType(type), methodName), paramTypes);
+ }
+
+ public static boolean hasIdentifier(String identifier) {
+ return get().identifiers.containsKey(identifier);
}
}
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java
index 4f14ee550b..faded22260 100644
--- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java
@@ -37,6 +37,7 @@ import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
+import com.vaadin.terminal.gwt.client.metadata.NoDataException;
import com.vaadin.terminal.gwt.client.metadata.Type;
import com.vaadin.terminal.gwt.client.metadata.TypeData;
import com.vaadin.terminal.gwt.client.ui.datefield.PopupDateFieldConnector;
@@ -80,9 +81,17 @@ public abstract class AbstractComponentConnector extends AbstractConnector
*/
protected Widget createWidget() {
Type type = TypeData.getType(getClass());
- Type widgetType = type.getMethod("getWidget").getReturnType();
- Object instance = widgetType.createInstance();
- return (Widget) instance;
+ try {
+ Type widgetType = type.getMethod("getWidget").getReturnType();
+ Object instance = widgetType.createInstance();
+ return (Widget) instance;
+ } catch (NoDataException e) {
+ throw new IllegalStateException(
+ "There is no information about the widget for "
+ + Util.getSimpleName(this)
+ + ". Did you remember to compile the right widgetset?",
+ e);
+ }
}
/**
diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java
index 9efa7bad0d..b861ade0bf 100644
--- a/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java
+++ b/client/src/com/vaadin/terminal/gwt/client/ui/AbstractConnector.java
@@ -33,6 +33,7 @@ import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.communication.StateChangeEvent.StateChangeHandler;
+import com.vaadin.terminal.gwt.client.metadata.NoDataException;
import com.vaadin.terminal.gwt.client.metadata.Type;
import com.vaadin.terminal.gwt.client.metadata.TypeData;
@@ -268,9 +269,19 @@ public abstract class AbstractConnector implements ServerConnector,
*/
protected SharedState createState() {
Type connectorType = TypeData.getType(getClass());
- Type stateType = connectorType.getMethod("getState").getReturnType();
- Object stateInstance = stateType.createInstance();
- return (SharedState) stateInstance;
+ try {
+ Type stateType = connectorType.getMethod("getState")
+ .getReturnType();
+ Object stateInstance = stateType.createInstance();
+ return (SharedState) stateInstance;
+ } catch (NoDataException e) {
+ throw new IllegalStateException(
+ "There is no information about the state for "
+ + Util.getSimpleName(this)
+ + ". Did you remember to compile the right widgetset?",
+ e);
+ }
+
}
@Override