Difference between revisions of "Teams Winter 2011/team1/OSGI/Create the Service Interface"

From CDOT Wiki
Jump to: navigation, search
(1. Create the Service Interface)
(1. Create the Service Interface)
 
(7 intermediate revisions by the same user not shown)
Line 13: Line 13:
  
 
'''1.2. Create Interfaces'''<br/>
 
'''1.2. Create Interfaces'''<br/>
Add a package to the src folder in your project.Then Add following ttems to your package:
+
Add a package to the src folder in your project.Then Add following items to your package:
 
# A Java class named BusRoute.
 
# A Java class named BusRoute.
 
# A Java class named BusRouteNotFoundException which extends java.lang.Exceptions class.
 
# A Java class named BusRouteNotFoundException which extends java.lang.Exceptions class.
 +
# A Java class named InvalidNumberOfSeatsException which extends java.lang.Exception class.
 
# An Interface named Ticketing
 
# An Interface named Ticketing
  
 
:[[Image: 5CreateInterfaces.jpg| 800px]]
 
:[[Image: 5CreateInterfaces.jpg| 800px]]
  
:Enter the code for the classes and the interface as per the following screenshots:
+
:Enter the code for the classes and the interface as per the following screen-shots:
 
:'''BusRout Class:'''
 
:'''BusRout Class:'''
 
:[[Image: 6CreateNewClass.jpg | 700px]]
 
:[[Image: 6CreateNewClass.jpg | 700px]]
 
:'''BusRoutNotFoundException Class:'''
 
:'''BusRoutNotFoundException Class:'''
 
:[[Image: 7CreateNewClass.jpg | 700px]]
 
:[[Image: 7CreateNewClass.jpg | 700px]]
 +
:'''InvalidNumberOfSeatsException Class:'''
 +
:[[Image: 71CreateNewClass.jpg | 700px]]
 
:'''Ticketing Interface:'''
 
:'''Ticketing Interface:'''
 
:[[Image: 8CreateInterface.jpg | 700px]]
 
:[[Image: 8CreateInterface.jpg | 700px]]
Line 32: Line 35:
  
 
:[[Image: 9ExportPackge.jpg | 700px]]
 
:[[Image: 9ExportPackge.jpg | 700px]]
:Select the Ticketing package and add it.
+
 
:[[Image: 10_ExceptionClass.jpg | 700px]]
+
:Select the Ticketing package and press Ok button.
:[[Image: 11.jpg | 700px]]
+
:[[Image: 10ExportPackage.jpg | 400px]]
:[[Image: 12_ExportPackage.JPG | 700px]]
+
:[[Image: 12ExportPackage.jpg | 400px]]
:[[Image: 13.jpg | 700px]]
+
 
:[[Image: 14_ExportPackage.jpg | 700px]]
+
:The Interface is Exported and now it's time to build the service implementation project where you add all the implementations of the interface and register it at run time.
:[[Image: 15.jpg | 700px]]
 

Latest revision as of 12:07, 16 February 2011

1. Create the Service Interface

First thing to do in building an OSGI application is to define the service interface so that the developer who creates the GUI part of application knows what services will be available, and what are their requirements and outcome.In order to do this please follow these steps:

1.1. Create the interface bundle

Create a new Plug-in project in eclipse using File>New> Plug-in Project:
1CreateNewPlugInProject.JPG
Give it a proper name and Choose the target platform to be an OSGI platform:
2CreateNewPlugInProject.jpg
Make sure you check off the , so that no Activator class is created in the project (this bundel is just interfaces so it does not run).
3CreateNewPlugInProject.jpg
4CreateNewPlugInProject.jpg

1.2. Create Interfaces
Add a package to the src folder in your project.Then Add following items to your package:

  1. A Java class named BusRoute.
  2. A Java class named BusRouteNotFoundException which extends java.lang.Exceptions class.
  3. A Java class named InvalidNumberOfSeatsException which extends java.lang.Exception class.
  4. An Interface named Ticketing
5CreateInterfaces.jpg
Enter the code for the classes and the interface as per the following screen-shots:
BusRout Class:
6CreateNewClass.jpg
BusRoutNotFoundException Class:
7CreateNewClass.jpg
InvalidNumberOfSeatsException Class:
71CreateNewClass.jpg
Ticketing Interface:
8CreateInterface.jpg

1.3. Export Package

In order to be able to register our service we need to export our package in the interface bundle. To do so, select MANIFEST.MF in the package explored and then brows to the Runtime tab.Click on "Add" in Exported Packages section.
9ExportPackge.jpg
Select the Ticketing package and press Ok button.
10ExportPackage.jpg
12ExportPackage.jpg
The Interface is Exported and now it's time to build the service implementation project where you add all the implementations of the interface and register it at run time.