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

FindCmd

public class FindCmd extends JMXCmd

Fields Summary
static final String
ENV_CURRENT_SET
private static final String
OPTIONS_INFO
private static final char
BACKSLASH
Constructors Summary
public FindCmd(CmdEnv env)

	
		
	    
	
		super( env );
	
Methods Summary
java.util.SetarrayToSet(java.lang.Object[] names)

		final TreeSet	theSet	= new TreeSet();
		
		for( int i = 0; i < names.length; ++i )
		{
			theSet.add( names[ i ] );
		}

		return( theSet );
	
static java.lang.StringconvertToJavaRegex(java.lang.String input)

	
	/*
		We support only '*" in a simplified form.
	 */
		 
	   
	
		String	converted	= input;
		
		if ( input != null )
		{
			// first run the tokenizer on it specifying no delimiters so as to eliminate any escape constructs
			final String []	tokens	= new TokenizerImpl( input, "", '\\", "*").getTokens();
			assert( tokens.length == 1 );
			// now any '\' or '*' characters are to be taken literally
			
			final String	unescapedInput	= tokens[ 0 ];
			
			final int 			length	= unescapedInput.length();
			final StringBuffer	buf	= new StringBuffer();
			
			for( int i = 0; i < length; ++i )
			{
				final char	theChar	= unescapedInput.charAt( i );
				
				if ( theChar == '." )
				{
					buf.append( "[.]" );
				}
				else if ( theChar == '*" )
				{
					buf.append( ".*" );
				}
				else if ( theChar == BACKSLASH )
				{
					buf.append( "" + BACKSLASH + BACKSLASH );
				}
				else
				{
					buf.append( theChar );
				}
			}
			
			converted	= buf.toString();
			
		}
		return( converted );
	
voiddisplay(java.util.Set names)

		println( IteratorStringifier.stringify( names.iterator(), "\n" ) );
	
voidexecuteInternal()

		String [] targets	= getOperands();
		
		if ( targets.length == 0 )
		{
			targets	= new String [] { "all" };
		}
		
		final boolean add				= getBoolean( "add", Boolean.FALSE ).booleanValue();
		final boolean remove			= getBoolean( "remove", Boolean.FALSE ).booleanValue();
		final boolean displayCurrent	= getBoolean( "current", Boolean.FALSE ).booleanValue();
		final String regex				= getString( "regex", null );
		final String javaregex			= getString( "java-regex", null );
		
		final Set	currentSet	= getCurrent();
		
		if ( displayCurrent )
		{
			if ( currentSet == null || currentSet.size() == 0 )
			{
				println( "Nothing in current set." );
			}
			else
			{
				display( currentSet  );
			}
		}
		else
		{
			establishProxy();
			
			final String	actualRegex	= (javaregex != null) ?
								javaregex : convertToJavaRegex( regex );
			
			ObjectName []	objectNames	= getProxy().mbeanFind( targets, actualRegex);
			
			final String []		objectStrings	= objectNamesToStrings( objectNames );
			Set		resultSet	= arrayToSet( objectStrings );
			
			if ( currentSet != null )
			{
				if ( add )
				{
					currentSet.addAll( resultSet );
					resultSet	= currentSet;
				}
				else if ( remove )
				{
					currentSet.removeAll( resultSet );
					resultSet	= currentSet;
				}
			}
			
			envPut( ENV_CURRENT_SET, resultSet, false );
			
			if ( resultSet.size() == 0 )
			{
				println( "No objects match the targets " + SmartStringifier.toString( targets ) );
			}
			else
			{
				
				display( resultSet );
			}
		}
	
java.util.SetgetCurrent()

		return( (Set)envGet( ENV_CURRENT_SET ) );
	
public static java.lang.String[]getNames()

		return( new String [] { "find", "f" } );
	
intgetNumRequiredOperands()

		// require 1, by default
		return( 0 );
	
ArgHelper.OptionsInfogetOptionInfo()

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

		return( CmdStrings.FIND_HELP.toString() );
	
java.lang.String[]objectNamesToStrings(javax.management.ObjectName[] objectNames)

		// sorting doesn't work on returned array, so convert to Strings first,then sort
		final String []	resultStrs	= new String [ objectNames.length ];
		for( int i = 0; i < resultStrs.length; ++i )
		{
			resultStrs[ i ]	= objectNames[ i ].toString();
		}
		
		return( resultStrs );