Eclipse Tutorial

Download Report

Transcript Eclipse Tutorial

CMI 1.0 tutorial in
Eclipse
March 7 2006
CS509
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
ComputeController
GUIBased (Execute this class)
Processor
TextBased (Execute this class)
UML highlights
<<interface>>
IAgent
ComputeController
#agent: IAgent
#proc: Processor
+getN()
+getM()
+putResult(int)
GUIBased
Processor
+int compute(int, int)
+void compute()
TextBased
gui : GUIBased
c : ComputeController
p : Processor
: User
1 : Press Compute Button()
2 : void compute()
3 : getM()
Perform Computation
4 : getN()
User
6 : putResult()
5 : int compute()
CBSE Industries
► Third
party development
 GUIBased and TextBased
 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
“oldCMI”
and press
Finish
Will
appear
under
your
package
explorer in
Eclipse
“File  Import …”
First
Select
project
“oldCMI”
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
oldCMITutorial.zip
Click Finish
Run the Demonstration
Browse to the File oldCMI: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 <scriptsDir> <storageDir> <blocksDir>
<scriptsDir> is directory where scripts are located.
<storageDir> is directory for persistentStorage.
<blocksDir> 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
ICalc
Calc
Load class from tutorial.jar
Create new instance
Foundation
Load class from calc.jar
Create new instance
Connect
Input
ICalc
ICalc
Calc
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
Calc
activate
activate
Foundation
Deactivate
ICalc
Input
ICalc
Calc
deactivate
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 FirstTry in tutorial for example
► deactivate()
 What to do when application is done? Often
Methods for IBlock component
(cont)
► getProvided()
 Return those interfaces provided by this
component. Never return null but rather an
empty Enumeration
► getRequired()
 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 interfaceName) { return false; }
public void deactivate() {}
public Enumeration getProvided() {
Vector v = new Vector();
v.add (ICalc.class.getName());
return v.elements();
}
public Enumeration getRequired() {
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 JarDesc 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.FirstTry from tutorial.jar as Input
► Now
re-launch Foundation
Reading Scripts from scripts
Connect Successful
Storage Directory: C:\Documents and Settings\George\workspace\S07\storage
Trying to load: two.Adder
Trying to load: tutorial.FirstTry
FirstTry: 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.