Difference between revisions of "OSGi : Develop Simple Apps"
Line 13: | Line 13: | ||
* [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleActivator.html BundleActivator] | * [http://www.osgi.org/javadoc/r4v42/org/osgi/framework/BundleActivator.html BundleActivator] | ||
− | <h4>2. Define the Bundle | + | <h4>2. Define the Bundle Service Provider</h4> |
− | <h5>2.1 Define the Java Interface that exposes the services</h5> | + | <h5> 2.1 Define the Generic Bundle Service Provider</h5> |
+ | |||
+ | <h5>2.1.1 Define the Java Interface that exposes the services</h5> | ||
Let us suppose that you want to define a service that allows the user to find a book from the book isbn. Then the interface should look similare with this one: | Let us suppose that you want to define a service that allows the user to find a book from the book isbn. Then the interface should look similare with this one: | ||
<source lang="java"> | <source lang="java"> | ||
Line 81: | Line 83: | ||
Export-Package: cs.ecl.osgi.simple.bookfinder | Export-Package: cs.ecl.osgi.simple.bookfinder | ||
</source> | </source> | ||
− | <h5>2. | + | |
+ | <h5>2.2 Define the Concrete Bundle Provider</h5> |
Revision as of 16:04, 22 January 2011
Main Page · Course Description · Course Topics · Schedule, Students, Teams · Course Resources · Course Projects
OSGi Activities
- Start and run the Eclipse for OSGi as installed in the previous lecture.
- Open the Subversion Perspective in Eclipse for OSGi.
- Check out the Simple Sample from OSGi Course Repository
- Run the sample and change it.
- Define the main steps involved in developing OSGi applications.
- Write a small tutorial (main steps) about using Eclipse to develop OSGi applications.
Start the lab activities in the order defined below:
- Check out the Service Interface
- Check out the Service Provider
- Check out the Service Consumer
Steps for Building Bundels
Contents
1. Study the Interfaces
2. Define the Bundle Service Provider
2.1 Define the Generic Bundle Service Provider
2.1.1 Define the Java Interface that exposes the services
Let us suppose that you want to define a service that allows the user to find a book from the book isbn. Then the interface should look similare with this one:
package cs.ecl.osgi.simple.bookfinder;
public interface BookFinder {
Book findBook(int isbn) throws BookNotFoundException;
}
Define in the same bundle the classes that you need such as: Book and BookNotFoundException
package cs.ecl.osgi.simple.bookfinder;
public class Book {
private int isbn;
private String title;
public Book(int isbn, String title) {
super();
this.isbn = isbn;
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getIsbn() {
return isbn;
}
public void setIsbn(int isbn) {
this.isbn = isbn;
}
}
package cs.ecl.osgi.simple.bookfinder;
public class BookNotFoundException extends Exception {
private static final long serialVersionUID = -6184839510952070091L;
public BookNotFoundException() {
super();
}
public BookNotFoundException(String arg0) {
super(arg0);
}
}
Define in the MANIFEST.MF that cs.ecl.osgi.simple.bookfinder is the Exported-Package
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bookfinder
Bundle-SymbolicName: cs.ecl.osgi.simple.bookfinder
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: Seneca College - Eclipse Course
Export-Package: cs.ecl.osgi.simple.bookfinder