FileDocCategorySizeDatePackage
ServerTool.javaAPI DocJava SE 5 API27835Fri Aug 26 14:54:18 BST 2005com.sun.corba.se.impl.activation

ServerTool

public class ServerTool extends Object
version
1.7, 97/10/19
author
Anita Jindal
since
JDK1.3

Fields Summary
static final String
helpCommand
static final String
toolName
static final String
commandArg
private static final boolean
debug
org.omg.CORBA.ORB
orb
static Vector
handlers
static int
maxNameLen
Constructors Summary
Methods Summary
voidexecuteCommand(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 intgetServerIdForAlias(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 voidmain(java.lang.String[] args)

	ServerTool tool = new ServerTool();
	tool.run(args);
    
voidprintAvailableCommands()

	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;
    
voidrun(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();
	}