You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by bb...@apache.org on 2006/11/02 22:17:46 UTC

svn commit: r470558 - in /incubator/xap/trunk/src/xap/application: ./ Application.js

Author: bbuffone
Date: Thu Nov  2 14:17:46 2006
New Revision: 470558

URL: http://svn.apache.org/viewvc?view=rev&rev=470558
Log:
I have updated the starting process of the XAP engine with the HTML page.
This changes is defined in emails from me on the 8/29.  
This changes break compatibilty with existing samples. 
To see how the new process works check out the new samples in 
the startup folder.

Added:
    incubator/xap/trunk/src/xap/application/
    incubator/xap/trunk/src/xap/application/Application.js

Added: incubator/xap/trunk/src/xap/application/Application.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/application/Application.js?view=auto&rev=470558
==============================================================================
--- incubator/xap/trunk/src/xap/application/Application.js (added)
+++ incubator/xap/trunk/src/xap/application/Application.js Thu Nov  2 14:17:46 2006
@@ -0,0 +1,139 @@
+/*
+ * Copyright  2006 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+Xap.provide("xap.application.Application");
+Xap.require("xap.util.Exception");
+Xap.require("xap.session.ClientSession");
+Xap.require("xap.util.LogFactory");
+
+/**
+ * xap.application.Application controls the creation of xap applications
+ * This class is a developer facing class to instaniation a XAP application
+ * with in a web page.
+ * @author bbuffone
+ */
+ 
+/**
+ * Configuration object
+ *
+ * applicationConfig = {
+ *	        applicationName: "myApplication",
+ *		    startPage: "index.xal",
+ *		    context: "../../",
+ *		    toolkitType: "dojo",
+ *		    element: "MyApplicationRoot",
+ *          scanPage: true,  
+ *		    debug: false,
+ *	};
+ * 
+ */
+
+//-----------------------------------------------------------------------
+// Constructors.
+//-----------------------------------------------------------------------
+xap.application.Application = function(applicationConfig) {
+	if (applicationConfig != null){
+    	this._applicationConfig = applicationConfig;  
+    }else{
+    	this._applicationConfig = {context: "../../"};  
+    }
+}
+
+/**
+ * The method creates the session and starts it. Also scans the page if the
+ * user wants to.
+ */
+xap.application.Application.prototype.create = function() {
+    //load configuration information and merge the objects.   
+    this._processConfiguration();
+    
+    //create the session   
+    if (this._applicationConfig == null){
+		throw new xap.util.Exception(" bad argument, no configuration object supplied to the Xap.createApplication", 
+		                                null, null, "xap.application.Application.prototype.create");
+    }
+       
+	if(this._applicationConfig.logging == true) {
+		xap.util.LogFactory.enableLogging()
+	} else {
+		xap.util.LogFactory.disableLogging();
+	}
+    
+    //need to make sure there is a default context supplied.
+    if (this._applicationConfig.context == null){
+    	this._applicationConfig.context = "../../";
+    }
+	this._session = new xap.session.ClientSession(this._applicationConfig.context, 
+	                                    this._applicationConfig.toolkitType, 
+	                                    this._applicationConfig.element);
+	
+    //now start the session this will retrieve the start page from the server.    
+	this._session._start(this._applicationConfig);	
+}
+
+/**
+ * Get the session object for this application 
+ */
+xap.application.Application.prototype.getSession = function() {
+	return this._session;
+}
+
+/**
+ * Get the configuration object that was used to start the application. 
+ */
+xap.application.Application.prototype.getConfiguration = function() {
+	return this._configuationObject;
+}
+
+/**
+ * Get the configuration object that was used to start the application. 
+ */
+xap.application.Application.prototype.fireEvent = function(eventString) {
+    var clientEvent = new xap.session.ClientEvent(null, this.getSession());
+	return this._session.getEventHandler().fireEvent("", eventString, null, clientEvent);
+}
+
+
+//-----------------------------------------------------------------------
+// Private Methods.
+//-----------------------------------------------------------------------
+/**
+ * Method is used to create the configration and merge the objects.
+ */
+xap.application.Application.prototype._processConfiguration = function() {
+	if (this._applicationConfig.configFilePath == null){
+		this._applicationConfig.configFilePath = this._applicationConfig.context + "XapConfig.js";
+	}
+
+	//TODO may we can remove the need for this.
+	var requestService = new xap.requestservice.RequestService( null );
+	var configString = requestService.retrieve( this._applicationConfig.configFilePath ).responseText;
+
+	if( configString && configString != null ) {
+
+	    //eval the session configuration.
+        var sessionConfiguration = eval('(' + configString + ')');
+        
+        //create a single application configuration object.
+        //Any thing that is in the not in the application config should be added.       
+		for (property in sessionConfiguration){
+		    if (!this._applicationConfig[property]){
+		        this._applicationConfig[property] = sessionConfiguration[property];
+		    }
+		}	                    
+	}
+}
+