/**
 *	Generated by Dragonfly SDK
 *
 */
package geriatricassistant.servicetracker;

import geriatricassistant.GeriatricAssistantApplication;

import org.osgi.framework.BundleContext;

import com.buglabs.application.AbstractServiceTracker;

/**
 * Service tracker for the BugApp Bundle;
 * 
 */
public class GeriatricAssistantServiceTracker extends AbstractServiceTracker {
	private GeriatricAssistantApplication application;

	public GeriatricAssistantServiceTracker(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() {
		if (!getApplication().isAlive()) {
			if (getApplication().getRan()) {
				application = new GeriatricAssistantApplication(this);
			}
			getApplication().start();
		}

	}

	/**
	 * Called when a service that this application depends is unregistered.
	 */
	public void doStop() {
		getApplication().tearDown();

	}

	/**
	 * 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().addAll(getApplication().getServices());
	}

	/**
	 * Returns the application thread.
	 */
	public GeriatricAssistantApplication getApplication() {
		if (application == null) {
			application = new GeriatricAssistantApplication(this);
		}

		return application;
	}
}