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

CreateAliasCmd

public class CreateAliasCmd extends JMXCmd

Fields Summary
private static final String
OPTIONS_INFO
Constructors Summary
public CreateAliasCmd(CmdEnv env)

		super( env );
	
Methods Summary
private voidaliasCreationFailed(java.lang.String name, java.lang.Exception e)

		final String value	= getAliasMgr().resolveAlias( name );
		
		if ( value != null )
		{
			printError( "Failed to create alias: " + name + "(already exists with value " + value + ")" );
			printError( "If you want to change it, delete it first." );
		}
		else if ( ExceptionUtil.getRootCause( e ) instanceof IllegalArgumentException )
		{
			printError( "Illegal alias name: " + name );
		}
		else
		{
			printError( "Failed to create alias: " + name );
		}
	
voidexecuteInternal()

		final String [] pairs	= getOperands();
		
		final boolean	replace	= getBoolean( "replace", Boolean.FALSE).booleanValue();
		
		for( int i = 0; i < pairs.length; ++i )
		{
			final String	pair	= pairs[ i ];
			final int		separatorIndex	= pair.indexOf( '=" );
			
			if ( separatorIndex < 0 )
			{
				printError( "Alias request must be of form name=value: " + pair );
				continue;
			}
			
			final String	name	= pair.substring( 0,separatorIndex);
			final String	value	= pair.substring( separatorIndex + 1, pair.length() );
			
			try
			{
				if ( replace )
				{
					getAliasMgr().deleteAlias( name );
				}
				
				getAliasMgr().createAlias( name, value );
				printError( "Created alias: " + name );
			}
			catch( Exception e )
			{
				aliasCreationFailed( name, e);
			}
		}
	
public static java.lang.String[]getNames()

		return( new String [] { "create-alias", "ca" } );
	
ArgHelper.OptionsInfogetOptionInfo()

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

		return( CmdStrings.CREATE_ALIAS_HELP.toString() );