Difference between revisions of "OSGi : Develop Simple Apps"

From CDOT Wiki
Jump to: navigation, search
(step 1)
(book class)
Line 21: Line 21:
 
public interface BookFinder {
 
public interface BookFinder {
 
Book findBook(int isbn) throws BookNotFoundException;
 
Book findBook(int isbn) throws BookNotFoundException;
 +
}
 +
</source>
 +
Define in the same bundle the classes that you need such as: Book and BookNotFoundException
 +
<source lang="java">
 +
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);
 +
}
 
}
 
}
 
</source>
 
</source>

Revision as of 15:39, 22 January 2011


OSGi Activities



Start the lab activities in the order defined below:

  1. Check out the Service Interface
  2. Check out the Service Provider
  3. Check out the Service Consumer

Steps for Building Bundels

1. Study the Interfaces

2. Define the Bundle that provide the service (Provider Bundle)

2.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);
	}
}