|
Framework Professional Edition Package |
||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Interface Summary | |
|---|---|
| PluggableCommands | This interface should be used for installing new commands
in the com.prosyst.util.parser.ParserService. |
| Class Summary | |
|---|---|
| CommandInfo | This class represents an executable command in the
PluggableCommands. |
| PCommandsUtils | This class provides utility methods for formatting plain text messages. |
This package provides the base interfaces and class for the Parser Service pluggable commands. Each pluggable commands should implement the com.prosyst.util.pcommands.PluggableCommands interface and should be registered in the framework.
Here is an example how you can implement this service:
import com.prosyst.util.pcommands.CommandInfo;
import com.prosyst.util.pcommands.PluggableCommands;
import java.io.PrintStream;
public class TestCommands implements PluggableCommands {
private static String command = "command";
private static String shortcut1 = "comm";
private static String shortcut2 = "c";
// Methods inherited from interface
// com.prosyst.util.pcommands.PluggableCommands
// Executing a command on request
public void executeCommand(String name, String[] params, PrintStream pStream) {
String option = "";
String result = "";
if(name.equals(command) || name.equals(shortcut1) || name.equals(shortcut2)){
for(int i=0; i < params.length; i ++) {
if(params[i].equals("-o")) {
option = params[i];
} else {
result = result.concat(params[i]);
}
}
if(option != "") {
pStream.println("\tExample option used!");
}
pStream.println(result);
}
}
// Defining command properties
public CommandInfo[] getCommandsInfo() {
CommandInfo[] commands = new CommandInfo[1];
String[] names = {command, shortcut1, shortcut2};
String[] params = {"[-o]", "Command option", "parameter", "Command parameter"};
commands[0] = new CommandInfo(names, "Example command ", params);
return commands;
}
public String getGroupHelpMessage() {
return "Example help message";
}
// Specifying the group's name
public String getGroupName() {
return "example";
}
} |
The next exemple shows how to register the commands above into the framework so that the Parser Service can receive a notification and insert them into its command inventory.
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import TestCommands;
public class CommandsActivator implements BundleActivator {
ServiceRegistration sReg = null;
String servName = "com.prosyst.util.pcommands.PluggableCommands";
public void start(BundleContext bc) {
// Registering the collection of commands as a service
sReg = bc.registerService(servName, new TestCommands(), null);
if (sReg != null) {
System.out.println("Commands registered successfully!");
}
}
public void stop(BundleContext bc) {
sReg.unregister();
}
} |
|
Framework Professional Edition Package |
||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||