Methods Summary |
---|
void | executeCommand(java.lang.String[] cmd)
boolean result;
CommandHandler handler;
// handle the help command
if (cmd[0].equals(helpCommand)) {
if (cmd.length == 1) printAvailableCommands();
else {
// print long help for a specific command
for (int i=0; i < handlers.size(); i++) {
handler = (CommandHandler) handlers.elementAt(i);
if (handler.getCommandName().equals(cmd[1])) {
handler.printCommandHelp(System.out,
CommandHandler.longHelp);
}
}
}
return;
}
// determine the subcommand and execute it
for (int i=0; i < handlers.size(); i++) {
handler = (CommandHandler) handlers.elementAt(i);
if (handler.getCommandName().equals(cmd[0])) {
String[] cmdArgs = new String[cmd.length - 1];
// construct args to the command
for (int j=0; j < cmdArgs.length; j++)
cmdArgs[j] = cmd[j+1];
// execute the command
try {
System.out.println();
result = handler.processCommand(cmdArgs, orb, System.out);
if (result == CommandHandler.parseError) {
handler.printCommandHelp(System.out,
CommandHandler.longHelp);
}
System.out.println();
} catch (Exception ex) {}
return;
}
}
// unknown command - print available commands
printAvailableCommands();
|
static int | getServerIdForAlias(org.omg.CORBA.ORB orb, java.lang.String applicationName)
try {
Repository rep = RepositoryHelper.narrow(
orb.resolve_initial_references( ORBConstants.SERVER_REPOSITORY_NAME ) ) ;
int serverid = rep.getServerID(applicationName);
return rep.getServerID( applicationName ) ;
} catch (Exception ex) {
throw (new ServerNotRegistered());
}
|
public static void | main(java.lang.String[] args)
ServerTool tool = new ServerTool();
tool.run(args);
|
void | printAvailableCommands()
CommandHandler handler;
// print short help
System.out.println(CorbaResourceUtil.getText("servertool.shorthelp"));
for (int i=0; i < handlers.size(); i++) {
handler = (CommandHandler) handlers.elementAt(i);
System.out.print("\t" + handler.getCommandName());
for (int j=handler.getCommandName().length();
j < maxNameLen; j++) System.out.print(" ");
System.out.print(" - ");
handler.printCommandHelp(System.out,
CommandHandler.shortHelp);
}
System.out.println();
|
java.lang.String[] | readCommand(java.io.BufferedReader in)
System.out.print(toolName + " > ");
try {
int i = 0;
String cmd[] = null;
String cmdLine = in.readLine();
if (cmdLine != null) {
StringTokenizer st = new StringTokenizer(cmdLine);
if (st.countTokens() != 0) {
cmd = new String[st.countTokens()];
while (st.hasMoreTokens()) cmd[i++] = st.nextToken();
}
}
return cmd;
} catch (Exception ex) {
System.out.println(CorbaResourceUtil.getText("servertool.usage", "servertool"));
System.out.println();
ex.printStackTrace();
}
return null;
|
void | run(java.lang.String[] args)
String[] cmd = null;
// if command specified in the args, get it
for (int i=0; i < args.length; i++) {
if (args[i].equals(commandArg)) {
// get the command
int cmdLen = args.length - i - 1;
cmd = new String[cmdLen];
for (int j=0; j < cmdLen; j++) cmd[j] = args[++i];
break;
}
}
try {
// create the POA ORB
Properties props = System.getProperties() ;
props.put("org.omg.CORBA.ORBClass",
"com.sun.corba.se.impl.orb.ORBImpl" );
orb = (ORB) ORB.init(args, props);
// if command specified in the args, process it
if (cmd != null) executeCommand(cmd);
else { // process commands interactively
// create a buffered reader to read commands from standard in
BufferedReader in = new
BufferedReader(new InputStreamReader(System.in));
// print tool banner
System.out.println(CorbaResourceUtil.getText("servertool.banner"));
// process commands until user quits
while (true) {
cmd = readCommand(in);
if (cmd != null) executeCommand(cmd);
else printAvailableCommands();
}
}
} catch (Exception ex) {
System.out.println(CorbaResourceUtil.getText("servertool.usage", "servertool"));
System.out.println();
ex.printStackTrace();
}
|