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

CmdFactory

public class CmdFactory extends Object

Fields Summary
private final HashMap
mCmds
public static final String
DEFAULT_CMD_NAME
Constructors Summary
public CmdFactory()

		mCmds	= new HashMap();
	
Methods Summary
public voidaddCmdMapping(java.lang.String name, java.lang.Class theClass)

		if ( ! Cmd.class.isAssignableFrom( theClass ) )
		{
			throw new IllegalArgumentException( "Command " + theClass.getName() +
				" must implement " + Cmd.class.getName() );
		}
		
		mCmds.put( name, theClass );
	
public CmdcreateCmd(java.lang.String name, CmdEnv env)

		final String	cmdString	= name;
		
		final Cmd	cmd	= instantiateCmd( cmdString, env );
		
		return( cmd );
	
public java.lang.ClassgetClass(java.lang.String cmdName)

		final Class	cmdClass	= (Class)mCmds.get( cmdName );
		
		return( cmdClass );
	
public java.lang.String[]getNames(java.lang.Class theClass)

		final ArrayList	list	= new ArrayList();
		
		final Iterator keys	= mCmds.keySet().iterator();
		
		while( keys.hasNext() )
		{
			final String	key	= (String)keys.next();
			
			final Class	thisClass	= (Class)mCmds.get( key );
			if ( thisClass == theClass ) 
			{
				list.add( key );
			}
		}
		
		final String []	names	= new String [ list.size() ];
		list.toArray( names );
		
		return( names );
	
private CmdinstantiateCmd(java.lang.String cmdName, CmdEnv env)

		Class	cmdClass	= (Class)mCmds.get( cmdName );
		
		if ( cmdClass == null )
		{
			// not found; see if there is a default registered
			cmdClass	= (Class)mCmds.get( DEFAULT_CMD_NAME );
		}
		
		if ( cmdClass == null )
		{
			return( null );
		}

		final Object []	args	= new Object [] { env };

		Cmd cmd	= null;
		try
		{
			cmd	= (CmdBase)ClassUtil.InstantiateObject( cmdClass, args );
		}
		catch( Exception e )
		{
			p( e.getMessage() );
			e.printStackTrace();
			throw e;
		}
		
		return( cmd );
	
private static voidp(java.lang.Object o)

	
		  
	   
	
		System.out.println( SmartStringifier.toString( o ) );
	
public voidremoveCmdMapping(java.lang.String name)

		mCmds.remove( name );