Database Tutorial Command Provider

From RifidiWiki

Revision as of 21:50, 3 December 2009 by Kyle (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In order to control the database application, you can use a CommandProvider, which is a class that plugs into the eclipse osgi console and allows you to provide custom commands.

Implement the CommandProvider interface

The org.eclipse.osgi.framework.console.CommandProvider interface allows you to write methods which are exposed as commands in the eclipse console. By convention, any methods that you want to expose should start with an underscore (i.e. '_'), should have a return type of Object and should take in a CommandInterpreter (which allows you to get input and write output to the eclipse console ).

	/**
	 * Start the application
	 * 
	 * @param intp
	 * @return
	 */
	public Object _dbstart(CommandInterpreter intp) {
		app.start();
		return null;
	}

	/**
	 * Stop the application
	 * 
	 * @param intp
	 * @return
	 */
	public Object _dbstop(CommandInterpreter intp) {
		app.stop();
		return null;
	}

Dependency Injection

Like the other objects we have create so far, we are going to use dependency injection to give the CommandProvider access to the DBApp object.

	/**
	 * Called by spring
	 * 
	 * @param app
	 *            the app to set
	 */
	public void setApp(DBApp app) {
		this.app = app;
	}

Extra Credit

A command that lists the last five tag reads

Control the DBApp with RMI instead of the console

Personal tools