Difference between revisions of "Teams Winter 2011/team6/lab2"
Line 90: | Line 90: | ||
:: | :: | ||
+ | a) import java.util.Calendar; | ||
+ | import java.util.Date; | ||
+ | import cs.dps914.osgi.lab.chatinterface.IMessage; | ||
− | + | public class SimpleMessage implements IMessage { | |
− | + | private String source; | |
+ | private Date time; | ||
+ | private String message; | ||
+ | |||
+ | public SimpleMessage(String src,String msg) { | ||
+ | setSource(src); | ||
+ | setTime(Calendar.getInstance().getTime()); | ||
+ | setMessage(msg); | ||
+ | } | ||
+ | |||
+ | public void setSource(String src) { | ||
+ | if (src!=null) { | ||
+ | source=src; | ||
+ | } else { | ||
+ | source=""; | ||
+ | } | ||
+ | } | ||
+ | public String getSource() { | ||
+ | return source; | ||
+ | } | ||
+ | |||
+ | public void setTime(Date time) { | ||
+ | if (time!=null) { | ||
+ | this.time=time; | ||
+ | } else { | ||
+ | this.time=Calendar.getInstance().getTime(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public Date getTime() { | ||
+ | return time; | ||
+ | } | ||
+ | |||
+ | public void setMessage(String msg) { | ||
+ | if (msg!=null) { | ||
+ | message=msg; | ||
+ | } else { | ||
+ | message=""; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | public String getMessage() { | ||
+ | return message; | ||
+ | } | ||
+ | } | ||
b) In the Runtime tab select Add | b) In the Runtime tab select Add |
Revision as of 13:43, 12 April 2011
Contents
Lab 2 OSGI Tutorial
- After downloading the “Eclipse classic” from Eclipse then proceed with the following steps to create Chat Program with OSGi.
Create the Chat Interface
- The first step is to create the Chat Interface which is the Service Provider in the Program. This defines and provides the services available and the requirements and outcomes for those services.
Define the service interface
- a) Create a new Plug-in Project
- b) Name your Plug-in Project (cs.dps914.osgi.lab.chatinterface) and be sure to select the target platform (OSGi framework: Equinox)
- c) Be sure to uncheck the “Generate an activator” option as you will not be needing an activator then go ahead and click finish.
Create the bundle with the interface
- a) You must now create three interfaces: IChatClient, IChatSystem and IMessage
- Be sure to edit the package name and the Interface Name.
- b) Fill the interfaces with the following information:
- Message
- Chat System
- Chat Client
Export the Package
- To register our service we must export the package into the interface bundle
- a) Select the MANIFEST.MF
- b) In the Runtime tab select Add
- c) Select the chatinterface package
Implement the Chat Provider
Register the service in the class Activator
- a) Create a new Plug-in Project
- b) Name your Plug-in Project (cs.dps914.osgi.lab.provider) again be sure to select the target platform correctly
- c) This time you can leave the Activator checked as you will need it. (Change the name of the activator to cs.dps914.osgi.lab.provider.ChatActivator)
Define MANIFEST.MF
- a) Select the MANIFEST.MF
- b) In the Dependencies tab select Add for Required Plug-ins
- c) Add cs.dps914.osgilab.chatinterface
Create Java Classes Required
- a) Create 2 Java Classes (SimpleMessage and SimpleChatSystem)
- b) Make sure the package is defined correctly (cs.dps914.osgi.lab.provider.internals)
- c) Fill Java Classes with following Data
- SimpleMessage.java
a) import java.util.Calendar;
import java.util.Date; import cs.dps914.osgi.lab.chatinterface.IMessage;
public class SimpleMessage implements IMessage {
private String source; private Date time; private String message;
public SimpleMessage(String src,String msg) { setSource(src); setTime(Calendar.getInstance().getTime()); setMessage(msg); }
public void setSource(String src) { if (src!=null) { source=src; } else { source=""; } }
public String getSource() { return source; }
public void setTime(Date time) { if (time!=null) { this.time=time; } else { this.time=Calendar.getInstance().getTime(); } }
public Date getTime() { return time; }
public void setMessage(String msg) { if (msg!=null) { message=msg; } else { message=""; } }
public String getMessage() { return message; } }
b) In the Runtime tab select Add