CMI 1 0 tutorial in Eclipse March 7



























- Slides: 27

CMI 1. 0 tutorial in Eclipse March 7 2006 CS 509

Preliminaries ► Moving away from strict Object-Oriented solutions ► Goal is to have full Component-Based Software Engineering § Many assumptions are going to change § Need new development processes

Sample OO example ► Problem: Read two numbers from user and compute their product § Divide into: (a) user interface; (b) processing ► Grab code from Examples_2007/modular § Compute. Controller § GUIBased (Execute this class) § Processor § Text. Based (Execute this class)

UML highlights

CBSE Industries ► Third party development § GUIBased and Text. Based § Processor ► Neither should know of the other § Not possible for GUIBased to instantiate Processor § Need standard solution ► Deployment becomes an issue § In the same way that JDK 1. 5 is deployed

Select “File New Project” Then select Java Project

Enter Project Name Enter “old. CMI” and press Finish Will appear under your package explorer in Eclipse

“File Import …” First Select project “old. CMI” Then from File menu select Import … Select Archive file (or Zip file if that is presented to you)

Browse to ZIP location Click on “Browse…” to locate the file old. CMITutorial. zip Click Finish

Run the Demonstration Browse to the File old. CMI: oldcmi: Foundation. java Right Click the mouse on the file Foundation. java and select menu item Debug As Java Application

You will see usage information Usage: java oldcmi. Foundation <scripts. Dir> <storage. Dir> <blocks. Dir> <scripts. Dir> is directory where scripts are located. <storage. Dir> is directory for persistent. Storage. <blocks. Dir> is directory where block. jar files exist. Select menu Run Debug … and you will see something like the following Foundation will be selected. Click on the “arguments” tab.

Enter arguments to application Enter “scripts storage blocks” exactly in the Program Arguments window. Then click on the Debug button at the bottom.

Proper Execution should occur Enter in 2 numbers separated by a space and the program will multiply them together. Enter “-1 – 1” to exit.

CMI 1. 0 in a nutshell ►A technology that enables independentlydeveloped components to communicate with each other ► Relies on Foundation container that manages the lifecycle of the components

CMI 1. 0 Component Life Cycle ► Instantiate § More comprehensive and powerful than new ► Connect § Enable components to communicate with each other via standardized (and versioned!) interfaces ► Activate § Rudimentary control flow ► Deactivate § What happens when application is done

Instantiate Input ICalc Load class from tutorial. jar Create new instance Foundation Load class from calc. jar Create new instance

Connect Input ICalc connect (IBlock b, String iname) Have Input connect to Calc on ICalc interface. Why? Because Input Requires some component through the ICalc interface. Foundation

Activate ICalc Input ICalc activate Foundation

Deactivate ICalc Input ICalc deactivate Foundation

Tutorial Phase Two ► Develop a second Calculator component that adds the numbers instead 1. 2. 3. 4. 5. Develop Block Template Fill in ‘add’ computation Package & Deploy Modify Instantiation Scripts Execute

1. Develop Block Template ► In the Eclipse project for the CMI 1. 0 tutorial § Create new package (I call it two) § Within this package create a new class that implements IBlock ►Click on “Add …” to locate IBlock interface ►Once done, click Finish

Methods for IBlock component ► activate() § Initiate the execution of component at run-time; note that this must return true, otherwise Foundation will assume failure ► connect (IBlock, String) § If component has external dependency, it can only be fulfilled by having an external component satisfy it. The component is responsible for storing this reference for later use; see First. Try in tutorial for example ► deactivate() § What to do when application is done? Often

Methods for IBlock component (cont) ► get. Provided() § Return those interfaces provided by this component. Never return null but rather an empty Enumeration ► get. Required() § Return required interfaces. Never return null but rather an empty Enumeration ► Default Constructor() § Each Block component must have a default noargument constructor for Foundation to instantiate it.

Full Implementation for Adder package two; import ifaces. ICalc; import java. util. Enumeration; import java. util. Vector; import oldcmi. interfaces. IBlock; public class Adder implements IBlock, ICalc { public boolean activate() { return true; } public boolean connect(IBlock obj, String interface. Name) { return false; } public void deactivate() {} public Enumeration get. Provided() { Vector v = new Vector(); v. add (ICalc. class. get. Name()); return v. elements(); } public Enumeration get. Required() { return new Vector(). elements(); } public int compute (int a, int b) { return a+b; } }

Deploy Adder Component ► Create JAR file within blocks/ directory § Right-click ‘two’ package and select “Export …” Make sure that you select the ‘ifaces’’ package as well as the ‘two’ package. Make sure that JAR file is located within the blocks/ directory. Then click Next

Deploy Adder Component ► Create (cont) the Jar. Desc file within two package. § Then click “Finish”. Note how ‘adder. jar’ file appears in blocks/ directory

Rewrite “Application” scripts ► Modify instantiate. scr in scripts/ directory ; here we put a list of commands to instantiate components we are going to ; use instantiate two. Adder from adder. jar as Calc instantiate tutorial. First. Try from tutorial. jar as Input ► Now re-launch Foundation Reading Scripts from scripts Connect Successful Storage Directory: C: Documents and SettingsGeorgeworkspaceS 07storage Trying to load: two. Adder Trying to load: tutorial. First. Try: Enter two numbers, separated by a space and press return. I will perform a computation on them. enter "-1 -1" to stop. 6 7 compute(6, 7) = 13 -1 -1 Program stopped.