Database Tutorial Command Provider
From RifidiWiki
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.
Contents
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; }