* Execute this command
*/
public void execute() throws Exception {
PrintWriter out = getOutput().getPrintWriter();
PrintWriter err = getError().getPrintWriter();
final KeyboardLayoutManager mgr = InitialNaming.lookup(KeyboardLayoutManager.NAME);
final Collection<Device> kbDevs =
DeviceUtils.getDevicesByAPI(KeyboardAPI.class);
if (argAdd.isSet()) {
String layoutID = getLayoutID(mgr);
if (!argClass.isSet()) {
throw new CommandSyntaxException(ex_syntax_class);
}
String className = argClass.getValue();
mgr.add(layoutID, className);
out.format(fmt_add, layoutID);
} else if (argRemove.isSet()) {
String layoutID = getLayoutID(mgr);
mgr.remove(layoutID);
out.format(fmt_remove, layoutID);
} else if (argSet.isSet()) {
String layoutID = getLayoutID(mgr);
for (Device kb : kbDevs) {
final KeyboardAPI api = kb.getAPI(KeyboardAPI.class);
try {
final KeyboardInterpreter kbInt = mgr.createKeyboardInterpreter(layoutID);
out.format(fmt_set_interp, kb.getId(), kbInt.getClass().getName());
api.setKbInterpreter(kbInt);
} catch (KeyboardInterpreterException ex) {
err.format(ex_set_interp, kb.getId(), ex.getLocalizedMessage());
// Re-throw the exception so that the shell can decide whether or not