summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/terminal/AbstractClientConnector.java
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-23 10:46:17 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-23 10:46:17 +0300
commit8606feb8596ed8f6cd3ed41160706b692f6f4679 (patch)
tree08bbf9aa04c74168ef075dce3de5a50a166575e5 /server/src/com/vaadin/terminal/AbstractClientConnector.java
parentfad5360a76b9f4f93b99f9775ad01997899859ab (diff)
downloadvaadin-framework-8606feb8596ed8f6cd3ed41160706b692f6f4679.tar.gz
vaadin-framework-8606feb8596ed8f6cd3ed41160706b692f6f4679.zip
Make getStateType() find getState methods in superclases (#9315)
Also cache the result as the finding logic could be quite expensive with multiple exceptions thrown and caught.
Diffstat (limited to 'server/src/com/vaadin/terminal/AbstractClientConnector.java')
-rw-r--r--server/src/com/vaadin/terminal/AbstractClientConnector.java39
1 files changed, 24 insertions, 15 deletions
diff --git a/server/src/com/vaadin/terminal/AbstractClientConnector.java b/server/src/com/vaadin/terminal/AbstractClientConnector.java
index 1025297a4f..53b3bb1c9d 100644
--- a/server/src/com/vaadin/terminal/AbstractClientConnector.java
+++ b/server/src/com/vaadin/terminal/AbstractClientConnector.java
@@ -71,6 +71,8 @@ public abstract class AbstractClientConnector implements ClientConnector {
*/
private SharedState sharedState;
+ private Class<? extends SharedState> stateType;
+
/**
* Pending RPC method invocations to be sent.
*/
@@ -179,26 +181,33 @@ public abstract class AbstractClientConnector implements ClientConnector {
}
}
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.terminal.gwt.server.ClientConnector#getStateType()
- */
@Override
public Class<? extends SharedState> getStateType() {
+ // Lazy load because finding type can be expensive because of the
+ // exceptions flying around
+ if (stateType == null) {
+ stateType = findStateType();
+ }
+
+ return stateType;
+ }
+
+ private Class<? extends SharedState> findStateType() {
try {
- Method m = null;
Class<?> class1 = getClass();
- while (m == null && class1 != null) {
- m = class1.getDeclaredMethod("getState", (Class[]) null);
- class1 = class1.getSuperclass();
- }
- if (m == null) {
- throw new NoSuchMethodException(getClass().getCanonicalName()
- + ".getState()");
+ while (class1 != null) {
+ try {
+ Method m = class1.getDeclaredMethod("getState",
+ (Class[]) null);
+ Class<?> type = m.getReturnType();
+ return type.asSubclass(SharedState.class);
+ } catch (NoSuchMethodException nsme) {
+ // Try in superclass instead
+ class1 = class1.getSuperclass();
+ }
}
- Class<?> type = m.getReturnType();
- return type.asSubclass(SharedState.class);
+ throw new NoSuchMethodException(getClass().getCanonicalName()
+ + ".getState()");
} catch (Exception e) {
throw new RuntimeException("Error finding state type for "
+ getClass().getName(), e);