summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java')
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java69
1 files changed, 64 insertions, 5 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index 7cad8e3a33..c65b8947d6 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -25,6 +25,7 @@ import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.text.StringCharacterIterator;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
@@ -46,6 +47,8 @@ import com.vaadin.Application;
import com.vaadin.Application.SystemMessages;
import com.vaadin.RootRequiresMoreInformationException;
import com.vaadin.Version;
+import com.vaadin.annotations.JavaScript;
+import com.vaadin.annotations.StyleSheet;
import com.vaadin.external.json.JSONArray;
import com.vaadin.external.json.JSONException;
import com.vaadin.external.json.JSONObject;
@@ -497,10 +500,11 @@ public abstract class AbstractCommunicationManager implements Serializable {
* found
* @throws IOException
* @throws InvalidUIDLSecurityKeyException
+ * @throws JSONException
*/
public void handleUidlRequest(WrappedRequest request,
WrappedResponse response, Callback callback, Root root)
- throws IOException, InvalidUIDLSecurityKeyException {
+ throws IOException, InvalidUIDLSecurityKeyException, JSONException {
checkWidgetsetVersion(request);
requestThemeName = request.getParameter("theme");
@@ -696,11 +700,12 @@ public abstract class AbstractCommunicationManager implements Serializable {
* @param analyzeLayouts
* @throws PaintException
* @throws IOException
+ * @throws JSONException
*/
private void paintAfterVariableChanges(WrappedRequest request,
WrappedResponse response, Callback callback, boolean repaintAll,
final PrintWriter outWriter, Root root, boolean analyzeLayouts)
- throws PaintException, IOException {
+ throws PaintException, IOException, JSONException {
// Removes application if it has stopped during variable changes
if (!application.isRunning()) {
@@ -764,7 +769,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
@SuppressWarnings("unchecked")
public void writeUidlResponse(WrappedRequest request, boolean repaintAll,
final PrintWriter outWriter, Root root, boolean analyzeLayouts)
- throws PaintException {
+ throws PaintException, JSONException {
ArrayList<ClientConnector> dirtyVisibleConnectors = new ArrayList<ClientConnector>();
Application application = root.getApplication();
// Paints components
@@ -1095,10 +1100,14 @@ public abstract class AbstractCommunicationManager implements Serializable {
boolean typeMappingsOpen = false;
ClientCache clientCache = getClientCache(root);
+ List<Class<? extends ClientConnector>> newConnectorTypes = new ArrayList<Class<? extends ClientConnector>>();
+
for (Class<? extends ClientConnector> class1 : usedClientConnectors) {
if (clientCache.cache(class1)) {
// client does not know the mapping key for this type, send
// mapping to client
+ newConnectorTypes.add(class1);
+
if (!typeMappingsOpen) {
typeMappingsOpen = true;
outWriter.print(", \"typeMappings\" : { ");
@@ -1142,6 +1151,54 @@ public abstract class AbstractCommunicationManager implements Serializable {
}
}
+ /*
+ * Ensure super classes come before sub classes to get script dependency
+ * order right. Sub class @JavaScript might assume that @JavaScript
+ * defined by super class is already loaded.
+ */
+ Collections.sort(newConnectorTypes, new Comparator<Class<?>>() {
+ public int compare(Class<?> o1, Class<?> o2) {
+ // TODO optimize using Class.isAssignableFrom?
+ return hierarchyDepth(o1) - hierarchyDepth(o2);
+ }
+
+ private int hierarchyDepth(Class<?> type) {
+ if (type == Object.class) {
+ return 0;
+ } else {
+ return hierarchyDepth(type.getSuperclass()) + 1;
+ }
+ }
+ });
+
+ List<String> scriptDependencies = new ArrayList<String>();
+ List<String> styleDependencies = new ArrayList<String>();
+
+ for (Class<? extends ClientConnector> class1 : newConnectorTypes) {
+ JavaScript jsAnnotation = class1.getAnnotation(JavaScript.class);
+ if (jsAnnotation != null) {
+ scriptDependencies.addAll(Arrays.asList(jsAnnotation.value()));
+ }
+
+ StyleSheet styleAnnotation = class1.getAnnotation(StyleSheet.class);
+ if (styleAnnotation != null) {
+ styleDependencies
+ .addAll(Arrays.asList(styleAnnotation.value()));
+ }
+ }
+
+ // Include script dependencies in output if there are any
+ if (!scriptDependencies.isEmpty()) {
+ outWriter.print(", \"scriptDependencies\": "
+ + new JSONArray(scriptDependencies).toString());
+ }
+
+ // Include style dependencies in output if there are any
+ if (!styleDependencies.isEmpty()) {
+ outWriter.print(", \"styleDependencies\": "
+ + new JSONArray(styleDependencies).toString());
+ }
+
// add any pending locale definitions requested by the client
printLocaleDeclarations(outWriter);
@@ -1380,7 +1437,7 @@ public abstract class AbstractCommunicationManager implements Serializable {
private boolean handleVariables(WrappedRequest request,
WrappedResponse response, Callback callback,
Application application2, Root root) throws IOException,
- InvalidUIDLSecurityKeyException {
+ InvalidUIDLSecurityKeyException, JSONException {
boolean success = true;
String changes = getRequestPayload(request);
@@ -2256,9 +2313,11 @@ public abstract class AbstractCommunicationManager implements Serializable {
* @return a string with the initial UIDL message
* @throws PaintException
* if an exception occurs while painting
+ * @throws JSONException
+ * if an exception occurs while encoding output
*/
protected String getInitialUIDL(WrappedRequest request, Root root)
- throws PaintException {
+ throws PaintException, JSONException {
// TODO maybe unify writeUidlResponse()?
StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter(sWriter);