summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/terminal
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-22 21:12:47 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-22 21:12:47 +0300
commit050bec8a443b916e45adf4bf7ea91241690d37e2 (patch)
treef2c338ec73f5dfb0d1cb4607a5e9529ba0f89c04 /server/src/com/vaadin/terminal
parent38358ae25543433f8cc381101bc340adc7e5c67f (diff)
downloadvaadin-framework-050bec8a443b916e45adf4bf7ea91241690d37e2.tar.gz
vaadin-framework-050bec8a443b916e45adf4bf7ea91241690d37e2.zip
Make the (server-side) getState method protected (#9315)
Diffstat (limited to 'server/src/com/vaadin/terminal')
-rw-r--r--server/src/com/vaadin/terminal/AbstractClientConnector.java11
-rw-r--r--server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java2
-rw-r--r--server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java83
-rw-r--r--server/src/com/vaadin/terminal/gwt/server/ClientConnector.java14
-rw-r--r--server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java14
5 files changed, 74 insertions, 50 deletions
diff --git a/server/src/com/vaadin/terminal/AbstractClientConnector.java b/server/src/com/vaadin/terminal/AbstractClientConnector.java
index bc1cd2af1a..a8da553a62 100644
--- a/server/src/com/vaadin/terminal/AbstractClientConnector.java
+++ b/server/src/com/vaadin/terminal/AbstractClientConnector.java
@@ -31,9 +31,12 @@ import java.util.NoSuchElementException;
import java.util.logging.Logger;
import com.vaadin.Application;
+import com.vaadin.external.json.JSONException;
+import com.vaadin.external.json.JSONObject;
import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.ServerRpc;
import com.vaadin.shared.communication.SharedState;
+import com.vaadin.terminal.gwt.server.AbstractCommunicationManager;
import com.vaadin.terminal.gwt.server.ClientConnector;
import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
import com.vaadin.terminal.gwt.server.RpcManager;
@@ -137,14 +140,18 @@ public abstract class AbstractClientConnector implements ClientConnector {
registerRpc(implementation, type);
}
- @Override
- public SharedState getState() {
+ protected SharedState getState() {
if (null == sharedState) {
sharedState = createState();
}
return sharedState;
}
+ @Override
+ public JSONObject encodeState() throws JSONException {
+ return AbstractCommunicationManager.encodeState(this, getState());
+ }
+
/**
* Creates the shared state bean to be used in server to client
* communication.
diff --git a/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java b/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java
index aae71640aa..1def6df697 100644
--- a/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java
+++ b/server/src/com/vaadin/terminal/AbstractJavaScriptExtension.java
@@ -166,7 +166,7 @@ public abstract class AbstractJavaScriptExtension extends AbstractExtension {
}
@Override
- public JavaScriptExtensionState getState() {
+ protected JavaScriptExtensionState getState() {
return (JavaScriptExtensionState) super.getState();
}
}
diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index 99376ffd1f..7ea4a7d097 100644
--- a/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/server/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -880,49 +880,19 @@ public abstract class AbstractCommunicationManager implements Serializable {
// processing.
JSONObject sharedStates = new JSONObject();
for (ClientConnector connector : dirtyVisibleConnectors) {
- SharedState state = connector.getState();
- if (null != state) {
- // encode and send shared state
- try {
- Class<? extends SharedState> stateType = connector
- .getStateType();
- Object diffState = rootConnectorTracker
- .getDiffState(connector);
- if (diffState == null) {
- diffState = new JSONObject();
- // Use an empty state object as reference for full
- // repaints
- boolean emptyInitialState = JavaScriptConnectorState.class
- .isAssignableFrom(stateType);
- if (!emptyInitialState) {
- try {
- SharedState referenceState = stateType
- .newInstance();
- diffState = JsonCodec.encode(referenceState,
- null, stateType,
- root.getConnectorTracker());
- } catch (Exception e) {
- getLogger().log(
- Level.WARNING,
- "Error creating reference object for state of type "
- + stateType.getName());
- }
- }
- rootConnectorTracker.setDiffState(connector, diffState);
- }
- JSONObject stateJson = (JSONObject) JsonCodec.encode(state,
- diffState, stateType, root.getConnectorTracker());
+ // encode and send shared state
+ try {
+ JSONObject stateJson = connector.encodeState();
- if (stateJson.length() != 0) {
- sharedStates.put(connector.getConnectorId(), stateJson);
- }
- } catch (JSONException e) {
- throw new PaintException(
- "Failed to serialize shared state for connector "
- + connector.getClass().getName() + " ("
- + connector.getConnectorId() + "): "
- + e.getMessage(), e);
+ if (stateJson != null && stateJson.length() != 0) {
+ sharedStates.put(connector.getConnectorId(), stateJson);
}
+ } catch (JSONException e) {
+ throw new PaintException(
+ "Failed to serialize shared state for connector "
+ + connector.getClass().getName() + " ("
+ + connector.getConnectorId() + "): "
+ + e.getMessage(), e);
}
}
outWriter.print("\"state\":");
@@ -1273,6 +1243,37 @@ public abstract class AbstractCommunicationManager implements Serializable {
writePerformanceData(outWriter);
}
+ public static JSONObject encodeState(ClientConnector connector,
+ SharedState state) throws JSONException {
+ Root root = connector.getRoot();
+ ConnectorTracker connectorTracker = root.getConnectorTracker();
+ Class<? extends SharedState> stateType = connector.getStateType();
+ Object diffState = connectorTracker.getDiffState(connector);
+ if (diffState == null) {
+ diffState = new JSONObject();
+ // Use an empty state object as reference for full
+ // repaints
+ boolean emptyInitialState = JavaScriptConnectorState.class
+ .isAssignableFrom(stateType);
+ if (!emptyInitialState) {
+ try {
+ SharedState referenceState = stateType.newInstance();
+ diffState = JsonCodec.encode(referenceState, null,
+ stateType, root.getConnectorTracker());
+ } catch (Exception e) {
+ getLogger().log(
+ Level.WARNING,
+ "Error creating reference object for state of type "
+ + stateType.getName());
+ }
+ }
+ connectorTracker.setDiffState(connector, diffState);
+ }
+ JSONObject stateJson = (JSONObject) JsonCodec.encode(state, diffState,
+ stateType, root.getConnectorTracker());
+ return stateJson;
+ }
+
/**
* Resolves a resource URI, registering the URI with this
* {@code AbstractCommunicationManager} if needed and returns a fully
diff --git a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java
index c9fe2563f9..87524fe28f 100644
--- a/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java
+++ b/server/src/com/vaadin/terminal/gwt/server/ClientConnector.java
@@ -18,6 +18,8 @@ package com.vaadin.terminal.gwt.server;
import java.util.Collection;
import java.util.List;
+import com.vaadin.external.json.JSONException;
+import com.vaadin.external.json.JSONObject;
import com.vaadin.shared.Connector;
import com.vaadin.shared.communication.SharedState;
import com.vaadin.terminal.AbstractClientConnector;
@@ -177,4 +179,16 @@ public interface ClientConnector extends Connector, RpcTarget {
* @since 7.0
*/
public void beforeClientResponse(boolean initial);
+
+ /**
+ * Called by the framework to encode the state to a JSONObject. This is
+ * typically done by calling the static method
+ * {@link AbstractCommunicationManager#encodeState(ClientConnector, SharedState)}
+ * .
+ *
+ * @return a JSON object with the encoded connector state
+ * @throws JSONException
+ * if the state can not be encoded
+ */
+ public JSONObject encodeState() throws JSONException;
}
diff --git a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
index 56d5ed1393..981d2569d1 100644
--- a/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
+++ b/server/src/com/vaadin/terminal/gwt/server/DragAndDropService.java
@@ -31,6 +31,8 @@ import com.vaadin.event.dd.DropTarget;
import com.vaadin.event.dd.TargetDetails;
import com.vaadin.event.dd.TargetDetailsImpl;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
+import com.vaadin.external.json.JSONException;
+import com.vaadin.external.json.JSONObject;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.communication.SharedState;
import com.vaadin.shared.ui.dd.DragEventType;
@@ -235,12 +237,6 @@ public class DragAndDropService implements VariableOwner, ClientConnector {
}
@Override
- public SharedState getState() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
public String getConnectorId() {
return ApplicationConstants.DRAG_AND_DROP_CONNECTOR_ID;
}
@@ -327,4 +323,10 @@ public class DragAndDropService implements VariableOwner, ClientConnector {
public void beforeClientResponse(boolean initial) {
// Nothing to do
}
+
+ @Override
+ public JSONObject encodeState() throws JSONException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}