<application-components>

	<!--
	
		The "_handle_[event]" syntax is static.
		The event list is specified as a configurable property in the Engine SDK.

	-->
	
	<!--
		ac_destroy = handle click event to destroy component
	-->
	<application-component id = "ac_destroy">
		<![CDATA[
			component_init:function(){
				var oM = org.cote.js.message.MessageService;
				oM.sendMessage("Component Init","200.4");
			},
			_handle_click:function(){

				var oComp = org.cote.js.registry.ObjectRegistry.getObject("demo_component");
				var oM = org.cote.js.message.MessageService;
				if(!oComp){
					oM.sendMessage("Invalid Component","200.4");
					return 0;
				}
				oM.sendMessage("Invoke [component].destroy()","200.3");
				oComp.destroy();
	
				return 1;

			}
		]]>
	</application-component>

	<!--
		ac_load = handle click event to load component
	-->
	<application-component id = "ac_load">
		<![CDATA[	
			_handle_click:function(){

				var CAppComp = org.cote.js.appcomp.ApplicationComponent;
				var oComp = CAppComp.newInstance("demo_component");
				/*
					I guess the obviously lame thing here is that you have to reference the path to the xml
					file even while operating in the context of the xml file.
					
					But, as long as it is cached by the xml utility, it's not that big of a deal.
				*/
				oComp.loadComponent("communique","/projects/engine/demonstrations/demonstration_11/application_components.xml");

			}
		]]>
	</application-component>

	<!--
		communique = threaded component with no UI element.
	-->
	<application-component id = "communique">
		<![CDATA[	

			component_init:function(){
				var oMS = org.cote.js.message.MessageService;

				oMS.sendMessage("Component Init was invoked","200.3");

				var oThread = org.cote.js.thread.newInstance(this);

				var oThread2 = org.cote.js.thread.newInstance(this);

				org.cote.js.message.MessageService.sendMessage("Thread #1 = " + oThread.getObjectId() + " created on " + oThread.o.s.z,"200.1");
//				org.cote.js.message.MessageService.sendMessage("Thread #2 = " + oThread2.getObjectId() + " created on " + oThread2.o.s.z,"200.1");
//				alert(org.cote.js.message.MessageService.debugPublish("onremoveobject","foo"));
				oThread.run();

//				oThread2.run(400);

			},

			component_destroy:function(){
				org.cote.js.message.MessageService.sendMessage("Component Destroy was invoked","200.3");
			},
			handle_thread_start:function(thread_object){
				org.cote.js.message.MessageService.sendMessage("Thread " + thread_object.getObjectId() + " was started","200.3");
			},
			handle_thread_run:function(thread_object){
				org.cote.js.message.MessageService.sendMessage("Thread " + thread_object.getObjectId() + " is running","200.3");
			},
			handle_thread_stop:function(thread_object){
				org.cote.js.message.MessageService.sendMessage("Thread " + thread_object.getObjectId() + " was stopped","200.3");
			}
			
		]]>
	</application-component>	

</application-components>

