You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicationConnection.java 99KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585
  1. /*
  2. * Copyright 2011 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.terminal.gwt.client;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.Date;
  20. import java.util.HashMap;
  21. import java.util.HashSet;
  22. import java.util.Iterator;
  23. import java.util.LinkedHashMap;
  24. import java.util.LinkedList;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.Set;
  28. import com.google.gwt.core.client.Duration;
  29. import com.google.gwt.core.client.GWT;
  30. import com.google.gwt.core.client.JavaScriptObject;
  31. import com.google.gwt.core.client.JsArray;
  32. import com.google.gwt.core.client.JsArrayString;
  33. import com.google.gwt.core.client.Scheduler;
  34. import com.google.gwt.core.client.Scheduler.ScheduledCommand;
  35. import com.google.gwt.http.client.Request;
  36. import com.google.gwt.http.client.RequestBuilder;
  37. import com.google.gwt.http.client.RequestCallback;
  38. import com.google.gwt.http.client.RequestException;
  39. import com.google.gwt.http.client.Response;
  40. import com.google.gwt.http.client.URL;
  41. import com.google.gwt.json.client.JSONArray;
  42. import com.google.gwt.json.client.JSONObject;
  43. import com.google.gwt.json.client.JSONString;
  44. import com.google.gwt.regexp.shared.MatchResult;
  45. import com.google.gwt.regexp.shared.RegExp;
  46. import com.google.gwt.user.client.Command;
  47. import com.google.gwt.user.client.DOM;
  48. import com.google.gwt.user.client.Element;
  49. import com.google.gwt.user.client.Timer;
  50. import com.google.gwt.user.client.ui.HasWidgets;
  51. import com.google.gwt.user.client.ui.Widget;
  52. import com.vaadin.shared.ApplicationConstants;
  53. import com.vaadin.shared.ComponentState;
  54. import com.vaadin.shared.Version;
  55. import com.vaadin.shared.communication.LegacyChangeVariablesInvocation;
  56. import com.vaadin.shared.communication.MethodInvocation;
  57. import com.vaadin.shared.communication.SharedState;
  58. import com.vaadin.terminal.gwt.client.ApplicationConfiguration.ErrorMessage;
  59. import com.vaadin.terminal.gwt.client.ResourceLoader.ResourceLoadEvent;
  60. import com.vaadin.terminal.gwt.client.ResourceLoader.ResourceLoadListener;
  61. import com.vaadin.terminal.gwt.client.communication.HasJavaScriptConnectorHelper;
  62. import com.vaadin.terminal.gwt.client.communication.JsonDecoder;
  63. import com.vaadin.terminal.gwt.client.communication.JsonEncoder;
  64. import com.vaadin.terminal.gwt.client.communication.RpcManager;
  65. import com.vaadin.terminal.gwt.client.communication.SerializerMap;
  66. import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
  67. import com.vaadin.terminal.gwt.client.extensions.AbstractExtensionConnector;
  68. import com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader;
  69. import com.vaadin.terminal.gwt.client.metadata.Type;
  70. import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
  71. import com.vaadin.terminal.gwt.client.ui.VContextMenu;
  72. import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager;
  73. import com.vaadin.terminal.gwt.client.ui.notification.VNotification;
  74. import com.vaadin.terminal.gwt.client.ui.notification.VNotification.HideEvent;
  75. import com.vaadin.terminal.gwt.client.ui.root.RootConnector;
  76. import com.vaadin.terminal.gwt.client.ui.window.WindowConnector;
  77. /**
  78. * This is the client side communication "engine", managing client-server
  79. * communication with its server side counterpart
  80. * com.vaadin.terminal.gwt.server.AbstractCommunicationManager.
  81. *
  82. * Client-side connectors receive updates from the corresponding server-side
  83. * connector (typically component) as state updates or RPC calls. The connector
  84. * has the possibility to communicate back with its server side counter part
  85. * through RPC calls.
  86. *
  87. * TODO document better
  88. *
  89. * Entry point classes (widgetsets) define <code>onModuleLoad()</code>.
  90. */
  91. public class ApplicationConnection {
  92. public static final String MODIFIED_CLASSNAME = "v-modified";
  93. public static final String DISABLED_CLASSNAME = "v-disabled";
  94. public static final String REQUIRED_CLASSNAME_EXT = "-required";
  95. public static final String ERROR_CLASSNAME_EXT = "-error";
  96. public static final char VAR_BURST_SEPARATOR = '\u001d';
  97. public static final char VAR_ESCAPE_CHARACTER = '\u001b';
  98. private static SerializerMap serializerMap;
  99. /**
  100. * A string that, if found in a non-JSON response to a UIDL request, will
  101. * cause the browser to refresh the page. If followed by a colon, optional
  102. * whitespace, and a URI, causes the browser to synchronously load the URI.
  103. *
  104. * <p>
  105. * This allows, for instance, a servlet filter to redirect the application
  106. * to a custom login page when the session expires. For example:
  107. * </p>
  108. *
  109. * <pre>
  110. * if (sessionExpired) {
  111. * response.setHeader(&quot;Content-Type&quot;, &quot;text/html&quot;);
  112. * response.getWriter().write(
  113. * myLoginPageHtml + &quot;&lt;!-- Vaadin-Refresh: &quot;
  114. * + request.getContextPath() + &quot; --&gt;&quot;);
  115. * }
  116. * </pre>
  117. */
  118. public static final String UIDL_REFRESH_TOKEN = "Vaadin-Refresh";
  119. // will hold the UIDL security key (for XSS protection) once received
  120. private String uidlSecurityKey = "init";
  121. private final HashMap<String, String> resourcesMap = new HashMap<String, String>();
  122. /**
  123. * The pending method invocations that will be send to the server by
  124. * {@link #sendPendingCommand}. The key is defined differently based on
  125. * whether the method invocation is enqueued with lastonly. With lastonly
  126. * enabled, the method signature ( {@link MethodInvocation#getLastonlyTag()}
  127. * ) is used as the key to make enable removing a previously enqueued
  128. * invocation. Without lastonly, an incremental id based on
  129. * {@link #lastInvocationTag} is used to get unique values.
  130. */
  131. private LinkedHashMap<String, MethodInvocation> pendingInvocations = new LinkedHashMap<String, MethodInvocation>();
  132. private int lastInvocationTag = 0;
  133. private WidgetSet widgetSet;
  134. private VContextMenu contextMenu = null;
  135. private Timer loadTimer;
  136. private Timer loadTimer2;
  137. private Timer loadTimer3;
  138. private Element loadElement;
  139. private final RootConnector rootConnector;
  140. protected boolean applicationRunning = false;
  141. private boolean hasActiveRequest = false;
  142. protected boolean cssLoaded = false;
  143. /** Parameters for this application connection loaded from the web-page */
  144. private ApplicationConfiguration configuration;
  145. /** List of pending variable change bursts that must be submitted in order */
  146. private final ArrayList<LinkedHashMap<String, MethodInvocation>> pendingBursts = new ArrayList<LinkedHashMap<String, MethodInvocation>>();
  147. /** Timer for automatic refirect to SessionExpiredURL */
  148. private Timer redirectTimer;
  149. /** redirectTimer scheduling interval in seconds */
  150. private int sessionExpirationInterval;
  151. private ArrayList<Widget> componentCaptionSizeChanges = new ArrayList<Widget>();
  152. private Date requestStartTime;
  153. private boolean validatingLayouts = false;
  154. private Set<ComponentConnector> zeroWidthComponents = null;
  155. private Set<ComponentConnector> zeroHeightComponents = null;
  156. private final LayoutManager layoutManager;
  157. private final RpcManager rpcManager;
  158. public static class MultiStepDuration extends Duration {
  159. private int previousStep = elapsedMillis();
  160. public void logDuration(String message) {
  161. logDuration(message, 0);
  162. }
  163. public void logDuration(String message, int minDuration) {
  164. int currentTime = elapsedMillis();
  165. int stepDuration = currentTime - previousStep;
  166. if (stepDuration >= minDuration) {
  167. VConsole.log(message + ": " + stepDuration + " ms");
  168. }
  169. previousStep = currentTime;
  170. }
  171. }
  172. public ApplicationConnection() {
  173. rootConnector = GWT.create(RootConnector.class);
  174. rpcManager = GWT.create(RpcManager.class);
  175. layoutManager = GWT.create(LayoutManager.class);
  176. layoutManager.setConnection(this);
  177. serializerMap = GWT.create(SerializerMap.class);
  178. }
  179. public void init(WidgetSet widgetSet, ApplicationConfiguration cnf) {
  180. VConsole.log("Starting application " + cnf.getRootPanelId());
  181. VConsole.log("Vaadin application servlet version: "
  182. + cnf.getServletVersion());
  183. VConsole.log("Application version: " + cnf.getApplicationVersion());
  184. if (!cnf.getServletVersion().equals(Version.getFullVersion())) {
  185. VConsole.error("Warning: your widget set seems to be built with a different "
  186. + "version than the one used on server. Unexpected "
  187. + "behavior may occur.");
  188. }
  189. this.widgetSet = widgetSet;
  190. configuration = cnf;
  191. ComponentLocator componentLocator = new ComponentLocator(this);
  192. String appRootPanelName = cnf.getRootPanelId();
  193. // remove the end (window name) of autogenerated rootpanel id
  194. appRootPanelName = appRootPanelName.replaceFirst("-\\d+$", "");
  195. initializeTestbenchHooks(componentLocator, appRootPanelName);
  196. initializeClientHooks();
  197. // Assuming Root data is eagerly loaded
  198. ConnectorBundleLoader.get().loadBundle(
  199. ConnectorBundleLoader.EAGER_BUNDLE_NAME, null);
  200. rootConnector.init(cnf.getRootPanelId(), this);
  201. showLoadingIndicator();
  202. }
  203. /**
  204. * Starts this application. Don't call this method directly - it's called by
  205. * {@link ApplicationConfiguration#startNextApplication()}, which should be
  206. * called once this application has started (first response received) or
  207. * failed to start. This ensures that the applications are started in order,
  208. * to avoid session-id problems.
  209. *
  210. */
  211. public void start() {
  212. String jsonText = configuration.getUIDL();
  213. if (jsonText == null) {
  214. // inital UIDL not in DOM, request later
  215. repaintAll();
  216. } else {
  217. // Update counter so TestBench knows something is still going on
  218. hasActiveRequest = true;
  219. // initial UIDL provided in DOM, continue as if returned by request
  220. handleJSONText(jsonText, -1);
  221. }
  222. }
  223. private native void initializeTestbenchHooks(
  224. ComponentLocator componentLocator, String TTAppId)
  225. /*-{
  226. var ap = this;
  227. var client = {};
  228. client.isActive = $entry(function() {
  229. return ap.@com.vaadin.terminal.gwt.client.ApplicationConnection::hasActiveRequest()()
  230. || ap.@com.vaadin.terminal.gwt.client.ApplicationConnection::isExecutingDeferredCommands()();
  231. });
  232. var vi = ap.@com.vaadin.terminal.gwt.client.ApplicationConnection::getVersionInfo()();
  233. if (vi) {
  234. client.getVersionInfo = function() {
  235. return vi;
  236. }
  237. }
  238. client.getProfilingData = $entry(function() {
  239. var pd = [
  240. ap.@com.vaadin.terminal.gwt.client.ApplicationConnection::lastProcessingTime,
  241. ap.@com.vaadin.terminal.gwt.client.ApplicationConnection::totalProcessingTime
  242. ];
  243. pd = pd.concat(ap.@com.vaadin.terminal.gwt.client.ApplicationConnection::serverTimingInfo);
  244. return pd;
  245. });
  246. client.getElementByPath = $entry(function(id) {
  247. return componentLocator.@com.vaadin.terminal.gwt.client.ComponentLocator::getElementByPath(Ljava/lang/String;)(id);
  248. });
  249. client.getPathForElement = $entry(function(element) {
  250. return componentLocator.@com.vaadin.terminal.gwt.client.ComponentLocator::getPathForElement(Lcom/google/gwt/user/client/Element;)(element);
  251. });
  252. $wnd.vaadin.clients[TTAppId] = client;
  253. }-*/;
  254. /**
  255. * Helper for tt initialization
  256. */
  257. private JavaScriptObject getVersionInfo() {
  258. return configuration.getVersionInfoJSObject();
  259. }
  260. /**
  261. * Publishes a JavaScript API for mash-up applications.
  262. * <ul>
  263. * <li><code>vaadin.forceSync()</code> sends pending variable changes, in
  264. * effect synchronizing the server and client state. This is done for all
  265. * applications on host page.</li>
  266. * <li><code>vaadin.postRequestHooks</code> is a map of functions which gets
  267. * called after each XHR made by vaadin application. Note, that it is
  268. * attaching js functions responsibility to create the variable like this:
  269. *
  270. * <code><pre>
  271. * if(!vaadin.postRequestHooks) {vaadin.postRequestHooks = new Object();}
  272. * postRequestHooks.myHook = function(appId) {
  273. * if(appId == "MyAppOfInterest") {
  274. * // do the staff you need on xhr activity
  275. * }
  276. * }
  277. * </pre></code> First parameter passed to these functions is the identifier
  278. * of Vaadin application that made the request.
  279. * </ul>
  280. *
  281. * TODO make this multi-app aware
  282. */
  283. private native void initializeClientHooks()
  284. /*-{
  285. var app = this;
  286. var oldSync;
  287. if ($wnd.vaadin.forceSync) {
  288. oldSync = $wnd.vaadin.forceSync;
  289. }
  290. $wnd.vaadin.forceSync = $entry(function() {
  291. if (oldSync) {
  292. oldSync();
  293. }
  294. app.@com.vaadin.terminal.gwt.client.ApplicationConnection::sendPendingVariableChanges()();
  295. });
  296. var oldForceLayout;
  297. if ($wnd.vaadin.forceLayout) {
  298. oldForceLayout = $wnd.vaadin.forceLayout;
  299. }
  300. $wnd.vaadin.forceLayout = $entry(function() {
  301. if (oldForceLayout) {
  302. oldForceLayout();
  303. }
  304. app.@com.vaadin.terminal.gwt.client.ApplicationConnection::forceLayout()();
  305. });
  306. }-*/;
  307. /**
  308. * Runs possibly registered client side post request hooks. This is expected
  309. * to be run after each uidl request made by Vaadin application.
  310. *
  311. * @param appId
  312. */
  313. private static native void runPostRequestHooks(String appId)
  314. /*-{
  315. if ($wnd.vaadin.postRequestHooks) {
  316. for ( var hook in $wnd.vaadin.postRequestHooks) {
  317. if (typeof ($wnd.vaadin.postRequestHooks[hook]) == "function") {
  318. try {
  319. $wnd.vaadin.postRequestHooks[hook](appId);
  320. } catch (e) {
  321. }
  322. }
  323. }
  324. }
  325. }-*/;
  326. /**
  327. * If on Liferay and logged in, ask the client side session management
  328. * JavaScript to extend the session duration.
  329. *
  330. * Otherwise, Liferay client side JavaScript will explicitly expire the
  331. * session even though the server side considers the session to be active.
  332. * See ticket #8305 for more information.
  333. */
  334. protected native void extendLiferaySession()
  335. /*-{
  336. if ($wnd.Liferay && $wnd.Liferay.Session) {
  337. $wnd.Liferay.Session.extend();
  338. // if the extend banner is visible, hide it
  339. if ($wnd.Liferay.Session.banner) {
  340. $wnd.Liferay.Session.banner.remove();
  341. }
  342. }
  343. }-*/;
  344. /**
  345. * Get the active Console for writing debug messages. May return an actual
  346. * logging console, or the NullConsole if debugging is not turned on.
  347. *
  348. * @deprecated Developers should use {@link VConsole} since 6.4.5
  349. *
  350. * @return the active Console
  351. */
  352. @Deprecated
  353. public static Console getConsole() {
  354. return VConsole.getImplementation();
  355. }
  356. /**
  357. * Checks if client side is in debug mode. Practically this is invoked by
  358. * adding ?debug parameter to URI.
  359. *
  360. * @deprecated use ApplicationConfiguration isDebugMode instead.
  361. *
  362. * @return true if client side is currently been debugged
  363. */
  364. @Deprecated
  365. public static boolean isDebugMode() {
  366. return ApplicationConfiguration.isDebugMode();
  367. }
  368. /**
  369. * Gets the application base URI. Using this other than as the download
  370. * action URI can cause problems in Portlet 2.0 deployments.
  371. *
  372. * @return application base URI
  373. */
  374. public String getAppUri() {
  375. return configuration.getApplicationUri();
  376. };
  377. /**
  378. * Indicates whether or not there are currently active UIDL requests. Used
  379. * internally to sequence requests properly, seldom needed in Widgets.
  380. *
  381. * @return true if there are active requests
  382. */
  383. public boolean hasActiveRequest() {
  384. return hasActiveRequest;
  385. }
  386. private String getRepaintAllParameters() {
  387. // collect some client side data that will be sent to server on
  388. // initial uidl request
  389. String nativeBootstrapParameters = getNativeBrowserDetailsParameters(getConfiguration()
  390. .getRootPanelId());
  391. // TODO figure out how client and view size could be used better on
  392. // server. screen size can be accessed via Browser object, but other
  393. // values currently only via transaction listener.
  394. String parameters = "repaintAll=1&" + nativeBootstrapParameters;
  395. return parameters;
  396. }
  397. /**
  398. * Gets the browser detail parameters that are sent by the bootstrap
  399. * javascript for two-request initialization.
  400. *
  401. * @param parentElementId
  402. * @return
  403. */
  404. private static native String getNativeBrowserDetailsParameters(
  405. String parentElementId)
  406. /*-{
  407. return $wnd.vaadin.getBrowserDetailsParameters(parentElementId);
  408. }-*/;
  409. protected void repaintAll() {
  410. String repainAllParameters = getRepaintAllParameters();
  411. makeUidlRequest("", repainAllParameters, false);
  412. }
  413. /**
  414. * Requests an analyze of layouts, to find inconsistencies. Exclusively used
  415. * for debugging during development.
  416. */
  417. public void analyzeLayouts() {
  418. String params = getRepaintAllParameters() + "&analyzeLayouts=1";
  419. makeUidlRequest("", params, false);
  420. }
  421. /**
  422. * Sends a request to the server to print details to console that will help
  423. * developer to locate component in the source code.
  424. *
  425. * @param componentConnector
  426. */
  427. void highlightComponent(ComponentConnector componentConnector) {
  428. String params = getRepaintAllParameters() + "&highlightComponent="
  429. + componentConnector.getConnectorId();
  430. makeUidlRequest("", params, false);
  431. }
  432. /**
  433. * Makes an UIDL request to the server.
  434. *
  435. * @param requestData
  436. * Data that is passed to the server.
  437. * @param extraParams
  438. * Parameters that are added as GET parameters to the url.
  439. * Contains key=value pairs joined by & characters or is empty if
  440. * no parameters should be added. Should not start with any
  441. * special character.
  442. * @param forceSync
  443. * true if the request should be synchronous, false otherwise
  444. */
  445. protected void makeUidlRequest(final String requestData,
  446. final String extraParams, final boolean forceSync) {
  447. startRequest();
  448. // Security: double cookie submission pattern
  449. final String payload = uidlSecurityKey + VAR_BURST_SEPARATOR
  450. + requestData;
  451. VConsole.log("Making UIDL Request with params: " + payload);
  452. String uri = translateVaadinUri(ApplicationConstants.APP_PROTOCOL_PREFIX
  453. + ApplicationConstants.UIDL_REQUEST_PATH);
  454. if (extraParams != null && extraParams.length() > 0) {
  455. uri = addGetParameters(uri, extraParams);
  456. }
  457. uri = addGetParameters(uri, ApplicationConstants.ROOT_ID_PARAMETER
  458. + "=" + configuration.getRootId());
  459. doUidlRequest(uri, payload, forceSync);
  460. }
  461. /**
  462. * Sends an asynchronous or synchronous UIDL request to the server using the
  463. * given URI.
  464. *
  465. * @param uri
  466. * The URI to use for the request. May includes GET parameters
  467. * @param payload
  468. * The contents of the request to send
  469. * @param synchronous
  470. * true if the request should be synchronous, false otherwise
  471. */
  472. protected void doUidlRequest(final String uri, final String payload,
  473. final boolean synchronous) {
  474. if (!synchronous) {
  475. RequestCallback requestCallback = new RequestCallback() {
  476. @Override
  477. public void onError(Request request, Throwable exception) {
  478. showCommunicationError(exception.getMessage(), -1);
  479. endRequest();
  480. }
  481. @Override
  482. public void onResponseReceived(Request request,
  483. Response response) {
  484. VConsole.log("Server visit took "
  485. + String.valueOf((new Date()).getTime()
  486. - requestStartTime.getTime()) + "ms");
  487. int statusCode = response.getStatusCode();
  488. switch (statusCode) {
  489. case 0:
  490. showCommunicationError(
  491. "Invalid status code 0 (server down?)",
  492. statusCode);
  493. endRequest();
  494. return;
  495. case 401:
  496. /*
  497. * Authorization has failed. Could be that the session
  498. * has timed out and the container is redirecting to a
  499. * login page.
  500. */
  501. showAuthenticationError("");
  502. endRequest();
  503. return;
  504. case 503:
  505. /*
  506. * We'll assume msec instead of the usual seconds. If
  507. * there's no Retry-After header, handle the error like
  508. * a 500, as per RFC 2616 section 10.5.4.
  509. */
  510. String delay = response.getHeader("Retry-After");
  511. if (delay != null) {
  512. VConsole.log("503, retrying in " + delay + "msec");
  513. (new Timer() {
  514. @Override
  515. public void run() {
  516. doUidlRequest(uri, payload, synchronous);
  517. }
  518. }).schedule(Integer.parseInt(delay));
  519. return;
  520. }
  521. }
  522. if ((statusCode / 100) == 4) {
  523. // Handle all 4xx errors the same way as (they are
  524. // all permanent errors)
  525. showCommunicationError(
  526. "UIDL could not be read from server. Check servlets mappings. Error code: "
  527. + statusCode, statusCode);
  528. endRequest();
  529. return;
  530. } else if ((statusCode / 100) == 5) {
  531. // Something's wrong on the server, there's nothing the
  532. // client can do except maybe try again.
  533. showCommunicationError("Server error. Error code: "
  534. + statusCode, statusCode);
  535. endRequest();
  536. return;
  537. }
  538. String contentType = response.getHeader("Content-Type");
  539. if (contentType == null
  540. || !contentType.startsWith("application/json")) {
  541. /*
  542. * A servlet filter or equivalent may have intercepted
  543. * the request and served non-UIDL content (for
  544. * instance, a login page if the session has expired.)
  545. * If the response contains a magic substring, do a
  546. * synchronous refresh. See #8241.
  547. */
  548. MatchResult refreshToken = RegExp.compile(
  549. UIDL_REFRESH_TOKEN + "(:\\s*(.*?))?(\\s|$)")
  550. .exec(response.getText());
  551. if (refreshToken != null) {
  552. redirect(refreshToken.getGroup(2));
  553. return;
  554. }
  555. }
  556. // for(;;);[realjson]
  557. final String jsonText = response.getText().substring(9,
  558. response.getText().length() - 1);
  559. handleJSONText(jsonText, statusCode);
  560. }
  561. };
  562. try {
  563. doAsyncUIDLRequest(uri, payload, requestCallback);
  564. } catch (RequestException e) {
  565. VConsole.error(e);
  566. endRequest();
  567. }
  568. } else {
  569. // Synchronized call, discarded response (leaving the page)
  570. SynchronousXHR syncXHR = (SynchronousXHR) SynchronousXHR.create();
  571. syncXHR.synchronousPost(uri + "&"
  572. + ApplicationConstants.PARAM_UNLOADBURST + "=1", payload);
  573. /*
  574. * Although we are in theory leaving the page, the page may still
  575. * stay open. End request properly here too. See #3289
  576. */
  577. endRequest();
  578. }
  579. }
  580. /**
  581. * Handles received UIDL JSON text, parsing it, and passing it on to the
  582. * appropriate handlers, while logging timiing information.
  583. *
  584. * @param jsonText
  585. * @param statusCode
  586. */
  587. private void handleJSONText(String jsonText, int statusCode) {
  588. final Date start = new Date();
  589. final ValueMap json;
  590. try {
  591. json = parseJSONResponse(jsonText);
  592. } catch (final Exception e) {
  593. endRequest();
  594. showCommunicationError(e.getMessage() + " - Original JSON-text:"
  595. + jsonText, statusCode);
  596. return;
  597. }
  598. VConsole.log("JSON parsing took "
  599. + (new Date().getTime() - start.getTime()) + "ms");
  600. if (applicationRunning) {
  601. handleReceivedJSONMessage(start, jsonText, json);
  602. } else {
  603. applicationRunning = true;
  604. handleWhenCSSLoaded(jsonText, json);
  605. }
  606. }
  607. /**
  608. * Sends an asynchronous UIDL request to the server using the given URI.
  609. *
  610. * @param uri
  611. * The URI to use for the request. May includes GET parameters
  612. * @param payload
  613. * The contents of the request to send
  614. * @param requestCallback
  615. * The handler for the response
  616. * @throws RequestException
  617. * if the request could not be sent
  618. */
  619. protected void doAsyncUIDLRequest(String uri, String payload,
  620. RequestCallback requestCallback) throws RequestException {
  621. RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, uri);
  622. // TODO enable timeout
  623. // rb.setTimeoutMillis(timeoutMillis);
  624. rb.setHeader("Content-Type", "text/plain;charset=utf-8");
  625. rb.setRequestData(payload);
  626. rb.setCallback(requestCallback);
  627. rb.send();
  628. }
  629. int cssWaits = 0;
  630. /**
  631. * Holds the time spent rendering the last request
  632. */
  633. protected int lastProcessingTime;
  634. /**
  635. * Holds the total time spent rendering requests during the lifetime of the
  636. * session.
  637. */
  638. protected int totalProcessingTime;
  639. /**
  640. * Holds the timing information from the server-side. How much time was
  641. * spent servicing the last request and how much time has been spent
  642. * servicing the session so far. These values are always one request behind,
  643. * since they cannot be measured before the request is finished.
  644. */
  645. private ValueMap serverTimingInfo;
  646. static final int MAX_CSS_WAITS = 100;
  647. protected void handleWhenCSSLoaded(final String jsonText,
  648. final ValueMap json) {
  649. if (!isCSSLoaded() && cssWaits < MAX_CSS_WAITS) {
  650. (new Timer() {
  651. @Override
  652. public void run() {
  653. handleWhenCSSLoaded(jsonText, json);
  654. }
  655. }).schedule(50);
  656. VConsole.log("Assuming CSS loading is not complete, "
  657. + "postponing render phase. "
  658. + "(.v-loading-indicator height == 0)");
  659. cssWaits++;
  660. } else {
  661. cssLoaded = true;
  662. handleReceivedJSONMessage(new Date(), jsonText, json);
  663. if (cssWaits >= MAX_CSS_WAITS) {
  664. VConsole.error("CSS files may have not loaded properly.");
  665. }
  666. }
  667. }
  668. /**
  669. * Checks whether or not the CSS is loaded. By default checks the size of
  670. * the loading indicator element.
  671. *
  672. * @return
  673. */
  674. protected boolean isCSSLoaded() {
  675. return cssLoaded
  676. || DOM.getElementPropertyInt(loadElement, "offsetHeight") != 0;
  677. }
  678. /**
  679. * Shows the communication error notification.
  680. *
  681. * @param details
  682. * Optional details for debugging.
  683. * @param statusCode
  684. * The status code returned for the request
  685. *
  686. */
  687. protected void showCommunicationError(String details, int statusCode) {
  688. VConsole.error("Communication error: " + details);
  689. ErrorMessage communicationError = configuration.getCommunicationError();
  690. showError(details, communicationError.getCaption(),
  691. communicationError.getMessage(), communicationError.getUrl());
  692. }
  693. /**
  694. * Shows the authentication error notification.
  695. *
  696. * @param details
  697. * Optional details for debugging.
  698. */
  699. protected void showAuthenticationError(String details) {
  700. VConsole.error("Authentication error: " + details);
  701. ErrorMessage authorizationError = configuration.getAuthorizationError();
  702. showError(details, authorizationError.getCaption(),
  703. authorizationError.getMessage(), authorizationError.getUrl());
  704. }
  705. /**
  706. * Shows the error notification.
  707. *
  708. * @param details
  709. * Optional details for debugging.
  710. */
  711. private void showError(String details, String caption, String message,
  712. String url) {
  713. StringBuilder html = new StringBuilder();
  714. if (caption != null) {
  715. html.append("<h1>");
  716. html.append(caption);
  717. html.append("</h1>");
  718. }
  719. if (message != null) {
  720. html.append("<p>");
  721. html.append(message);
  722. html.append("</p>");
  723. }
  724. if (html.length() > 0) {
  725. // Add error description
  726. html.append("<br/><p><I style=\"font-size:0.7em\">");
  727. html.append(details);
  728. html.append("</I></p>");
  729. VNotification n = VNotification.createNotification(1000 * 60 * 45);
  730. n.addEventListener(new NotificationRedirect(url));
  731. n.show(html.toString(), VNotification.CENTERED_TOP,
  732. VNotification.STYLE_SYSTEM);
  733. } else {
  734. redirect(url);
  735. }
  736. }
  737. protected void startRequest() {
  738. if (hasActiveRequest) {
  739. VConsole.error("Trying to start a new request while another is active");
  740. }
  741. hasActiveRequest = true;
  742. requestStartTime = new Date();
  743. // show initial throbber
  744. if (loadTimer == null) {
  745. loadTimer = new Timer() {
  746. @Override
  747. public void run() {
  748. /*
  749. * IE7 does not properly cancel the event with
  750. * loadTimer.cancel() so we have to check that we really
  751. * should make it visible
  752. */
  753. if (loadTimer != null) {
  754. showLoadingIndicator();
  755. }
  756. }
  757. };
  758. // First one kicks in at 300ms
  759. }
  760. loadTimer.schedule(300);
  761. }
  762. protected void endRequest() {
  763. if (!hasActiveRequest) {
  764. VConsole.error("No active request");
  765. }
  766. // After checkForPendingVariableBursts() there may be a new active
  767. // request, so we must set hasActiveRequest to false before, not after,
  768. // the call. Active requests used to be tracked with an integer counter,
  769. // so setting it after used to work but not with the #8505 changes.
  770. hasActiveRequest = false;
  771. if (applicationRunning) {
  772. checkForPendingVariableBursts();
  773. runPostRequestHooks(configuration.getRootPanelId());
  774. }
  775. // deferring to avoid flickering
  776. Scheduler.get().scheduleDeferred(new Command() {
  777. @Override
  778. public void execute() {
  779. if (!hasActiveRequest()) {
  780. hideLoadingIndicator();
  781. // If on Liferay and session expiration management is in
  782. // use, extend session duration on each request.
  783. // Doing it here rather than before the request to improve
  784. // responsiveness.
  785. // Postponed until the end of the next request if other
  786. // requests still pending.
  787. extendLiferaySession();
  788. }
  789. }
  790. });
  791. }
  792. /**
  793. * This method is called after applying uidl change set to application.
  794. *
  795. * It will clean current and queued variable change sets. And send next
  796. * change set if it exists.
  797. */
  798. private void checkForPendingVariableBursts() {
  799. cleanVariableBurst(pendingInvocations);
  800. if (pendingBursts.size() > 0) {
  801. for (LinkedHashMap<String, MethodInvocation> pendingBurst : pendingBursts) {
  802. cleanVariableBurst(pendingBurst);
  803. }
  804. LinkedHashMap<String, MethodInvocation> nextBurst = pendingBursts
  805. .remove(0);
  806. buildAndSendVariableBurst(nextBurst, false);
  807. }
  808. }
  809. /**
  810. * Cleans given queue of variable changes of such changes that came from
  811. * components that do not exist anymore.
  812. *
  813. * @param variableBurst
  814. */
  815. private void cleanVariableBurst(
  816. LinkedHashMap<String, MethodInvocation> variableBurst) {
  817. Iterator<MethodInvocation> iterator = variableBurst.values().iterator();
  818. while (iterator.hasNext()) {
  819. String id = iterator.next().getConnectorId();
  820. if (!getConnectorMap().hasConnector(id)
  821. && !getConnectorMap().isDragAndDropPaintable(id)) {
  822. // variable owner does not exist anymore
  823. iterator.remove();
  824. VConsole.log("Removed variable from removed component: " + id);
  825. }
  826. }
  827. }
  828. private void showLoadingIndicator() {
  829. // show initial throbber
  830. if (loadElement == null) {
  831. loadElement = DOM.createDiv();
  832. DOM.setStyleAttribute(loadElement, "position", "absolute");
  833. DOM.appendChild(rootConnector.getWidget().getElement(), loadElement);
  834. VConsole.log("inserting load indicator");
  835. }
  836. DOM.setElementProperty(loadElement, "className", "v-loading-indicator");
  837. DOM.setStyleAttribute(loadElement, "display", "block");
  838. // Initialize other timers
  839. loadTimer2 = new Timer() {
  840. @Override
  841. public void run() {
  842. DOM.setElementProperty(loadElement, "className",
  843. "v-loading-indicator-delay");
  844. }
  845. };
  846. // Second one kicks in at 1500ms from request start
  847. loadTimer2.schedule(1200);
  848. loadTimer3 = new Timer() {
  849. @Override
  850. public void run() {
  851. DOM.setElementProperty(loadElement, "className",
  852. "v-loading-indicator-wait");
  853. }
  854. };
  855. // Third one kicks in at 5000ms from request start
  856. loadTimer3.schedule(4700);
  857. }
  858. private void hideLoadingIndicator() {
  859. if (loadTimer != null) {
  860. loadTimer.cancel();
  861. loadTimer = null;
  862. }
  863. if (loadTimer2 != null) {
  864. loadTimer2.cancel();
  865. loadTimer3.cancel();
  866. loadTimer2 = null;
  867. loadTimer3 = null;
  868. }
  869. if (loadElement != null) {
  870. DOM.setStyleAttribute(loadElement, "display", "none");
  871. }
  872. }
  873. /**
  874. * Checks if deferred commands are (potentially) still being executed as a
  875. * result of an update from the server. Returns true if a deferred command
  876. * might still be executing, false otherwise. This will not work correctly
  877. * if a deferred command is added in another deferred command.
  878. * <p>
  879. * Used by the native "client.isActive" function.
  880. * </p>
  881. *
  882. * @return true if deferred commands are (potentially) being executed, false
  883. * otherwise
  884. */
  885. private boolean isExecutingDeferredCommands() {
  886. Scheduler s = Scheduler.get();
  887. if (s instanceof VSchedulerImpl) {
  888. return ((VSchedulerImpl) s).hasWorkQueued();
  889. } else {
  890. return false;
  891. }
  892. }
  893. /**
  894. * Determines whether or not the loading indicator is showing.
  895. *
  896. * @return true if the loading indicator is visible
  897. */
  898. public boolean isLoadingIndicatorVisible() {
  899. if (loadElement == null) {
  900. return false;
  901. }
  902. if (loadElement.getStyle().getProperty("display").equals("none")) {
  903. return false;
  904. }
  905. return true;
  906. }
  907. private static native ValueMap parseJSONResponse(String jsonText)
  908. /*-{
  909. try {
  910. return JSON.parse(jsonText);
  911. } catch (ignored) {
  912. return eval('(' + jsonText + ')');
  913. }
  914. }-*/;
  915. private void handleReceivedJSONMessage(Date start, String jsonText,
  916. ValueMap json) {
  917. handleUIDLMessage(start, jsonText, json);
  918. }
  919. protected void handleUIDLMessage(final Date start, final String jsonText,
  920. final ValueMap json) {
  921. VConsole.log("Handling message from server");
  922. // Handle redirect
  923. if (json.containsKey("redirect")) {
  924. String url = json.getValueMap("redirect").getString("url");
  925. VConsole.log("redirecting to " + url);
  926. redirect(url);
  927. return;
  928. }
  929. final MultiStepDuration handleUIDLDuration = new MultiStepDuration();
  930. // Get security key
  931. if (json.containsKey(ApplicationConstants.UIDL_SECURITY_TOKEN_ID)) {
  932. uidlSecurityKey = json
  933. .getString(ApplicationConstants.UIDL_SECURITY_TOKEN_ID);
  934. }
  935. VConsole.log(" * Handling resources from server");
  936. if (json.containsKey("resources")) {
  937. ValueMap resources = json.getValueMap("resources");
  938. JsArrayString keyArray = resources.getKeyArray();
  939. int l = keyArray.length();
  940. for (int i = 0; i < l; i++) {
  941. String key = keyArray.get(i);
  942. resourcesMap.put(key, resources.getAsString(key));
  943. }
  944. }
  945. handleUIDLDuration.logDuration(
  946. " * Handling resources from server completed", 10);
  947. VConsole.log(" * Handling type inheritance map from server");
  948. if (json.containsKey("typeInheritanceMap")) {
  949. configuration.addComponentInheritanceInfo(json
  950. .getValueMap("typeInheritanceMap"));
  951. }
  952. handleUIDLDuration.logDuration(
  953. " * Handling type inheritance map from server completed", 10);
  954. VConsole.log("Handling type mappings from server");
  955. if (json.containsKey("typeMappings")) {
  956. configuration.addComponentMappings(
  957. json.getValueMap("typeMappings"), widgetSet);
  958. }
  959. VConsole.log("Handling resource dependencies");
  960. if (json.containsKey("scriptDependencies")) {
  961. loadScriptDependencies(json.getJSStringArray("scriptDependencies"));
  962. }
  963. if (json.containsKey("styleDependencies")) {
  964. loadStyleDependencies(json.getJSStringArray("styleDependencies"));
  965. }
  966. handleUIDLDuration.logDuration(
  967. " * Handling type mappings from server completed", 10);
  968. /*
  969. * Hook for e.g. TestBench to get details about server peformance
  970. */
  971. if (json.containsKey("timings")) {
  972. serverTimingInfo = json.getValueMap("timings");
  973. }
  974. Command c = new Command() {
  975. @Override
  976. public void execute() {
  977. handleUIDLDuration.logDuration(" * Loading widgets completed",
  978. 10);
  979. MultiStepDuration updateDuration = new MultiStepDuration();
  980. if (json.containsKey("locales")) {
  981. VConsole.log(" * Handling locales");
  982. // Store locale data
  983. JsArray<ValueMap> valueMapArray = json
  984. .getJSValueMapArray("locales");
  985. LocaleService.addLocales(valueMapArray);
  986. }
  987. updateDuration.logDuration(" * Handling locales completed", 10);
  988. boolean repaintAll = false;
  989. ValueMap meta = null;
  990. if (json.containsKey("meta")) {
  991. VConsole.log(" * Handling meta information");
  992. meta = json.getValueMap("meta");
  993. if (meta.containsKey("repaintAll")) {
  994. repaintAll = true;
  995. rootConnector.getWidget().clear();
  996. getConnectorMap().clear();
  997. if (meta.containsKey("invalidLayouts")) {
  998. validatingLayouts = true;
  999. zeroWidthComponents = new HashSet<ComponentConnector>();
  1000. zeroHeightComponents = new HashSet<ComponentConnector>();
  1001. }
  1002. }
  1003. if (meta.containsKey("timedRedirect")) {
  1004. final ValueMap timedRedirect = meta
  1005. .getValueMap("timedRedirect");
  1006. redirectTimer = new Timer() {
  1007. @Override
  1008. public void run() {
  1009. redirect(timedRedirect.getString("url"));
  1010. }
  1011. };
  1012. sessionExpirationInterval = timedRedirect
  1013. .getInt("interval");
  1014. }
  1015. }
  1016. updateDuration.logDuration(
  1017. " * Handling meta information completed", 10);
  1018. if (redirectTimer != null) {
  1019. redirectTimer.schedule(1000 * sessionExpirationInterval);
  1020. }
  1021. componentCaptionSizeChanges.clear();
  1022. int startProcessing = updateDuration.elapsedMillis();
  1023. // Ensure that all connectors that we are about to update exist
  1024. createConnectorsIfNeeded(json);
  1025. updateDuration.logDuration(" * Creating connectors completed",
  1026. 10);
  1027. // Update states, do not fire events
  1028. Collection<StateChangeEvent> pendingStateChangeEvents = updateConnectorState(json);
  1029. updateDuration.logDuration(
  1030. " * Update of connector states completed", 10);
  1031. // Update hierarchy, do not fire events
  1032. Collection<ConnectorHierarchyChangeEvent> pendingHierarchyChangeEvents = updateConnectorHierarchy(json);
  1033. updateDuration.logDuration(
  1034. " * Update of connector hierarchy completed", 10);
  1035. // Fire hierarchy change events
  1036. sendHierarchyChangeEvents(pendingHierarchyChangeEvents);
  1037. updateDuration.logDuration(
  1038. " * Hierarchy state change event processing completed",
  1039. 10);
  1040. // Fire state change events.
  1041. sendStateChangeEvents(pendingStateChangeEvents);
  1042. updateDuration.logDuration(
  1043. " * State change event processing completed", 10);
  1044. // Update of legacy (UIDL) style connectors
  1045. updateVaadin6StyleConnectors(json);
  1046. updateDuration
  1047. .logDuration(
  1048. " * Vaadin 6 style connector updates (updateFromUidl) completed",
  1049. 10);
  1050. // Handle any RPC invocations done on the server side
  1051. handleRpcInvocations(json);
  1052. updateDuration.logDuration(
  1053. " * Processing of RPC invocations completed", 10);
  1054. if (json.containsKey("dd")) {
  1055. // response contains data for drag and drop service
  1056. VDragAndDropManager.get().handleServerResponse(
  1057. json.getValueMap("dd"));
  1058. }
  1059. updateDuration
  1060. .logDuration(
  1061. " * Processing of drag and drop server response completed",
  1062. 10);
  1063. unregisterRemovedConnectors();
  1064. updateDuration.logDuration(
  1065. " * Unregistering of removed components completed", 10);
  1066. VConsole.log("handleUIDLMessage: "
  1067. + (updateDuration.elapsedMillis() - startProcessing)
  1068. + " ms");
  1069. LayoutManager layoutManager = getLayoutManager();
  1070. layoutManager.setEverythingNeedsMeasure();
  1071. layoutManager.layoutNow();
  1072. updateDuration
  1073. .logDuration(" * Layout processing completed", 10);
  1074. if (ApplicationConfiguration.isDebugMode()) {
  1075. VConsole.log(" * Dumping state changes to the console");
  1076. VConsole.dirUIDL(json, ApplicationConnection.this);
  1077. updateDuration
  1078. .logDuration(
  1079. " * Dumping state changes to the console completed",
  1080. 10);
  1081. }
  1082. if (meta != null) {
  1083. if (meta.containsKey("appError")) {
  1084. ValueMap error = meta.getValueMap("appError");
  1085. String html = "";
  1086. if (error.containsKey("caption")
  1087. && error.getString("caption") != null) {
  1088. html += "<h1>" + error.getAsString("caption")
  1089. + "</h1>";
  1090. }
  1091. if (error.containsKey("message")
  1092. && error.getString("message") != null) {
  1093. html += "<p>" + error.getAsString("message")
  1094. + "</p>";
  1095. }
  1096. String url = null;
  1097. if (error.containsKey("url")) {
  1098. url = error.getString("url");
  1099. }
  1100. if (html.length() != 0) {
  1101. /* 45 min */
  1102. VNotification n = VNotification
  1103. .createNotification(1000 * 60 * 45);
  1104. n.addEventListener(new NotificationRedirect(url));
  1105. n.show(html, VNotification.CENTERED_TOP,
  1106. VNotification.STYLE_SYSTEM);
  1107. } else {
  1108. redirect(url);
  1109. }
  1110. applicationRunning = false;
  1111. }
  1112. if (validatingLayouts) {
  1113. VConsole.printLayoutProblems(meta,
  1114. ApplicationConnection.this,
  1115. zeroHeightComponents, zeroWidthComponents);
  1116. zeroHeightComponents = null;
  1117. zeroWidthComponents = null;
  1118. validatingLayouts = false;
  1119. }
  1120. }
  1121. updateDuration.logDuration(" * Error handling completed", 10);
  1122. // TODO build profiling for widget impl loading time
  1123. lastProcessingTime = (int) ((new Date().getTime()) - start
  1124. .getTime());
  1125. totalProcessingTime += lastProcessingTime;
  1126. VConsole.log(" Processing time was "
  1127. + String.valueOf(lastProcessingTime) + "ms for "
  1128. + jsonText.length() + " characters of JSON");
  1129. VConsole.log("Referenced paintables: " + connectorMap.size());
  1130. endRequest();
  1131. }
  1132. /**
  1133. * Sends the state change events created while updating the state
  1134. * information.
  1135. *
  1136. * This must be called after hierarchy change listeners have been
  1137. * called. At least caption updates for the parent are strange if
  1138. * fired from state change listeners and thus calls the parent
  1139. * BEFORE the parent is aware of the child (through a
  1140. * ConnectorHierarchyChangedEvent)
  1141. *
  1142. * @param pendingStateChangeEvents
  1143. * The events to send
  1144. */
  1145. private void sendStateChangeEvents(
  1146. Collection<StateChangeEvent> pendingStateChangeEvents) {
  1147. VConsole.log(" * Sending state change events");
  1148. for (StateChangeEvent sce : pendingStateChangeEvents) {
  1149. try {
  1150. sce.getConnector().fireEvent(sce);
  1151. } catch (final Throwable e) {
  1152. VConsole.error(e);
  1153. }
  1154. }
  1155. }
  1156. private void unregisterRemovedConnectors() {
  1157. int unregistered = 0;
  1158. List<ServerConnector> currentConnectors = new ArrayList<ServerConnector>(
  1159. connectorMap.getConnectors());
  1160. for (ServerConnector c : currentConnectors) {
  1161. if (c.getParent() != null) {
  1162. if (!c.getParent().getChildren().contains(c)) {
  1163. VConsole.error("ERROR: Connector is connected to a parent but the parent does not contain the connector");
  1164. }
  1165. } else if ((c instanceof RootConnector && c == getRootConnector())) {
  1166. // RootConnector for this connection, leave as-is
  1167. } else if (c instanceof WindowConnector
  1168. && getRootConnector().hasSubWindow(
  1169. (WindowConnector) c)) {
  1170. // Sub window attached to this RootConnector, leave
  1171. // as-is
  1172. } else {
  1173. // The connector has been detached from the
  1174. // hierarchy, unregister it and any possible
  1175. // children. The RootConnector should never be
  1176. // unregistered even though it has no parent.
  1177. connectorMap.unregisterConnector(c);
  1178. unregistered++;
  1179. }
  1180. }
  1181. VConsole.log("* Unregistered " + unregistered + " connectors");
  1182. }
  1183. private void createConnectorsIfNeeded(ValueMap json) {
  1184. VConsole.log(" * Creating connectors (if needed)");
  1185. if (!json.containsKey("types")) {
  1186. return;
  1187. }
  1188. ValueMap types = json.getValueMap("types");
  1189. JsArrayString keyArray = types.getKeyArray();
  1190. for (int i = 0; i < keyArray.length(); i++) {
  1191. try {
  1192. String connectorId = keyArray.get(i);
  1193. int connectorType = Integer.parseInt(types
  1194. .getString((connectorId)));
  1195. ServerConnector connector = connectorMap
  1196. .getConnector(connectorId);
  1197. if (connector != null) {
  1198. continue;
  1199. }
  1200. Class<? extends ServerConnector> connectorClass = configuration
  1201. .getConnectorClassByEncodedTag(connectorType);
  1202. // Connector does not exist so we must create it
  1203. if (connectorClass != RootConnector.class) {
  1204. // create, initialize and register the paintable
  1205. getConnector(connectorId, connectorType);
  1206. } else {
  1207. // First RootConnector update. Before this the
  1208. // RootConnector has been created but not
  1209. // initialized as the connector id has not been
  1210. // known
  1211. connectorMap.registerConnector(connectorId,
  1212. rootConnector);
  1213. rootConnector.doInit(connectorId,
  1214. ApplicationConnection.this);
  1215. }
  1216. } catch (final Throwable e) {
  1217. VConsole.error(e);
  1218. }
  1219. }
  1220. }
  1221. private void updateVaadin6StyleConnectors(ValueMap json) {
  1222. JsArray<ValueMap> changes = json.getJSValueMapArray("changes");
  1223. int length = changes.length();
  1224. VConsole.log(" * Passing UIDL to Vaadin 6 style connectors");
  1225. // update paintables
  1226. for (int i = 0; i < length; i++) {
  1227. try {
  1228. final UIDL change = changes.get(i).cast();
  1229. final UIDL uidl = change.getChildUIDL(0);
  1230. String connectorId = uidl.getId();
  1231. final ComponentConnector legacyConnector = (ComponentConnector) connectorMap
  1232. .getConnector(connectorId);
  1233. if (legacyConnector instanceof Paintable) {
  1234. ((Paintable) legacyConnector).updateFromUIDL(uidl,
  1235. ApplicationConnection.this);
  1236. } else if (legacyConnector == null) {
  1237. VConsole.error("Received update for "
  1238. + uidl.getTag()
  1239. + ", but there is no such paintable ("
  1240. + connectorId + ") rendered.");
  1241. } else {
  1242. VConsole.error("Server sent Vaadin 6 style updates for "
  1243. + Util.getConnectorString(legacyConnector)
  1244. + " but this is not a Vaadin 6 Paintable");
  1245. }
  1246. } catch (final Throwable e) {
  1247. VConsole.error(e);
  1248. }
  1249. }
  1250. }
  1251. private void sendHierarchyChangeEvents(
  1252. Collection<ConnectorHierarchyChangeEvent> pendingHierarchyChangeEvents) {
  1253. if (pendingHierarchyChangeEvents.isEmpty()) {
  1254. return;
  1255. }
  1256. VConsole.log(" * Sending hierarchy change events");
  1257. for (ConnectorHierarchyChangeEvent event : pendingHierarchyChangeEvents) {
  1258. try {
  1259. event.getConnector().fireEvent(event);
  1260. } catch (final Throwable e) {
  1261. VConsole.error(e);
  1262. }
  1263. }
  1264. }
  1265. private Collection<StateChangeEvent> updateConnectorState(
  1266. ValueMap json) {
  1267. ArrayList<StateChangeEvent> events = new ArrayList<StateChangeEvent>();
  1268. VConsole.log(" * Updating connector states");
  1269. if (!json.containsKey("state")) {
  1270. return events;
  1271. }
  1272. // set states for all paintables mentioned in "state"
  1273. ValueMap states = json.getValueMap("state");
  1274. JsArrayString keyArray = states.getKeyArray();
  1275. for (int i = 0; i < keyArray.length(); i++) {
  1276. try {
  1277. String connectorId = keyArray.get(i);
  1278. ServerConnector connector = connectorMap
  1279. .getConnector(connectorId);
  1280. if (null != connector) {
  1281. JSONObject stateJson = new JSONObject(
  1282. states.getJavaScriptObject(connectorId));
  1283. if (connector instanceof HasJavaScriptConnectorHelper) {
  1284. ((HasJavaScriptConnectorHelper) connector)
  1285. .getJavascriptConnectorHelper()
  1286. .setNativeState(
  1287. stateJson.getJavaScriptObject());
  1288. }
  1289. SharedState state = connector.getState();
  1290. JsonDecoder.decodeValue(new Type(state.getClass()
  1291. .getName(), null), stateJson, state,
  1292. ApplicationConnection.this);
  1293. Set<String> changedProperties = new HashSet<String>();
  1294. addJsonFields(stateJson, changedProperties, "");
  1295. StateChangeEvent event = new StateChangeEvent(
  1296. connector, changedProperties);
  1297. events.add(event);
  1298. }
  1299. } catch (final Throwable e) {
  1300. VConsole.error(e);
  1301. }
  1302. }
  1303. return events;
  1304. }
  1305. /**
  1306. * Recursively adds the names of all fields in all objects in the
  1307. * provided json object.
  1308. *
  1309. * @param json
  1310. * the json object to process
  1311. * @param fields
  1312. * a set of all currently added fields
  1313. * @param context
  1314. * the base name of the current object
  1315. */
  1316. private void addJsonFields(JSONObject json, Set<String> fields,
  1317. String context) {
  1318. for (String key : json.keySet()) {
  1319. String fieldName = context + key;
  1320. fields.add(fieldName);
  1321. JSONObject object = json.get(key).isObject();
  1322. if (object != null) {
  1323. addJsonFields(object, fields, fieldName + ".");
  1324. }
  1325. }
  1326. }
  1327. /**
  1328. * Updates the connector hierarchy and returns a list of events that
  1329. * should be fired after update of the hierarchy and the state is
  1330. * done.
  1331. *
  1332. * @param json
  1333. * The JSON containing the hierarchy information
  1334. * @return A collection of events that should be fired when update
  1335. * of hierarchy and state is complete
  1336. */
  1337. private Collection<ConnectorHierarchyChangeEvent> updateConnectorHierarchy(
  1338. ValueMap json) {
  1339. List<ConnectorHierarchyChangeEvent> events = new LinkedList<ConnectorHierarchyChangeEvent>();
  1340. VConsole.log(" * Updating connector hierarchy");
  1341. if (!json.containsKey("hierarchy")) {
  1342. return events;
  1343. }
  1344. ValueMap hierarchies = json.getValueMap("hierarchy");
  1345. JsArrayString hierarchyKeys = hierarchies.getKeyArray();
  1346. for (int i = 0; i < hierarchyKeys.length(); i++) {
  1347. try {
  1348. String connectorId = hierarchyKeys.get(i);
  1349. ServerConnector parentConnector = connectorMap
  1350. .getConnector(connectorId);
  1351. JsArrayString childConnectorIds = hierarchies
  1352. .getJSStringArray(connectorId);
  1353. int childConnectorSize = childConnectorIds.length();
  1354. List<ServerConnector> newChildren = new ArrayList<ServerConnector>();
  1355. List<ComponentConnector> newComponents = new ArrayList<ComponentConnector>();
  1356. for (int connectorIndex = 0; connectorIndex < childConnectorSize; connectorIndex++) {
  1357. String childConnectorId = childConnectorIds
  1358. .get(connectorIndex);
  1359. ServerConnector childConnector = connectorMap
  1360. .getConnector(childConnectorId);
  1361. if (childConnector == null) {
  1362. VConsole.error("Hierarchy claims that "
  1363. + childConnectorId + " is a child for "
  1364. + connectorId + " ("
  1365. + parentConnector.getClass().getName()
  1366. + ") but no connector with id "
  1367. + childConnectorId
  1368. + " has been registered");
  1369. continue;
  1370. }
  1371. newChildren.add(childConnector);
  1372. if (childConnector instanceof ComponentConnector) {
  1373. newComponents
  1374. .add((ComponentConnector) childConnector);
  1375. } else if (!(childConnector instanceof AbstractExtensionConnector)) {
  1376. throw new IllegalStateException(
  1377. Util.getConnectorString(childConnector)
  1378. + " is not a ComponentConnector nor an AbstractExtensionConnector");
  1379. }
  1380. if (childConnector.getParent() != parentConnector) {
  1381. // Avoid extra calls to setParent
  1382. childConnector.setParent(parentConnector);
  1383. }
  1384. }
  1385. // TODO This check should be done on the server side in
  1386. // the future so the hierarchy update is only sent when
  1387. // something actually has changed
  1388. List<ServerConnector> oldChildren = parentConnector
  1389. .getChildren();
  1390. boolean actuallyChanged = !Util.collectionsEquals(
  1391. oldChildren, newChildren);
  1392. if (!actuallyChanged) {
  1393. continue;
  1394. }
  1395. if (parentConnector instanceof ComponentContainerConnector) {
  1396. ComponentContainerConnector ccc = (ComponentContainerConnector) parentConnector;
  1397. List<ComponentConnector> oldComponents = ccc
  1398. .getChildComponents();
  1399. if (!Util.collectionsEquals(oldComponents,
  1400. newComponents)) {
  1401. // Fire change event if the hierarchy has
  1402. // changed
  1403. ConnectorHierarchyChangeEvent event = GWT
  1404. .create(ConnectorHierarchyChangeEvent.class);
  1405. event.setOldChildren(oldComponents);
  1406. event.setConnector(parentConnector);
  1407. ccc.setChildComponents(newComponents);
  1408. events.add(event);
  1409. }
  1410. } else if (!newComponents.isEmpty()) {
  1411. VConsole.error("Hierachy claims "
  1412. + Util.getConnectorString(parentConnector)
  1413. + " has component children even though it isn't a ComponentContainerConnector");
  1414. }
  1415. parentConnector.setChildren(newChildren);
  1416. // Remove parent for children that are no longer
  1417. // attached to this (avoid updating children if they
  1418. // have already been assigned to a new parent)
  1419. for (ServerConnector oldChild : oldChildren) {
  1420. if (oldChild.getParent() != parentConnector) {
  1421. continue;
  1422. }
  1423. // TODO This could probably be optimized
  1424. if (!newChildren.contains(oldChild)) {
  1425. oldChild.setParent(null);
  1426. }
  1427. }
  1428. } catch (final Throwable e) {
  1429. VConsole.error(e);
  1430. }
  1431. }
  1432. return events;
  1433. }
  1434. private void handleRpcInvocations(ValueMap json) {
  1435. if (json.containsKey("rpc")) {
  1436. VConsole.log(" * Performing server to client RPC calls");
  1437. JSONArray rpcCalls = new JSONArray(
  1438. json.getJavaScriptObject("rpc"));
  1439. int rpcLength = rpcCalls.size();
  1440. for (int i = 0; i < rpcLength; i++) {
  1441. try {
  1442. JSONArray rpcCall = (JSONArray) rpcCalls.get(i);
  1443. rpcManager.parseAndApplyInvocation(rpcCall,
  1444. ApplicationConnection.this);
  1445. } catch (final Throwable e) {
  1446. VConsole.error(e);
  1447. }
  1448. }
  1449. }
  1450. }
  1451. };
  1452. ApplicationConfiguration.runWhenDependenciesLoaded(c);
  1453. }
  1454. private void loadStyleDependencies(JsArrayString dependencies) {
  1455. // Assuming no reason to interpret in a defined order
  1456. ResourceLoadListener resourceLoadListener = new ResourceLoadListener() {
  1457. @Override
  1458. public void onLoad(ResourceLoadEvent event) {
  1459. ApplicationConfiguration.endDependencyLoading();
  1460. }
  1461. @Override
  1462. public void onError(ResourceLoadEvent event) {
  1463. VConsole.error(event.getResourceUrl()
  1464. + " could not be loaded, or the load detection failed because the stylesheet is empty.");
  1465. // The show must go on
  1466. onLoad(event);
  1467. }
  1468. };
  1469. ResourceLoader loader = ResourceLoader.get();
  1470. for (int i = 0; i < dependencies.length(); i++) {
  1471. String url = translateVaadinUri(dependencies.get(i));
  1472. ApplicationConfiguration.startDependencyLoading();
  1473. loader.loadStylesheet(url, resourceLoadListener);
  1474. }
  1475. }
  1476. private void loadScriptDependencies(final JsArrayString dependencies) {
  1477. if (dependencies.length() == 0) {
  1478. return;
  1479. }
  1480. // Listener that loads the next when one is completed
  1481. ResourceLoadListener resourceLoadListener = new ResourceLoadListener() {
  1482. @Override
  1483. public void onLoad(ResourceLoadEvent event) {
  1484. if (dependencies.length() != 0) {
  1485. String url = translateVaadinUri(dependencies.shift());
  1486. ApplicationConfiguration.startDependencyLoading();
  1487. // Load next in chain (hopefully already preloaded)
  1488. event.getResourceLoader().loadScript(url, this);
  1489. }
  1490. // Call start for next before calling end for current
  1491. ApplicationConfiguration.endDependencyLoading();
  1492. }
  1493. @Override
  1494. public void onError(ResourceLoadEvent event) {
  1495. VConsole.error(event.getResourceUrl() + " could not be loaded.");
  1496. // The show must go on
  1497. onLoad(event);
  1498. }
  1499. };
  1500. ResourceLoader loader = ResourceLoader.get();
  1501. // Start chain by loading first
  1502. String url = translateVaadinUri(dependencies.shift());
  1503. ApplicationConfiguration.startDependencyLoading();
  1504. loader.loadScript(url, resourceLoadListener);
  1505. // Preload all remaining
  1506. for (int i = 0; i < dependencies.length(); i++) {
  1507. String preloadUrl = translateVaadinUri(dependencies.get(i));
  1508. loader.preloadResource(preloadUrl, null);
  1509. }
  1510. }
  1511. // Redirect browser, null reloads current page
  1512. private static native void redirect(String url)
  1513. /*-{
  1514. if (url) {
  1515. $wnd.location = url;
  1516. } else {
  1517. $wnd.location.reload(false);
  1518. }
  1519. }-*/;
  1520. private void addVariableToQueue(String connectorId, String variableName,
  1521. Object value, boolean immediate) {
  1522. boolean lastOnly = !immediate;
  1523. // note that type is now deduced from value
  1524. addMethodInvocationToQueue(new LegacyChangeVariablesInvocation(
  1525. connectorId, variableName, value), lastOnly, lastOnly);
  1526. }
  1527. /**
  1528. * Adds an explicit RPC method invocation to the send queue.
  1529. *
  1530. * @since 7.0
  1531. *
  1532. * @param invocation
  1533. * RPC method invocation
  1534. * @param delayed
  1535. * <code>false</code> to trigger sending within a short time
  1536. * window (possibly combining subsequent calls to a single
  1537. * request), <code>true</code> to let the framework delay sending
  1538. * of RPC calls and variable changes until the next non-delayed
  1539. * change
  1540. * @param lastonly
  1541. * <code>true</code> to remove all previously delayed invocations
  1542. * of the same method that were also enqueued with lastonly set
  1543. * to <code>true</code>. <code>false</code> to add invocation to
  1544. * the end of the queue without touching previously enqueued
  1545. * invocations.
  1546. */
  1547. public void addMethodInvocationToQueue(MethodInvocation invocation,
  1548. boolean delayed, boolean lastonly) {
  1549. String tag;
  1550. if (lastonly) {
  1551. tag = invocation.getLastonlyTag();
  1552. assert !tag.matches("\\d+") : "getLastonlyTag value must have at least one non-digit character";
  1553. pendingInvocations.remove(tag);
  1554. } else {
  1555. tag = Integer.toString(lastInvocationTag++);
  1556. }
  1557. pendingInvocations.put(tag, invocation);
  1558. if (!delayed) {
  1559. sendPendingVariableChanges();
  1560. }
  1561. }
  1562. /**
  1563. * This method sends currently queued variable changes to server. It is
  1564. * called when immediate variable update must happen.
  1565. *
  1566. * To ensure correct order for variable changes (due servers multithreading
  1567. * or network), we always wait for active request to be handler before
  1568. * sending a new one. If there is an active request, we will put varible
  1569. * "burst" to queue that will be purged after current request is handled.
  1570. *
  1571. */
  1572. public void sendPendingVariableChanges() {
  1573. if (!deferedSendPending) {
  1574. deferedSendPending = true;
  1575. Scheduler.get().scheduleDeferred(sendPendingCommand);
  1576. }
  1577. }
  1578. private final ScheduledCommand sendPendingCommand = new ScheduledCommand() {
  1579. @Override
  1580. public void execute() {
  1581. deferedSendPending = false;
  1582. doSendPendingVariableChanges();
  1583. }
  1584. };
  1585. private boolean deferedSendPending = false;
  1586. private void doSendPendingVariableChanges() {
  1587. if (applicationRunning) {
  1588. if (hasActiveRequest()) {
  1589. // skip empty queues if there are pending bursts to be sent
  1590. if (pendingInvocations.size() > 0 || pendingBursts.size() == 0) {
  1591. pendingBursts.add(pendingInvocations);
  1592. pendingInvocations = new LinkedHashMap<String, MethodInvocation>();
  1593. // Keep tag string short
  1594. lastInvocationTag = 0;
  1595. }
  1596. } else {
  1597. buildAndSendVariableBurst(pendingInvocations, false);
  1598. }
  1599. }
  1600. }
  1601. /**
  1602. * Build the variable burst and send it to server.
  1603. *
  1604. * When sync is forced, we also force sending of all pending variable-bursts
  1605. * at the same time. This is ok as we can assume that DOM will never be
  1606. * updated after this.
  1607. *
  1608. * @param pendingInvocations
  1609. * List of RPC method invocations to send
  1610. * @param forceSync
  1611. * Should we use synchronous request?
  1612. */
  1613. private void buildAndSendVariableBurst(
  1614. LinkedHashMap<String, MethodInvocation> pendingInvocations,
  1615. boolean forceSync) {
  1616. final StringBuffer req = new StringBuffer();
  1617. while (!pendingInvocations.isEmpty()) {
  1618. if (ApplicationConfiguration.isDebugMode()) {
  1619. Util.logVariableBurst(this, pendingInvocations.values());
  1620. }
  1621. JSONArray reqJson = new JSONArray();
  1622. for (MethodInvocation invocation : pendingInvocations.values()) {
  1623. JSONArray invocationJson = new JSONArray();
  1624. invocationJson.set(0,
  1625. new JSONString(invocation.getConnectorId()));
  1626. invocationJson.set(1,
  1627. new JSONString(invocation.getInterfaceName()));
  1628. invocationJson.set(2,
  1629. new JSONString(invocation.getMethodName()));
  1630. JSONArray paramJson = new JSONArray();
  1631. boolean restrictToInternalTypes = isLegacyVariableChange(invocation);
  1632. for (int i = 0; i < invocation.getParameters().length; ++i) {
  1633. // TODO non-static encoder? type registration?
  1634. paramJson.set(i, JsonEncoder.encode(
  1635. invocation.getParameters()[i],
  1636. restrictToInternalTypes, this));
  1637. }
  1638. invocationJson.set(3, paramJson);
  1639. reqJson.set(reqJson.size(), invocationJson);
  1640. }
  1641. // escape burst separators (if any)
  1642. req.append(escapeBurstContents(reqJson.toString()));
  1643. pendingInvocations.clear();
  1644. // Keep tag string short
  1645. lastInvocationTag = 0;
  1646. // Append all the bursts to this synchronous request
  1647. if (forceSync && !pendingBursts.isEmpty()) {
  1648. pendingInvocations = pendingBursts.get(0);
  1649. pendingBursts.remove(0);
  1650. req.append(VAR_BURST_SEPARATOR);
  1651. }
  1652. }
  1653. // Include the browser detail parameters if they aren't already sent
  1654. String extraParams;
  1655. if (!getConfiguration().isBrowserDetailsSent()) {
  1656. extraParams = getNativeBrowserDetailsParameters(getConfiguration()
  1657. .getRootPanelId());
  1658. getConfiguration().setBrowserDetailsSent();
  1659. } else {
  1660. extraParams = "";
  1661. }
  1662. if (!getConfiguration().isWidgetsetVersionSent()) {
  1663. if (!extraParams.isEmpty()) {
  1664. extraParams += "&";
  1665. }
  1666. String widgetsetVersion = Version.getFullVersion();
  1667. extraParams += "wsver=" + widgetsetVersion;
  1668. getConfiguration().setWidgetsetVersionSent();
  1669. }
  1670. makeUidlRequest(req.toString(), extraParams, forceSync);
  1671. }
  1672. private boolean isLegacyVariableChange(MethodInvocation invocation) {
  1673. return ApplicationConstants.UPDATE_VARIABLE_METHOD.equals(invocation
  1674. .getInterfaceName())
  1675. && ApplicationConstants.UPDATE_VARIABLE_METHOD
  1676. .equals(invocation.getMethodName());
  1677. }
  1678. /**
  1679. * Sends a new value for the given paintables given variable to the server.
  1680. * <p>
  1681. * The update is actually queued to be sent at a suitable time. If immediate
  1682. * is true, the update is sent as soon as possible. If immediate is false,
  1683. * the update will be sent along with the next immediate update.
  1684. * </p>
  1685. *
  1686. * @param paintableId
  1687. * the id of the paintable that owns the variable
  1688. * @param variableName
  1689. * the name of the variable
  1690. * @param newValue
  1691. * the new value to be sent
  1692. * @param immediate
  1693. * true if the update is to be sent as soon as possible
  1694. */
  1695. public void updateVariable(String paintableId, String variableName,
  1696. ServerConnector newValue, boolean immediate) {
  1697. addVariableToQueue(paintableId, variableName, newValue, immediate);
  1698. }
  1699. /**
  1700. * Sends a new value for the given paintables given variable to the server.
  1701. * <p>
  1702. * The update is actually queued to be sent at a suitable time. If immediate
  1703. * is true, the update is sent as soon as possible. If immediate is false,
  1704. * the update will be sent along with the next immediate update.
  1705. * </p>
  1706. *
  1707. * @param paintableId
  1708. * the id of the paintable that owns the variable
  1709. * @param variableName
  1710. * the name of the variable
  1711. * @param newValue
  1712. * the new value to be sent
  1713. * @param immediate
  1714. * true if the update is to be sent as soon as possible
  1715. */
  1716. public void updateVariable(String paintableId, String variableName,
  1717. String newValue, boolean immediate) {
  1718. addVariableToQueue(paintableId, variableName, newValue, immediate);
  1719. }
  1720. /**
  1721. * Sends a new value for the given paintables given variable to the server.
  1722. * <p>
  1723. * The update is actually queued to be sent at a suitable time. If immediate
  1724. * is true, the update is sent as soon as possible. If immediate is false,
  1725. * the update will be sent along with the next immediate update.
  1726. * </p>
  1727. *
  1728. * @param paintableId
  1729. * the id of the paintable that owns the variable
  1730. * @param variableName
  1731. * the name of the variable
  1732. * @param newValue
  1733. * the new value to be sent
  1734. * @param immediate
  1735. * true if the update is to be sent as soon as possible
  1736. */
  1737. public void updateVariable(String paintableId, String variableName,
  1738. int newValue, boolean immediate) {
  1739. addVariableToQueue(paintableId, variableName, newValue, immediate);
  1740. }
  1741. /**
  1742. * Sends a new value for the given paintables given variable to the server.
  1743. * <p>
  1744. * The update is actually queued to be sent at a suitable time. If immediate
  1745. * is true, the update is sent as soon as possible. If immediate is false,
  1746. * the update will be sent along with the next immediate update.
  1747. * </p>
  1748. *
  1749. * @param paintableId
  1750. * the id of the paintable that owns the variable
  1751. * @param variableName
  1752. * the name of the variable
  1753. * @param newValue
  1754. * the new value to be sent
  1755. * @param immediate
  1756. * true if the update is to be sent as soon as possible
  1757. */
  1758. public void updateVariable(String paintableId, String variableName,
  1759. long newValue, boolean immediate) {
  1760. addVariableToQueue(paintableId, variableName, newValue, immediate);
  1761. }
  1762. /**
  1763. * Sends a new value for the given paintables given variable to the server.
  1764. * <p>
  1765. * The update is actually queued to be sent at a suitable time. If immediate
  1766. * is true, the update is sent as soon as possible. If immediate is false,
  1767. * the update will be sent along with the next immediate update.
  1768. * </p>
  1769. *
  1770. * @param paintableId
  1771. * the id of the paintable that owns the variable
  1772. * @param variableName
  1773. * the name of the variable
  1774. * @param newValue
  1775. * the new value to be sent
  1776. * @param immediate
  1777. * true if the update is to be sent as soon as possible
  1778. */
  1779. public void updateVariable(String paintableId, String variableName,
  1780. float newValue, boolean immediate) {
  1781. addVariableToQueue(paintableId, variableName, newValue, immediate);
  1782. }
  1783. /**
  1784. * Sends a new value for the given paintables given variable to the server.
  1785. * <p>
  1786. * The update is actually queued to be sent at a suitable time. If immediate
  1787. * is true, the update is sent as soon as possible. If immediate is false,
  1788. * the update will be sent along with the next immediate update.
  1789. * </p>
  1790. *
  1791. * @param paintableId
  1792. * the id of the paintable that owns the variable
  1793. * @param variableName
  1794. * the name of the variable
  1795. * @param newValue
  1796. * the new value to be sent
  1797. * @param immediate
  1798. * true if the update is to be sent as soon as possible
  1799. */
  1800. public void updateVariable(String paintableId, String variableName,
  1801. double newValue, boolean immediate) {
  1802. addVariableToQueue(paintableId, variableName, newValue, immediate);
  1803. }
  1804. /**
  1805. * Sends a new value for the given paintables given variable to the server.
  1806. * <p>
  1807. * The update is actually queued to be sent at a suitable time. If immediate
  1808. * is true, the update is sent as soon as possible. If immediate is false,
  1809. * the update will be sent along with the next immediate update.
  1810. * </p>
  1811. *
  1812. * @param paintableId
  1813. * the id of the paintable that owns the variable
  1814. * @param variableName
  1815. * the name of the variable
  1816. * @param newValue
  1817. * the new value to be sent
  1818. * @param immediate
  1819. * true if the update is to be sent as soon as possible
  1820. */
  1821. public void updateVariable(String paintableId, String variableName,
  1822. boolean newValue, boolean immediate) {
  1823. addVariableToQueue(paintableId, variableName, newValue, immediate);
  1824. }
  1825. /**
  1826. * Sends a new value for the given paintables given variable to the server.
  1827. * <p>
  1828. * The update is actually queued to be sent at a suitable time. If immediate
  1829. * is true, the update is sent as soon as possible. If immediate is false,
  1830. * the update will be sent along with the next immediate update.
  1831. * </p>
  1832. *
  1833. * @param paintableId
  1834. * the id of the paintable that owns the variable
  1835. * @param variableName
  1836. * the name of the variable
  1837. * @param map
  1838. * the new values to be sent
  1839. * @param immediate
  1840. * true if the update is to be sent as soon as possible
  1841. */
  1842. public void updateVariable(String paintableId, String variableName,
  1843. Map<String, Object> map, boolean immediate) {
  1844. addVariableToQueue(paintableId, variableName, map, immediate);
  1845. }
  1846. /**
  1847. * Sends a new value for the given paintables given variable to the server.
  1848. *
  1849. * The update is actually queued to be sent at a suitable time. If immediate
  1850. * is true, the update is sent as soon as possible. If immediate is false,
  1851. * the update will be sent along with the next immediate update.
  1852. *
  1853. * A null array is sent as an empty array.
  1854. *
  1855. * @param paintableId
  1856. * the id of the paintable that owns the variable
  1857. * @param variableName
  1858. * the name of the variable
  1859. * @param values
  1860. * the new value to be sent
  1861. * @param immediate
  1862. * true if the update is to be sent as soon as possible
  1863. */
  1864. public void updateVariable(String paintableId, String variableName,
  1865. String[] values, boolean immediate) {
  1866. addVariableToQueue(paintableId, variableName, values, immediate);
  1867. }
  1868. /**
  1869. * Sends a new value for the given paintables given variable to the server.
  1870. *
  1871. * The update is actually queued to be sent at a suitable time. If immediate
  1872. * is true, the update is sent as soon as possible. If immediate is false,
  1873. * the update will be sent along with the next immediate update. </p>
  1874. *
  1875. * A null array is sent as an empty array.
  1876. *
  1877. *
  1878. * @param paintableId
  1879. * the id of the paintable that owns the variable
  1880. * @param variableName
  1881. * the name of the variable
  1882. * @param values
  1883. * the new value to be sent
  1884. * @param immediate
  1885. * true if the update is to be sent as soon as possible
  1886. */
  1887. public void updateVariable(String paintableId, String variableName,
  1888. Object[] values, boolean immediate) {
  1889. addVariableToQueue(paintableId, variableName, values, immediate);
  1890. }
  1891. /**
  1892. * Encode burst separator characters in a String for transport over the
  1893. * network. This protects from separator injection attacks.
  1894. *
  1895. * @param value
  1896. * to encode
  1897. * @return encoded value
  1898. */
  1899. protected String escapeBurstContents(String value) {
  1900. final StringBuilder result = new StringBuilder();
  1901. for (int i = 0; i < value.length(); ++i) {
  1902. char character = value.charAt(i);
  1903. switch (character) {
  1904. case VAR_ESCAPE_CHARACTER:
  1905. // fall-through - escape character is duplicated
  1906. case VAR_BURST_SEPARATOR:
  1907. result.append(VAR_ESCAPE_CHARACTER);
  1908. // encode as letters for easier reading
  1909. result.append(((char) (character + 0x30)));
  1910. break;
  1911. default:
  1912. // the char is not a special one - add it to the result as is
  1913. result.append(character);
  1914. break;
  1915. }
  1916. }
  1917. return result.toString();
  1918. }
  1919. private boolean runningLayout = false;
  1920. /**
  1921. * Causes a re-calculation/re-layout of all paintables in a container.
  1922. *
  1923. * @param container
  1924. */
  1925. public void runDescendentsLayout(HasWidgets container) {
  1926. if (runningLayout) {
  1927. return;
  1928. }
  1929. runningLayout = true;
  1930. internalRunDescendentsLayout(container);
  1931. runningLayout = false;
  1932. }
  1933. /**
  1934. * This will cause re-layouting of all components. Mainly used for
  1935. * development. Published to JavaScript.
  1936. */
  1937. public void forceLayout() {
  1938. Duration duration = new Duration();
  1939. layoutManager.forceLayout();
  1940. VConsole.log("forceLayout in " + duration.elapsedMillis() + " ms");
  1941. }
  1942. private void internalRunDescendentsLayout(HasWidgets container) {
  1943. // getConsole().log(
  1944. // "runDescendentsLayout(" + Util.getSimpleName(container) + ")");
  1945. final Iterator<Widget> childWidgets = container.iterator();
  1946. while (childWidgets.hasNext()) {
  1947. final Widget child = childWidgets.next();
  1948. if (getConnectorMap().isConnector(child)) {
  1949. if (handleComponentRelativeSize(child)) {
  1950. /*
  1951. * Only need to propagate event if "child" has a relative
  1952. * size
  1953. */
  1954. if (child instanceof ContainerResizedListener) {
  1955. ((ContainerResizedListener) child).iLayout();
  1956. }
  1957. if (child instanceof HasWidgets) {
  1958. final HasWidgets childContainer = (HasWidgets) child;
  1959. internalRunDescendentsLayout(childContainer);
  1960. }
  1961. }
  1962. } else if (child instanceof HasWidgets) {
  1963. // propagate over non Paintable HasWidgets
  1964. internalRunDescendentsLayout((HasWidgets) child);
  1965. }
  1966. }
  1967. }
  1968. /**
  1969. * Converts relative sizes into pixel sizes.
  1970. *
  1971. * @param child
  1972. * @return true if the child has a relative size
  1973. */
  1974. private boolean handleComponentRelativeSize(ComponentConnector paintable) {
  1975. return false;
  1976. }
  1977. /**
  1978. * Converts relative sizes into pixel sizes.
  1979. *
  1980. * @param child
  1981. * @return true if the child has a relative size
  1982. */
  1983. public boolean handleComponentRelativeSize(Widget widget) {
  1984. return handleComponentRelativeSize(connectorMap.getConnector(widget));
  1985. }
  1986. @Deprecated
  1987. public ComponentConnector getPaintable(UIDL uidl) {
  1988. // Non-component connectors shouldn't be painted from legacy connectors
  1989. return (ComponentConnector) getConnector(uidl.getId(),
  1990. Integer.parseInt(uidl.getTag()));
  1991. }
  1992. /**
  1993. * Get either an existing ComponentConnector or create a new
  1994. * ComponentConnector with the given type and id.
  1995. *
  1996. * If a ComponentConnector with the given id already exists, returns it.
  1997. * Otherwise creates and registers a new ComponentConnector of the given
  1998. * type.
  1999. *
  2000. * @param connectorId
  2001. * Id of the paintable
  2002. * @param connectorType
  2003. * Type of the connector, as passed from the server side
  2004. *
  2005. * @return Either an existing ComponentConnector or a new ComponentConnector
  2006. * of the given type
  2007. */
  2008. public ServerConnector getConnector(String connectorId, int connectorType) {
  2009. if (!connectorMap.hasConnector(connectorId)) {
  2010. return createAndRegisterConnector(connectorId, connectorType);
  2011. }
  2012. return connectorMap.getConnector(connectorId);
  2013. }
  2014. /**
  2015. * Creates a new ServerConnector with the given type and id.
  2016. *
  2017. * Creates and registers a new ServerConnector of the given type. Should
  2018. * never be called with the connector id of an existing connector.
  2019. *
  2020. * @param connectorId
  2021. * Id of the new connector
  2022. * @param connectorType
  2023. * Type of the connector, as passed from the server side
  2024. *
  2025. * @return A new ServerConnector of the given type
  2026. */
  2027. private ServerConnector createAndRegisterConnector(String connectorId,
  2028. int connectorType) {
  2029. // Create and register a new connector with the given type
  2030. ServerConnector p = widgetSet.createConnector(connectorType,
  2031. configuration);
  2032. connectorMap.registerConnector(connectorId, p);
  2033. p.doInit(connectorId, this);
  2034. return p;
  2035. }
  2036. /**
  2037. * Gets a recource that has been pre-loaded via UIDL, such as custom
  2038. * layouts.
  2039. *
  2040. * @param name
  2041. * identifier of the resource to get
  2042. * @return the resource
  2043. */
  2044. public String getResource(String name) {
  2045. return resourcesMap.get(name);
  2046. }
  2047. /**
  2048. * Singleton method to get instance of app's context menu.
  2049. *
  2050. * @return VContextMenu object
  2051. */
  2052. public VContextMenu getContextMenu() {
  2053. if (contextMenu == null) {
  2054. contextMenu = new VContextMenu();
  2055. DOM.setElementProperty(contextMenu.getElement(), "id",
  2056. "PID_VAADIN_CM");
  2057. }
  2058. return contextMenu;
  2059. }
  2060. /**
  2061. * Translates custom protocols in UIDL URI's to be recognizable by browser.
  2062. * All uri's from UIDL should be routed via this method before giving them
  2063. * to browser due URI's in UIDL may contain custom protocols like theme://.
  2064. *
  2065. * @param uidlUri
  2066. * Vaadin URI from uidl
  2067. * @return translated URI ready for browser
  2068. */
  2069. public String translateVaadinUri(String uidlUri) {
  2070. if (uidlUri == null) {
  2071. return null;
  2072. }
  2073. if (uidlUri.startsWith("theme://")) {
  2074. final String themeUri = configuration.getThemeUri();
  2075. if (themeUri == null) {
  2076. VConsole.error("Theme not set: ThemeResource will not be found. ("
  2077. + uidlUri + ")");
  2078. }
  2079. uidlUri = themeUri + uidlUri.substring(7);
  2080. }
  2081. if (uidlUri.startsWith(ApplicationConstants.CONNECTOR_PROTOCOL_PREFIX)) {
  2082. // getAppUri *should* always end with /
  2083. // substring *should* always start with / (connector:///foo.bar
  2084. // without connector://)
  2085. uidlUri = ApplicationConstants.APP_PROTOCOL_PREFIX
  2086. + ApplicationConstants.CONNECTOR_RESOURCE_PREFIX
  2087. + uidlUri
  2088. .substring(ApplicationConstants.CONNECTOR_PROTOCOL_PREFIX
  2089. .length());
  2090. // Let translation of app:// urls take care of the rest
  2091. }
  2092. if (uidlUri.startsWith(ApplicationConstants.APP_PROTOCOL_PREFIX)) {
  2093. String relativeUrl = uidlUri
  2094. .substring(ApplicationConstants.APP_PROTOCOL_PREFIX
  2095. .length());
  2096. if (getConfiguration().usePortletURLs()) {
  2097. // Should put path in v-resourcePath parameter and append query
  2098. // params to base portlet url
  2099. String[] parts = relativeUrl.split("\\?", 2);
  2100. String path = parts[0];
  2101. String url = getConfiguration().getPortletResourceUrl();
  2102. // If there's a "?" followed by something, append it as a query
  2103. // string to the base URL
  2104. if (parts.length > 1) {
  2105. String appUrlParams = parts[1];
  2106. url = addGetParameters(url, appUrlParams);
  2107. }
  2108. if (!path.startsWith("/")) {
  2109. path = '/' + path;
  2110. }
  2111. String pathParam = ApplicationConstants.V_RESOURCE_PATH + "="
  2112. + URL.encodeQueryString(path);
  2113. url = addGetParameters(url, pathParam);
  2114. uidlUri = url;
  2115. } else {
  2116. uidlUri = getAppUri() + relativeUrl;
  2117. }
  2118. }
  2119. return uidlUri;
  2120. }
  2121. /**
  2122. * Gets the URI for the current theme. Can be used to reference theme
  2123. * resources.
  2124. *
  2125. * @return URI to the current theme
  2126. */
  2127. public String getThemeUri() {
  2128. return configuration.getThemeUri();
  2129. }
  2130. /**
  2131. * Listens for Notification hide event, and redirects. Used for system
  2132. * messages, such as session expired.
  2133. *
  2134. */
  2135. private class NotificationRedirect implements VNotification.EventListener {
  2136. String url;
  2137. NotificationRedirect(String url) {
  2138. this.url = url;
  2139. }
  2140. @Override
  2141. public void notificationHidden(HideEvent event) {
  2142. redirect(url);
  2143. }
  2144. }
  2145. /* Extended title handling */
  2146. private final VTooltip tooltip = new VTooltip(this);
  2147. private ConnectorMap connectorMap = GWT.create(ConnectorMap.class);
  2148. protected String getUidlSecurityKey() {
  2149. return uidlSecurityKey;
  2150. }
  2151. /**
  2152. * Use to notify that the given component's caption has changed; layouts may
  2153. * have to be recalculated.
  2154. *
  2155. * @param component
  2156. * the Paintable whose caption has changed
  2157. */
  2158. public void captionSizeUpdated(Widget widget) {
  2159. componentCaptionSizeChanges.add(widget);
  2160. }
  2161. /**
  2162. * Gets the main view
  2163. *
  2164. * @return the main view
  2165. */
  2166. public RootConnector getRootConnector() {
  2167. return rootConnector;
  2168. }
  2169. /**
  2170. * Gets the {@link ApplicationConfiguration} for the current application.
  2171. *
  2172. * @see ApplicationConfiguration
  2173. * @return the configuration for this application
  2174. */
  2175. public ApplicationConfiguration getConfiguration() {
  2176. return configuration;
  2177. }
  2178. /**
  2179. * Checks if there is a registered server side listener for the event. The
  2180. * list of events which has server side listeners is updated automatically
  2181. * before the component is updated so the value is correct if called from
  2182. * updatedFromUIDL.
  2183. *
  2184. * @param paintable
  2185. * The connector to register event listeners for
  2186. * @param eventIdentifier
  2187. * The identifier for the event
  2188. * @return true if at least one listener has been registered on server side
  2189. * for the event identified by eventIdentifier.
  2190. * @deprecated Use {@link ComponentState#hasEventListener(String)} instead
  2191. */
  2192. @Deprecated
  2193. public boolean hasEventListeners(ComponentConnector paintable,
  2194. String eventIdentifier) {
  2195. return paintable.hasEventListener(eventIdentifier);
  2196. }
  2197. /**
  2198. * Adds the get parameters to the uri and returns the new uri that contains
  2199. * the parameters.
  2200. *
  2201. * @param uri
  2202. * The uri to which the parameters should be added.
  2203. * @param extraParams
  2204. * One or more parameters in the format "a=b" or "c=d&e=f". An
  2205. * empty string is allowed but will not modify the url.
  2206. * @return The modified URI with the get parameters in extraParams added.
  2207. */
  2208. public static String addGetParameters(String uri, String extraParams) {
  2209. if (extraParams == null || extraParams.length() == 0) {
  2210. return uri;
  2211. }
  2212. // RFC 3986: The query component is indicated by the first question
  2213. // mark ("?") character and terminated by a number sign ("#") character
  2214. // or by the end of the URI.
  2215. String fragment = null;
  2216. int hashPosition = uri.indexOf('#');
  2217. if (hashPosition != -1) {
  2218. // Fragment including "#"
  2219. fragment = uri.substring(hashPosition);
  2220. // The full uri before the fragment
  2221. uri = uri.substring(0, hashPosition);
  2222. }
  2223. if (uri.contains("?")) {
  2224. uri += "&";
  2225. } else {
  2226. uri += "?";
  2227. }
  2228. uri += extraParams;
  2229. if (fragment != null) {
  2230. uri += fragment;
  2231. }
  2232. return uri;
  2233. }
  2234. ConnectorMap getConnectorMap() {
  2235. return connectorMap;
  2236. }
  2237. @Deprecated
  2238. public void unregisterPaintable(ServerConnector p) {
  2239. System.out.println("unregisterPaintable (unnecessarily) called for "
  2240. + Util.getConnectorString(p));
  2241. // connectorMap.unregisterConnector(p);
  2242. }
  2243. /**
  2244. * Get VTooltip instance related to application connection
  2245. *
  2246. * @return VTooltip instance
  2247. */
  2248. public VTooltip getVTooltip() {
  2249. return tooltip;
  2250. }
  2251. /**
  2252. * Method provided for backwards compatibility. Duties previously done by
  2253. * this method is now handled by the state change event handler in
  2254. * AbstractComponentConnector. The only function this method has is to
  2255. * return true if the UIDL is a "cached" update.
  2256. *
  2257. * @param component
  2258. * @param uidl
  2259. * @param manageCaption
  2260. * @return
  2261. */
  2262. @Deprecated
  2263. public boolean updateComponent(Widget component, UIDL uidl,
  2264. boolean manageCaption) {
  2265. ComponentConnector connector = getConnectorMap()
  2266. .getConnector(component);
  2267. if (!AbstractComponentConnector.isRealUpdate(uidl)) {
  2268. return true;
  2269. }
  2270. if (!manageCaption) {
  2271. VConsole.error(Util.getConnectorString(connector)
  2272. + " called updateComponent with manageCaption=false. The parameter was ignored - override delegateCaption() to return false instead. It is however not recommended to use caption this way at all.");
  2273. }
  2274. return false;
  2275. }
  2276. @Deprecated
  2277. public boolean hasEventListeners(Widget widget, String eventIdentifier) {
  2278. return hasEventListeners(getConnectorMap().getConnector(widget),
  2279. eventIdentifier);
  2280. }
  2281. LayoutManager getLayoutManager() {
  2282. return layoutManager;
  2283. }
  2284. public SerializerMap getSerializerMap() {
  2285. return serializerMap;
  2286. }
  2287. }