package cadena;

public class Scenario{
	public static void main(String[] args) throws Exception {
		org.omg.Components.CCMHome ccmhome;
		// Init the ORB.
		System.out.println("Initializing the ORB...");
		// Init the OpenCCM Components Runtime.
		org.omg.CORBA.ORB corbaorb = org.objectweb.ccm.Components.Runtime.init(args);

		// Obtain the Name Service.
		System.out.println("Obtaining the Name Service...");
		org.omg.CORBA.Object corbaobj = corbaorb.resolve_initial_references("NameService");
		org.omg.CosNaming.NamingContext namingContext = org.omg.CosNaming.NamingContextHelper.narrow(corbaobj);

		// Obtain the component servers.
		System.out.println("Obtaining Component Servers...");
		org.omg.CosNaming.NameComponent[] nameComponent = new org.omg.CosNaming.NameComponent[1];
		nameComponent[0] = new org.omg.CosNaming.NameComponent("Board1","");
		corbaobj = namingContext.resolve(nameComponent);
		org.objectweb.ccm.Deployment.Server board1_server =
		org.objectweb.ccm.Deployment.ServerHelper.narrow(corbaobj);

		nameComponent[0].id = "Board2";
		corbaobj = namingContext.resolve(nameComponent);
		org.objectweb.ccm.Deployment.Server board2_server =
		org.objectweb.ccm.Deployment.ServerHelper.narrow(corbaobj);

		nameComponent[0].id = "Board3";
		corbaobj = namingContext.resolve(nameComponent);
		org.objectweb.ccm.Deployment.Server board3_server =
		org.objectweb.ccm.Deployment.ServerHelper.narrow(corbaobj);


		// Obtain the container homes.
		org.omg.Components.Deployment.ComponentServer board1_cs = 
		board1_server.provide_component_server();
		org.omg.Components.Deployment.ComponentServer board2_cs = 
		board2_server.provide_component_server();
		org.omg.Components.Deployment.ComponentServer board3_cs = 
		board3_server.provide_component_server();

		//Install archives.
		System.out.println("Installing archives...");
		org.omg.Components.Deployment.ComponentInstallation board1_inst = 
		board1_server.provide_install();
		board1_inst.install("basicsp", "./archives/basicsp.jar");
		board1_inst.install("openccm_plugins", "./OpenCCM_Plugins.jar");
		org.omg.Components.Deployment.ComponentInstallation board2_inst = 
		board2_server.provide_install();
		board2_inst.install("basicsp", "./archives/basicsp.jar");
		board2_inst.install("openccm_plugins", "./OpenCCM_Plugins.jar");
		org.omg.Components.Deployment.ComponentInstallation board3_inst = 
		board3_server.provide_install();
		board3_inst.install("basicsp", "./archives/basicsp.jar");
		board3_inst.install("openccm_plugins", "./OpenCCM_Plugins.jar");

		org.omg.Components.Deployment.Container board1_cont =
			board1_cs.create_container(new org.omg.Components.ConfigValue[0]);

		org.omg.Components.Deployment.Container board2_cont =
			board2_cs.create_container(new org.omg.Components.ConfigValue[0]);

		org.omg.Components.Deployment.Container board3_cont =
			board3_cs.create_container(new org.omg.Components.ConfigValue[0]);

		System.out.println("Instantiating homes, components...");
		ccmhome = board1_cont.install_home("basicsp", "cadena.common.EventChannelHomeImpl.create_home",
 		new org.omg.Components.ConfigValue[0]);
		cadena.common.EventChannelHome eventchannelBoard1Home = cadena.common.EventChannelHomeHelper.narrow(ccmhome);
		cadena.common.EventChannel eventchannel = eventchannelBoard1Home.create();
		ccmhome = board1_cont.install_home("basicsp", "cadena.common.BMDeviceHomeImpl.create_home",
 		new org.omg.Components.ConfigValue[0]);
		cadena.common.BMDeviceHome bmdeviceBoard1Home = cadena.common.BMDeviceHomeHelper.narrow(ccmhome);
		cadena.common.BMDevice gps = bmdeviceBoard1Home.create();
		ccmhome = board2_cont.install_home("basicsp", "cadena.common.BMClosedEDHomeImpl.create_home",
 		new org.omg.Components.ConfigValue[0]);
		cadena.common.BMClosedEDHome bmclosededBoard2Home = cadena.common.BMClosedEDHomeHelper.narrow(ccmhome);
		cadena.common.BMClosedED airframe = bmclosededBoard2Home.create();
		ccmhome = board3_cont.install_home("basicsp", "cadena.common.BMDisplayHomeImpl.create_home",
 		new org.omg.Components.ConfigValue[0]);
		cadena.common.BMDisplayHome bmdisplayBoard3Home = cadena.common.BMDisplayHomeHelper.narrow(ccmhome);
		cadena.common.BMDisplay navdisplay = bmdisplayBoard3Home.create();

		System.out.println("set instance names...");
		eventchannel.name("EventChannel");
		gps.name("GPS");
		airframe.name("AirFrame");
		navdisplay.name("NavDisplay");

		System.out.println("Interconnecting components...");
		eventchannel.subscribe_timeOut20(gps.get_consumer_timeOut());
		gps.subscribe_outDataAvailable(airframe.get_consumer_inDataAvailable());
		airframe.connect_dataIn(gps.provide_dataOut());
		airframe.subscribe_outDataAvailable(navdisplay.get_consumer_inDataAvailable());
		navdisplay.connect_dataIn(airframe.provide_dataOut());

		System.out.println("Create gateways...");
		edu.ksu.cis.EventChannelAdmin.Dependency Board2_Board1_dependency[] = 
			new edu.ksu.cis.EventChannelAdmin.Dependency[1];
		Board2_Board1_dependency[0] = 
			new edu.ksu.cis.EventChannelAdmin.Dependency();
		Board2_Board1_dependency[0].header = 
			new edu.ksu.cis.EventComm.EventHeader(2, 0);
		edu.ksu.cis.EventChannelAdmin.ConsumerQOS Board2_Board1_cqos = 
			new edu.ksu.cis.EventChannelAdmin.ConsumerQOS(Board2_Board1_dependency);
		board2_cs.create_gateway("Board2.EventChannel", "Board1.EventChannel", Board2_Board1_cqos);

		edu.ksu.cis.EventChannelAdmin.Dependency Board3_Board2_dependency[] = 
			new edu.ksu.cis.EventChannelAdmin.Dependency[1];
		Board3_Board2_dependency[0] = 
			new edu.ksu.cis.EventChannelAdmin.Dependency();
		Board3_Board2_dependency[0].header = 
			new edu.ksu.cis.EventComm.EventHeader(3, 0);
		edu.ksu.cis.EventChannelAdmin.ConsumerQOS Board3_Board2_cqos = 
			new edu.ksu.cis.EventChannelAdmin.ConsumerQOS(Board3_Board2_dependency);
		board3_cs.create_gateway("Board3.EventChannel", "Board2.EventChannel", Board3_Board2_cqos);


		System.out.println("Components configuration completion...");
		eventchannel.configuration_complete();
		gps.configuration_complete();
		airframe.configuration_complete();
		navdisplay.configuration_complete();
		System.exit(0);
	}
}


syntax highlighted by Code2HTML, v. 0.9.1