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

ConfigureCmd

public class ConfigureCmd extends JMXCmd

Fields Summary
public static final char
CLASSNAME_DELIM
public static final String
NAME
public static final String
SHOW_CONFIG
public static final String
ADD_PROVIDER
public static final String
REMOVE_PROVIDER
public static final String
ADD_CMD
public static final String
REMOVE_CMD
private static final String[]
NAMES
private static final String
OPTIONS_INFO
Constructors Summary
public ConfigureCmd(CmdEnv env)

	
		
	    
	
		super( env );
	
Methods Summary
voidaddCmd()

		requireNumOperands( 1, "A command classname must be specified");
		
		final String commandClassname	= getOperands()[ 0 ];
		
		final ClassList	list	= createCmdList();
		
		if ( list.exists( commandClassname ) )
		{
			println( "Command already in list: " + commandClassname );
		}
		else if ( ! isLegalClassname( commandClassname ) )
		{
			printError( "Illegal classname: " + commandClassname );
		}
		else
		{
			final CmdFactoryIniter	initer = new CmdFactoryIniter( getCmdFactory() );
			final Class	theClass	= ClassUtil.getClassFromName( commandClassname );
			
			initer.addMappings( theClass );
			
			list.add( commandClassname );
			envPut( ENV_COMMANDS, list.toString(), true );
		}
	
voidaddProvider()

		requireNumOperands( 1, "A provider classname must be specified");
		
		final String providerClassname	= getOperands()[ 0 ];
		
		ClassList	list	= createProviderList();
		
		if ( list.exists( providerClassname ) )
		{
			println( "Provider already in list: " + providerClassname );
		}
		else if ( ! isLegalClassname( providerClassname ) )
		{
			printError( "Illegal classname: " + providerClassname );
		}
		else
		{
			// if this succeeds, then we'll update the env
			try
			{
				getConnectionMgr().addProvider( Class.forName( providerClassname ) );
			}
			catch( Exception e )
			{
				printError( "WARNING: unable to instantiate provider (added to list anyway): " +
					e.getMessage() );
			}
			
			list.add( providerClassname );
			
			envPut( ENV_PROVIDERS, list.toString(), true );
		}
	
com.sun.cli.jmx.cmd.ConfigureCmd$ClassListcreateCmdList()

		return( new ClassList( (String)envGet( ENV_COMMANDS ) ) );
	
com.sun.cli.jmx.cmd.ConfigureCmd$ClassListcreateProviderList()

		return( new ClassList( (String)envGet( ENV_PROVIDERS ) ) );
	
voiddisplayCmds()

		println( "Commands configured: " );
		final String	list	= IteratorStringifier.stringify( createCmdList().iterator(), "\n" );
		
		println( (list.length() == 0) ? "<none>" : list );
	
voiddisplayConfig()

		displayProviders();
		
		println( "" );
		
		displayCmds();
	
voiddisplayProviders()

		println( "Available providers: " );
		final String	list	= IteratorStringifier.stringify( createProviderList().iterator(), "\n" );
		
		println( (list.length() == 0) ? "<none>" : list );
		
		println( "\nProviders successfully loaded (includes built-ins): " );
		final JMXConnectorProvider []	providersLoaded	= getConnectionMgr().getProviders();
		for ( int i = 0; i < providersLoaded.length; ++i )
		{
			JMXConnectorProvider provider	= providersLoaded[ i ];
			
			println( provider.getClass().getName() );
		}
	
voidexecuteInternal()

		final String	cmdName		= getCmdNameAsInvoked();
		
		if ( cmdName.equals( SHOW_CONFIG ) )
		{
			displayConfig();
		}
		else if ( cmdName.equals( ADD_PROVIDER ) )
		{
			addProvider();
		}
		else if ( cmdName.equals( REMOVE_PROVIDER ) )
		{
			removeProvider( );
		}
		else if ( cmdName.equals( ADD_CMD ) )
		{
			addCmd( );
		}
		else if ( cmdName.equals( REMOVE_CMD ) )
		{
			removeCmd( );
		}
		else
		{
			printUsage();
		}
	
public static java.lang.String[]getNames()

	
		   
	 
	
		return( NAMES );
	
intgetNumRequiredOperands()

		return( 0 );
	
ArgHelper.OptionsInfogetOptionInfo()

		
	
		
	
		 
	
		return( new ArgHelperOptionsInfo( OPTIONS_INFO ) );
	
java.lang.StringgetUsage()

		return( CmdStrings.CONFIGURE_HELP.toString() );
	
booleanisLegalClassname(java.lang.String name)

		// should test this properly, but at least make sure it doesn't have our delim
		return( name.indexOf( CLASSNAME_DELIM ) < 0 );
	
voidremoveCmd()

		requireNumOperands( 1, "A classname must be specified");
		
		final String	classname	= getOperands()[ 0 ];
		final ClassList	list		= createCmdList();
		
		if ( ! list.exists( classname ) )
		{
			println( "Command not registered: " + classname );
		}
		else
		{
			// remove it from the preferences
			list.remove( classname );
			envPut( ENV_PROVIDERS, list.toString(), true );
			
			// remove it from the factory
			final CmdFactoryIniter	initer = new CmdFactoryIniter( getCmdFactory() );
			initer.removeMappings( ClassUtil.getClassFromName( classname ) );

		}
	
voidremoveProvider()

		requireNumOperands( 1, "A provider classname must be specified");
		
		final String providerClassname	= getOperands()[ 0 ];
		
		ClassList	list	= createProviderList();
		
		if ( ! list.exists( providerClassname ) )
		{
			println( "Provider not found: " + providerClassname );
		}
		else
		{
			// if this succeeds, then we'll update the env
			try
			{
				final Class theClass	= Class.forName( providerClassname );
				getConnectionMgr().removeProvider( theClass );
			}
			catch( Exception e )
			{
				// ignore
			}
			
			list.remove( providerClassname );
			
			envPut( ENV_PROVIDERS, list.toString(), true );
		}