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

CmdMgr

public final class CmdMgr extends Object

Fields Summary
final CmdEnvImpl
mCmdEnv
final CmdFactory
mCmdFactory
final CmdRunner
mCmdRunner
private static final Class[]
CMDS
Constructors Summary
public CmdMgr()

		mCmdEnv		= new CmdEnvImpl();
		mCmdFactory	= new CmdFactory( );
		mCmdRunner	= new CmdRunnerImpl( mCmdFactory, mCmdEnv );
		
		mCmdEnv.put( CmdBase.ENV_CMD_RUNNER, mCmdRunner, false);
		mCmdEnv.put( CmdBase.ENV_CMD_FACTORY, mCmdFactory, false);
	
Methods Summary
private static voiddm(java.lang.Object o)

		System.out.println( SmartStringifier.toString( o ) );
	
voidhandleInteractive()

		final LineReaderImpl	lineReader	= new LineReaderImpl( System.in );
		final CmdReader			reader		= new CmdReader();
		
		try
		{
			reader.goInteractive( lineReader, mCmdRunner );
		}
		catch( Throwable t )
		{
			dm( "Exception from processing commands: " + t.getMessage() );
			t.printStackTrace();
		}
	
voidhandleSingle(java.lang.String[] args)

		// one-off command mode.  Only allowed meta option is a connect string "--connect"
		final String	OPTIONS	= "connect,1";
					
		final ArgHelperImpl	argHelper	= new ArgHelperImpl( Arrays.asList( args ).listIterator(),
								new ArgHelperOptionsInfo( OPTIONS ));
		
		String		lines	= "";
		
		final String connectString		= argHelper.getString( "connect", null );
		if ( connectString != null )
		{
			CmdReader.processLine( "connect " + connectString, mCmdRunner );
		}
		
		// now execute the remainder of the line
		final String []	remainder	= argHelper.getOperands();
		
		// the first operand is the command name
		mCmdRunner.execute( remainder[ 0 ], remainder );
	
private voidinitCmds()

		
		 
	
		 
	
		final CmdFactoryIniter	initer = new CmdFactoryIniter( mCmdFactory, CMDS );
		
		// initialize all non-built-in commands
		final ConfigureCmd.ClassList	list =
				new ConfigureCmd.ClassList( (String)mCmdEnv.get( CmdBase.ENV_COMMANDS ) );
		final java.util.Iterator	iter	= list.iterator();
		while ( iter.hasNext() )
		{
			final String	classname	= (String)iter.next();
			
			initer.addMappings( ClassUtil.getClassFromName( classname ) );
		}
	
public voidrun(java.lang.String[] args)

		final File	file	= JMXAdminFileNames.getPropsFile();
		mCmdEnv.load( file );
		
		initCmds();
		
			
		// if there are no arguments, start up in interactive mode
		if ( args.length == 0 || (args.length == 1 && args[ 0 ].equals( "multi" ) ) )
		{
			handleInteractive();
		}
		else
		{
			handleSingle( args );
		}
		
		// CAUTION: if a ctrl-c is received, the JVM seems to kill us half-way through
		// storing mCmdEnv, which ends up destroying it.  Pause briefly to avoid this (hack).
		Thread.sleep( 100 );
		mCmdEnv.store( file );