/*
	Author: Stephen W. Cote
	Email: wranlon@hotmail.com
	
	Copyright 2002, All Rights Reserved.
	
	Do not copy, archive, or distribute without prior written consent of the author.
	
*/

/*
	ApplicationDriver performs three basic tasks:
		- publishes a notification when the browser window loads
		- publishes a notification when the browser window unloads
		- stores global configuration
*/

_js_package("org.cote.js.util.driver");
org.cote.js.util.driver={
	ApplicationDriver:null,
	ApplicationDriverImpl:function(){
		var t=this,_j=org.cote.js,_x=org.cote.js.xml,_m=org.cote.js.message.MessageService;

		org.cote.js._implements(t,"base_object","application_driver","0.1a");

		t.object_config={
			status:{
				driver_loaded:0,
				driver_name:null,
				config_loaded:0,
				application_loaded:0,
				application_ui_ready:0,
				window_loaded:0
			}
		};

		t.application_config={
		
		};
		t._terminate=function(){
			_m.publish("destroy",window);
		};
		t._handle_window_unload=function(){
			/*
				handling the window unload event is done to reduce the possibility
				of errors, and also to propogate a destroy event to all objects.
				
				In order for this propogation to be effective, and for potential
				errors be squashed, the event_delay on the eventfactory is set to 0.
			*/

			_j._application_scope._send_sigterm();
			
			this._terminate();
		};


		t._handle_window_load=function(){
			t.object_config.status.window_loaded=1;
			
			/*
				This just propogates the window onload event back to
				any other component that cares to know, such as the TaskService.
				
				There is less impact than using an anonymous function to wrap
				the object instance.
			*/
			
			_m.publish("dom_event_window_load",this);
		};

		/*
			Add event buffer was designed for DOM events as a way
			of creating instance-specific handlers.
		*/

		org.cote.js.dom.event._add_event_buffer(t);

		t._create_handler("window_load",0,0,1);
		t._create_handler("window_unload",0,0,1);

		org.cote.js._application_scope.add_object(t);

		_j.dom.event.addEventListener(window,"unload",t._prehandle_window_unload);
		_j.dom.event.addEventListener(window,"load",t._prehandle_window_load);
	}

};

/* Create a new application driver */
org.cote.js.util.driver.ApplicationDriver=new org.cote.js.util.driver.ApplicationDriverImpl();

