123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- /*
- @ITMillApache2LicenseForJavaFiles@
- */
- package com.vaadin.terminal.gwt.client;
-
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
-
- import com.google.gwt.core.client.GWT;
- import com.google.gwt.core.client.JavaScriptObject;
- import com.google.gwt.core.client.JsArrayString;
- import com.vaadin.terminal.gwt.client.ui.VUnknownComponent;
-
- public class ApplicationConfiguration {
-
- // can only be inited once, to avoid multiple-entrypoint-problem
- private static WidgetSet initedWidgetSet;
-
- private String id;
- private String themeUri;
- private String pathInfo;
- private String appUri;
- private JavaScriptObject versionInfo;
- private String windowName;
- private String communicationErrorCaption;
- private String communicationErrorMessage;
- private String communicationErrorUrl;
- private boolean useDebugIdInDom = true;
- private boolean usePortletURLs = false;
- private String portletUidlURLBase;
-
- private HashMap<String, String> unknownComponents;
-
- private Class<? extends Paintable>[] classes = new Class[1024];
-
- private String windowId;
-
- private static ArrayList<ApplicationConnection> unstartedApplications = new ArrayList<ApplicationConnection>();
- private static ArrayList<ApplicationConnection> runningApplications = new ArrayList<ApplicationConnection>();
-
- public boolean usePortletURLs() {
- return usePortletURLs;
- }
-
- public String getPortletUidlURLBase() {
- return portletUidlURLBase;
- }
-
- public String getRootPanelId() {
- return id;
- }
-
- /**
- * Gets the application base URI. Using this other than as the download
- * action URI can cause problems in Portlet 2.0 deployments.
- *
- * @return application base URI
- */
- public String getApplicationUri() {
- return appUri;
- }
-
- public String getPathInfo() {
- return pathInfo;
- }
-
- public String getThemeUri() {
- return themeUri;
- }
-
- public void setAppId(String appId) {
- id = appId;
- }
-
- public void setInitialWindowName(String name) {
- windowName = name;
- }
-
- public String getInitialWindowName() {
- return windowName;
- }
-
- public JavaScriptObject getVersionInfoJSObject() {
- return versionInfo;
- }
-
- public String getCommunicationErrorCaption() {
- return communicationErrorCaption;
- }
-
- public String getCommunicationErrorMessage() {
- return communicationErrorMessage;
- }
-
- public String getCommunicationErrorUrl() {
- return communicationErrorUrl;
- }
-
- private native void loadFromDOM()
- /*-{
-
- var id = this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::id;
- if($wnd.vaadin.vaadinConfigurations && $wnd.vaadin.vaadinConfigurations[id]) {
- var jsobj = $wnd.vaadin.vaadinConfigurations[id];
- var uri = jsobj.appUri;
- if(uri != null && uri[uri.length -1] != "/") {
- uri = uri + "/";
- }
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::appUri = uri;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::pathInfo = jsobj.pathInfo;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::themeUri = jsobj.themeUri;
- if(jsobj.windowName) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::windowName = jsobj.windowName;
- }
- if('useDebugIdInDom' in jsobj && typeof(jsobj.useDebugIdInDom) == "boolean") {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::useDebugIdInDom = jsobj.useDebugIdInDom;
- }
- if(jsobj.versionInfo) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo = jsobj.versionInfo;
- }
- if(jsobj.comErrMsg) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorCaption = jsobj.comErrMsg.caption;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorMessage = jsobj.comErrMsg.message;
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::communicationErrorUrl = jsobj.comErrMsg.url;
- }
- if (jsobj.usePortletURLs) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::usePortletURLs = jsobj.usePortletURLs;
- }
- if (jsobj.portletUidlURLBase) {
- this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::portletUidlURLBase = jsobj.portletUidlURLBase;
- }
- } else {
- $wnd.alert("Vaadin app failed to initialize: " + this.id);
- }
-
- }-*/;
-
- /**
- * Inits the ApplicationConfiguration by reading the DOM and instantiating
- * ApplicationConnections accordingly. Call {@link #startNextApplication()}
- * to actually start the applications.
- *
- * @param widgetset
- * the widgetset that is running the apps
- */
- public static void initConfigurations(WidgetSet widgetset) {
- String wsname = widgetset.getClass().getName();
- String module = GWT.getModuleName();
- int lastdot = module.lastIndexOf(".");
- String base = module.substring(0, lastdot);
- String simpleName = module.substring(lastdot + 1);
-
- if (initedWidgetSet != null) {
- // Multiple widgetsets inited; can happen with custom WS + entry
- // point
- String msg = "Ignoring " + widgetset.getClass().getName()
- + ", because " + initedWidgetSet.getClass().getName()
- + " was already inited (if this is wrong, your entry point"
- + " is probably not first your .gwt.xml).";
- throw new IllegalStateException(msg);
- }
- initedWidgetSet = widgetset;
- ArrayList<String> appIds = new ArrayList<String>();
- loadAppIdListFromDOM(appIds);
-
- for (Iterator<String> it = appIds.iterator(); it.hasNext();) {
- String appId = it.next();
- ApplicationConfiguration appConf = getConfigFromDOM(appId);
- ApplicationConnection a = new ApplicationConnection(widgetset,
- appConf);
- unstartedApplications.add(a);
- }
- }
-
- /**
- * Starts the next unstarted application. The WidgetSet should call this
- * once to start the first application; after that, each application should
- * call this once it has started. This ensures that the applications are
- * started synchronously, which is neccessary to avoid session-id problems.
- *
- * @return true if an unstarted application was found
- */
- public static boolean startNextApplication() {
- if (unstartedApplications.size() > 0) {
- ApplicationConnection a = unstartedApplications.remove(0);
- a.start();
- runningApplications.add(a);
- return true;
- } else {
- return false;
- }
- }
-
- public static List<ApplicationConnection> getRunningApplications() {
- return runningApplications;
- }
-
- private native static void loadAppIdListFromDOM(ArrayList<String> list)
- /*-{
- var j;
- for(j in $wnd.vaadin.vaadinConfigurations) {
- list.@java.util.Collection::add(Ljava/lang/Object;)(j);
- }
- }-*/;
-
- public static ApplicationConfiguration getConfigFromDOM(String appId) {
- ApplicationConfiguration conf = new ApplicationConfiguration();
- conf.setAppId(appId);
- conf.loadFromDOM();
- return conf;
- }
-
- public native String getServletVersion()
- /*-{
- return this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo.vaadinVersion;
- }-*/;
-
- public native String getApplicationVersion()
- /*-{
- return this.@com.vaadin.terminal.gwt.client.ApplicationConfiguration::versionInfo.applicationVersion;
- }-*/;
-
- public boolean useDebugIdInDOM() {
- return useDebugIdInDom;
- }
-
- public Class<? extends Paintable> getWidgetClassByEncodedTag(String tag) {
- try {
- int parseInt = Integer.parseInt(tag);
- return classes[parseInt];
- } catch (Exception e) {
- // component was not present in mappings
- return VUnknownComponent.class;
- }
- }
-
- public void addComponentMappings(ValueMap valueMap, WidgetSet widgetSet) {
- JsArrayString keyArray = valueMap.getKeyArray();
- for (int i = 0; i < keyArray.length(); i++) {
- String key = keyArray.get(i).intern();
- int value = valueMap.getInt(key);
- classes[value] = widgetSet.getImplementationByClassName(key);
- if (classes[value] == VUnknownComponent.class) {
- if (unknownComponents == null) {
- unknownComponents = new HashMap<String, String>();
- }
- unknownComponents.put("" + value, key);
- } else if (key == "com.vaadin.ui.Window") {
- windowId = "" + value;
- }
- }
- }
-
- /**
- * @return the integer value that is used to code top level windows
- * "com.vaadin.ui.Window"
- */
- String getEncodedWindowTag() {
- return windowId;
- }
-
- String getUnknownServerClassNameByEncodedTagName(String tag) {
- if (unknownComponents != null) {
- return unknownComponents.get(tag);
- }
- return null;
- }
- }
|