730 likes | 939 Views
Component Models and Technology Component-based Software Engineering Ivica Crnkovic ivica.crnkovic@mdh.se. Overview. Introduction ACME Architectural Description Language Java Bean Component Model COM, DCOM, MTS and COM+ CORBA Component Model (CCM) .NET Component Model
E N D
Component Models and Technology Component-based Software Engineering Ivica Crnkovic ivica.crnkovic@mdh.se Component models
Overview • Introduction • ACME Architectural Description Language • Java Bean Component Model • COM, DCOM, MTS and COM+ • CORBA Component Model (CCM) • .NET Component Model • OSGI Component Model Component models
Architecture Definition Languages • ADLs primarily address the issues related to the early phases of software engineering: • Design • Analysis • They identify a number of concepts, such as: • Architecture, configurations, connectors, bindings, properties, hierarchical models, style, static analysis and behavior. Component models
ACME Architectural Description Language • Components and Ports • Connectors and Roles • Systems and Attachments • Representations and Bindings • Properties, Constraints, Types and Styles Component models
Components and Ports • Components • Represent the computational elements and data stores of a system. • Ports • Are the points of interaction between a component and its environment. Component Port Component models
Connectors and Roles • Connectors • Represent interactions between components such as method calls or an SQL connection between a client and a database server. • The interface of a connectoris defined as a set of roles Connector Role Component models
Systems and Attachments • The structure of a system is specified by a set of components, a set of connectors, and a set of attachments. • Attachment • Links a component port to a connector role. Attachement Component models
Representations and Bindings Component Connector Port Role Attachement Binding Component models
Component Interactions Iteractions with traditional software entities Traditional software entities Interactions with other components Interactions with other components Components Component Infrastructure Interactions with component infrastructure Component models
Terms in Components-based technologies Interface that satisfies contracts Component-type Specific interface Component implementation Independent deployment Component model Component Framework Coordination Services (transactions, persistence..) Component models
Java Bean Component Model Component models
Key Features "A Java Bean is a reusable software component that can be manipulated visually in a builder tool”. • The Java Bean was designed for the construction of graphical user interface (GUI). • Explicitly tailored to interact in two different contexts: • At composition time, within the builder tool. • At execution time, with the runtime environment. • Any Java class that adheres to certain conventions regarding property and event interface definitions can be a JavaBean. • Properties of a compiled bean can be obtained by introspection mechanism Component models
v Interface of a Component • This model defines four types of port: • methods, • properties, • event sources (generate an event) • event sinks called listeners (they receive event) Property Read-only property ro Method Write-only property wo Event source Unicast event source 1 Event sink (listener) Bounded property Vetoable property Ports Component models
Implementation of a Component • Most bean components are implemented by a simple Java object by naming convention Object Method Properties public void set<Property_name> (PropertyType value) public PropertyType get<Property_name> () Events public viod add<ListenerType> (<ListenerType> listener); public viod remove<ListenerType> (<ListenerType> listener); public class Y implements <Y>Listener { public viod <YoccuranceName> (<YObjectType> evt); } A simple implementation Component models
Component-based assembly Heterogeneous assembly Components Assembly • Assembly is one of the key features of Java Bean though no not specific solution is provided. • Composition tools (Bean Box) • No composition language • Different ways of assembling components are supplied. Component models
Packaging and Deployment • Java Beans define a model for packaging components into archives. • Includes the definition of dependency relationships between the package items. • Each package item can be marked "Design Only", so that they can be removed in a final application. Component models
An example • Example of a Cannibal bean, e.g as a part of a computer game • The Example contains: • A simple bean with a simple property and a boolean bound property • A simple test class for the bean • A class which do an introspection on the bean (similar to what a builder tool will do) showing the bean’s services, properties and events Component models
import java.beans.*; //for PropertyChangeListener class Cannibal { private String name; //r simple property private boolean saved; //rw bound boolean property //change listeners list private PropertyChangeSupport change; public Cannibal() { this("Eddy Merx", false); } public Cannibal(String n, boolean s) { name=n; saved=s; change=new PropertyChangeSupport(this); } public String getName() {//property name, get method return name; } public boolean isSaved() {//property saved, isXxx method, bound return saved; } Component models
//property saved, set method public void setSaved(boolean s) { boolean old=saved; saved=s; change.firePropertyChange( "saved", new Boolean(old), new Boolean(s) ); } //bean services //… // Property Change Listener Support Methods public synchronized void addPropertyChangeListener( PropertyChangeListener listener) { change.addPropertyChangeListener(listener); } public synchronized void removePropertyChangeListener( PropertyChangeListener listener) { change.removePropertyChangeListener(listener); } } Component models
public class Foo implements PropertyChangeListener { private Cannibal can; public static void main(String[] args) { new Foo(); } public Foo() { can=new Cannibal(); // create a Cannibal // add self to the Cannibal's listener list can.addPropertyChangeListener(this); // change the cannibal to saved can.setSaved(true); // fires property change event } public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName().equals("saved") ) { System.out.println( "The cannibal "+can.getName()+" has been converted.“ ); System.out.println("old saved status was: "+event.getOldValue()); System.out.println("new saved status is: "+event.getNewValue()); } } } Component models
Output from execution of Foo The cannibal Eddy has been converted old saved status was: false new saved status is: true Component models
import java.lang.reflect.*; public class IntrospectCannibal { public static void main(String[] args) { try { // obtain class object for class Cannibal Class classObject = Class.forName("Cannibal"); // get Constructor, Field and Method objects Constructor[] cons=classObject.getDeclaredConstructors(); Field[] fields = classObject.getDeclaredFields(); Method[] methods = classObject.getDeclaredMethods(); System.out.println("Class Cannibal"); System.out.println("\nConstructors:\n"); for (int i=0; i<cons.length; ++i) System.out.println(cons[i]); System.out.println ("\nFields:\n"); for (int i=0; i<fields.length; ++i) System.out.println(fields[i]); System.out.println("\nMethods:\n"); for (int i=0; i<methods.length; ++i) System.out.println(methods[i]); } catch(Exception e) {e.printStackTrace(System.out);} } } Component models
Output from IntrospectCannibal Class Cannibal Constructors: public Cannibal(java.lang.String,boolean) public Cannibal() Fields: private java.lang.String Cannibal.name private boolean Cannibal.saved private java.beans.PropertyChangeSupport Cannibal.change Methods: public java.lang.String Cannibal.getName() public boolean Cannibal.isSaved() public void Cannibal.setSaved(boolean) public void Cannibal.hunt(java.lang.Object) public synchronized void Cannibal.addPropertyChangeListener(java.beans.PropertyChangeListener) public synchronized void Cannibal.removePropertyChangeListener(java.beans.PropertyChangeListener) Component models
Java Remote Method Invocation (Java RMI) • RMI is an interface used over two protocols • Java Remote Method Protocol (JRMP) • Internet Inter-ORB Protocol (IIOP) JavaClient CORBAObject JavaObject RMI JRMP, IIOP Component models
Enterprise JavaBeans • Architecture for distributed applications (distributed components) • Framework for creating middleware EJB Server EJB Container EJB client Enterprise bean Clients accesses JBs via containers Component models
4. Return to client 1. Call a method 3.Return result 2. Acquire a bean and delegate thecall to the bean Calling an Enterprise Bean EJB Container/Server Client Application HomeObject EJBObject EnterpriseBean Component models
3. Return EJB Obj. Ref. 1. Create EJB Obj. 2. Create EJB Object EJBObject Creating the EJB Object EJB Container/Server Client Application HomeObject EnterpriseBean Component models
1. Retrivehomeobject 2. Return reference Java Naming and Directory Interface Client Application JNDI NamingService Component models
5. Return EJB Obj. Ref. 3. Create EJB Obj. 9. Return to client 4. Create EJB Object 1. Retrivehomeobject 2. Return reference 6. Call a method EJBObject 8.Return result 7. Acquire a bean and delegate thecall to the bean One More Time EJB Container/Server Client Application HomeObject JNDI EnterpriseBean NamingService Component models
DBMS DBMS DBMS HTTP JDBC JDBC EJBApplications JDBC RMI/IIOP Java Application Server Technologies VariousJSP Tools BrowserClient HTTPListener JSPApplications Servlets EJB RichClient VariousJavaTools Windows NT, Unix,Others Component models
J2EE (Java 2 Platform, enterprise edition) • Defines an architecture for building large scale multi-tier distributed applications • Uses standardized modular components • Provides standard services for those components • Automatically replaces many aspects of the application programming from the developer • Thinner clients Component models
J2EE architecture components • J2EE Platform Specification • Specification of the APIs to be provided • Descriptions of the support levels expected for containers, clients, and components • J2EE Sun’s Reference Implementation • Free implementation of the specified technologies, sample applications, tools, and documentation • J2EE Compatibility Test Suite • Test implementations of the platform • J2EE Sun BluePrint • Documentation, examples, and design guidelines Component models
J2EE application model • Business logic in Enterprise JavaBeans components • Client interaction presented through different technologies • Plain Html • Java applets • Java servlets • JSP • Components communicates transparently using different standards • Html • XML • RMI Component models
The J2EE architecture (Pic. Sun Microsystem, http://java.sun.com/j2ee/overview3.html) Component models
COM/DCOM Component models
Interfaces and Assembly • A COM interface is seen as a C++ virtual class and takes the form of a list of data and function declarations without associated code. • All interfaces are descendants of the IUnknown interface. Interface Component interface Component implementation Component models
A Simple COM Object • A COM interfaces can have methods and properties • Language independent – binary standard • All Access is through the interface • Supports multiple interfaces • Each interface has a GUID Component models
IUnkown • All COM objects must implement IUnknown • AddRef • Release • QueryInterface IUnknown Component models
IUnknown • Contains only three methods • HRESULT QueryInterface(GUID iid, void **iptr); • ULONG AddRef(); • ULONG Release(); • QueryInterface is used for Interface Navigation • AddRef and Release is used for reference counting • A form of collaborative carbage collection Component models
IDL Example interface ISpellCheck : IUnknown { HRESULT check([in] BSTR *word, [out] bool *correct); }; interface ICustomSpellCheck : IUnknown { HRESULT add([in] BSTR *word); HRESULT remove([in] BSTR *word); }; library SpellCheckerLib { coclass SpellChecker { [default] interface ISpellCheck; interface ICustomSpellCheck; }; }; Component models
4. Invoke methods 3. Return pointer to interface 1. CoCreateInstance 2. Locate server object CLSID_X Path to server X CLSID_Y Path to server Y Registry Creating a local object Client Application Object Server COM Library Component models
4. Invoke methods CLSID_X C:\X.exe 3. Return pointer to interface CLSID_X Idt.mdh.se ... ... 1. CoCreateInstance CLSID_Y D:\Y.exe 2. Locate server object Registry Registry Creating a remote object Client Application Object Server COM Library mrtc.mdh.se Idt.mdh.se Component models
DBMS DBMS DBMS HTTP ADO COMApplications ADO DCOM Microsoft Application Server Technologies VisualInterDev BrowserClient IIS ASPApplications MTS RichClient VBVC++VJ++ Windows NT Component models
CORBA andComponent Model (CCM) Component models
CORBA • Common Object Request Broker Architecture • Standard for writing distributed object systems • Language independent • Not controlled by one company • Optional value added services Component models
OMA Overview OMA–Object Management Architecture CORBAdomains CORBAapps CORBAfacilities CORBA (Common Object Request Broker Architecture) Transactions Event Security Naming CORBAservices Component models
Remote invocation Component models
CORBA 3.0 • Internet Integration • Firewall Specification • Interoperable Name Service • Quality of Service Control • Asynchronous Messaging and Quality of Service Control • Minimum, Fault-Tolerant, and Real-Time CORBA • The CORBAcomponent architecture • Components • Scripting Component models