FileDocCategorySizeDatePackage
CmdReader.javaAPI DocGlassfish v2 API5208Fri May 04 22:24:50 BST 2007com.sun.cli.jmx.cmd

CmdReader

public class CmdReader extends Object implements CmdOutput

Fields Summary
private static final String
ADVISORY
private static final String
USAGE
private static final String
DELIM_CHARS
private static final char
ESCAPE_CHAR
private static final String
ESCAPABLE_CHARS
Constructors Summary
public CmdReader()

	
Methods Summary
public voidgoInteractive(com.sun.cli.util.LineReader lineReader, CmdRunner cmdRunner)

		p( ADVISORY );
		
		while ( true )
		{
			final String	line	= readLine( lineReader );
			
			if ( isQuitLine( line ) )
			{
				println( "Quitting..." );
				break;
			}
			
			if ( line.length() == 0 )
				continue;
			
			processLine( line, cmdRunner );
		}
		
	
private static java.lang.StringinitUsage()

	
		  
	
	
		String	usage	= "*** Available commands ***\n\n";
		
		final CmdStrings.CmdHelp []	allHelp	= CmdStrings.getAllHelp();
		
		for( int i = 0; i < allHelp.length; ++i )
		{
			usage	= usage + allHelp[ i ] + "\n\n";
		}
		
		return( usage );
	
booleanisQuitLine(java.lang.String line)

		final boolean	isQuit	= 
			line == null  ||
			line.equalsIgnoreCase( "quit" ) ||
			line.equalsIgnoreCase( "q" ) ||
			line.equalsIgnoreCase( "exit" );
			line.equalsIgnoreCase( "exit" );
			
		return( isQuit );
	
static java.lang.String[]lineToTokens(java.lang.String line)

		  
	   
	
		final TokenizerImpl tk	= new TokenizerImpl( line, "" + DELIM_CHARS,
										ESCAPE_CHAR, ESCAPABLE_CHARS);
		
		return( tk.getTokens( ) );
	
private static voidp(java.lang.Object o)

		System.out.println( SmartStringifier.toString( o ) );
	
public voidprint(java.lang.Object o)

		System.out.print( o.toString() );
	
public voidprintDebug(java.lang.Object o)

		println( o );
	
public voidprintError(java.lang.Object o)

		System.err.println( o.toString() );
	
public voidprintln(java.lang.Object o)

		System.out.println( o.toString() );
	
public voidprocessCmd(java.lang.String line, CmdRunner cmdRunner)

		final String [] tokens	= lineToTokens( line );
		
		try
		{
			final String cmdName	= tokens[ 0 ];
			
			cmdRunner.execute( cmdName, tokens );
		}
		catch (Exception e )
		{
		}
	
public static intprocessLine(java.lang.String line, CmdRunner cmdRunner)

		int	errorCode	= 0;
		
		final String [] tokens	= lineToTokens( line );
		
		try
		{
			final String cmdName	= tokens[ 0 ];
			
			cmdRunner.execute( cmdName, tokens );
		}
		catch (Exception e )
		{
			errorCode	= -1;
		}
		
		return( errorCode );
	
public java.lang.StringreadLine(com.sun.cli.util.LineReader lineReader)

		String	line	= lineReader.readLine( "> ");
		
		if ( line != null )
		{
			line	= line.trim();
		}
		
		return( line );