From BUG Wiki
/**
* Generated by DragonFly
*
*/
package consume_example.servicetracker;
import java.util.List;
import org.osgi.framework.BundleContext;
import com.buglabs.bug.application.AbstractServiceTracker;
import com.buglabs.services.ws.IWSResponse;
import com.buglabs.services.ws.PublicWSAdmin;
import com.buglabs.services.ws.PublicWSDefinition;
import com.buglabs.services.ws.PublicWSProvider;
/**
* Service tracker for the BugApp Bundle;
*
*/
public class Consume_exampleServiceTracker extends AbstractServiceTracker implements PublicWSProvider {
public Consume_exampleServiceTracker(BundleContext context) {
super(context);
}
/**
* Determines if the application can start.
*/
public boolean canStart() {
return super.canStart();
}
/**
* If canStart returns true
* this method is called to start the application.
* Place your fun logic here.
*/
public void doStart() {
System.out.println("Consume_exampleServiceTracker: start");
PublicWSAdmin wsAdmin = (PublicWSAdmin) this.getService(PublicWSAdmin.class);
wsAdmin.registerService(this);
}
/**
* Called when a service that this application depends is unregistered.
*/
public void doStop() {
System.out.println("Consume_exampleServiceTracker: stop");
}
/**
* Allows the user to set the service dependencies by
* adding them to services list returned by getServices().
* i.e.nl getServices().add(MyService.class.getName());
*/
public void initServices() {
getServices().add("com.buglabs.services.ws.PublicWSAdmin");
}
public PublicWSDefinition discover(int operation) {
if (operation == PublicWSProvider.GET) {
return new PublicWSDefinition() {
public List getParameters() {
return null;
}
public String getReturnType() {
return "text/plain";
}
};
}
return null;
}
public IWSResponse execute(int operation, String input) {
if (operation == PublicWSProvider.GET) {
return new IWSResponse() {
public Object getContent() {
return "hello world!";
}
public int getErrorCode() {
// TODO Auto-generated method stub
return 0;
}
public String getErrorMessage() {
// TODO Auto-generated method stub
return null;
}
public String getMimeType() {
return "text/plain";
}
public boolean isError() {
return false;
}
};
}
return null;
}
public String getPublicName() {
return "Test";
}
}