FileDocCategorySizeDatePackage
CLISupportTestee.javaAPI DocGlassfish v2 API13373Fri May 04 22:24:54 BST 2007 com.sun.cli.jmx.test

CLISupportTestee

public final class CLISupportTestee extends Object implements DynamicMBean

Fields Summary
static final String
VIRTUAL_OPERATION_NAME
static final String
D
final com.sun.cli.jmx.util.InvokeHelper
mInvokeHelper
private MBeanInfo
mMBeanInfo
private static final Class[]
BASE_CLASSES
private static final int
NUM_BASE_CLASSES
Constructors Summary
public CLISupportTestee()

		mInvokeHelper	= new InvokeHelper( this );
	
Methods Summary
public javax.management.MBeanOperationInfo[]createMBeanOperationInfos()

		final Method []	allMethods	= this.getClass().getDeclaredMethods();
		
		final ArrayList	exportMethods	= new ArrayList();
		final int 		allCount	= Array.getLength( allMethods );
		for( int i = 0; i < allCount; ++i )
		{
			final Method	m	= allMethods[ i ];
			final String	name	= m.getName();
			
			if ( name.startsWith( "test" ) )
			{
				final String		description	= "tests '" + name + "' operation";
				final MBeanParameterInfo	parameterInfo []	= createMBeanParameterInfos( m );
				
				// our generic invoker will return the same type of result for each--
				// the signature that was invoked
				// final String		returnTypeString	= m.getReturnType().getName();
				final String		returnTypeString	= String [].class.getName();
				
				final MBeanOperationInfo	info	= new MBeanOperationInfo( name,
												 description,
												 parameterInfo,
												 returnTypeString,
												 MBeanOperationInfo.INFO );
				
				exportMethods.add( info );
			}
		}
		
		
		// add the virtual methods
		final MBeanOperationInfo []	virtualOperations	= createVirtualOperationInfos();
		for( int i = 0; i < Array.getLength( virtualOperations ); ++i )
		{
			exportMethods.add( virtualOperations[ i ] );
		}
		
		MBeanOperationInfo []	infos	= new MBeanOperationInfo[ exportMethods.size() ];
		
		infos	= (MBeanOperationInfo [])exportMethods.toArray( infos );
		
		
		return( infos );
	
public javax.management.MBeanParameterInfo[]createMBeanParameterInfos(java.lang.reflect.Method m)

	
	
		  
	  
	
		final Class []	parameterClasses	= m.getParameterTypes();
		
		final int					numParams	= Array.getLength( parameterClasses );
		final MBeanParameterInfo	infos []	= new MBeanParameterInfo[ numParams ];
		
		for( int i = 0; i < numParams; ++i )
		{
			// use parameter names of p1, p2, p3, etc
			final String	parameterName	= "p" + (i+1);
			
			final MBeanParameterInfo	info	=
				new MBeanParameterInfo( parameterName,
										parameterClasses[ i ].getName(),
										"parameter " + i + 1
										);
			
			infos[ i ]	= info;
		}
		
		return( infos );
	
public javax.management.MBeanOperationInfocreateVirtualOperationInfo(java.lang.String operationName, java.lang.Class[] argClasses)

		final int	numArgs	= Array.getLength( argClasses );
		
		// create a method for each supported class
		final ArrayList	paramInfos	= new ArrayList();
		
		for( int i = 0; i < numArgs; ++i )
		{
			final Class	theClass	= argClasses[ i ];
			
			// create single parameter with name of "pX", where X is the index of the param 1,2,3, etc
			final String	parameterName	= "p" + (i + 1);
			final String	parameterDescription	= "parameter " + (i+1);
			final MBeanParameterInfo	param	= new MBeanParameterInfo( parameterName, theClass.getName(), parameterDescription );
			
			paramInfos.add( param );
		}
		
		MBeanParameterInfo []	infos	= new MBeanParameterInfo [ paramInfos.size() ];
		paramInfos.toArray( infos );
		
		// create operation with return type of String [] (which will return the signature)
		final String		returnTypeString	= String [].class.getName();
		final String		description	= "virtual operation";
		final MBeanOperationInfo	info	= new MBeanOperationInfo( operationName,
													 description,
													 infos,
													 returnTypeString,
													 MBeanOperationInfo.INFO );
		return( info );
	
	
public javax.management.MBeanOperationInfo[]createVirtualOperationInfos()

		final String	operationName	= VIRTUAL_OPERATION_NAME;
		
		ArrayList	ops	= new ArrayList();
		
		/* create a method for each supported class consisting of a single parameter
		 */
		final Class []	classes		= getSupportedClassList();
		final int		numClasses	= classes.length;
		for( int i = 0; i < numClasses; ++i )
		{
			final Class []	classList	= new Class [] { classes[ i ] };
			final MBeanOperationInfo	info	= createVirtualOperationInfo( operationName, classList );
			ops.add( info );
		}
		
		// for each primitive type, create a signature with 3 parameters, each of which can vary between
		// the primitive type and the Object form.
		for( int i = 0; i < numClasses; ++i )
		{
			final Class	theClass	= classes[ i ];
			if ( ! ClassUtil.IsPrimitiveClass( theClass ) )
				continue;
				
			final Class objectClass	= ClassUtil.PrimitiveClassToObjectClass( theClass );
			
			// generate all 8 variants
			final Class []	both	= new Class [] { theClass, objectClass };
			for( int p1 = 0; p1 < 2; ++p1 )
			{
				for( int p2 = 0; p2 < 2; ++p2 )
				{
					for( int p3 = 0; p3 < 2; ++p3 )
					{
						final Class []	classList	= new Class [] { both[ p1 ], both[ p2 ], both[ p3 ] };
						MBeanOperationInfo	info	= createVirtualOperationInfo( operationName, classList );
						ops.add( info );
					}
				}
			}
		}
		
		
		// Create all method signature for depth of 2 with all variants of all supported types
		// CAUTION: this generates (num classes)^2 operations, about 7000 or so.
		final int	depth	= 2;
		final int	numCombinations	= numClasses * numClasses;	// must match depth
		for( int i = 0; i < numCombinations; ++i )
		{
			final Class []	classList	= new Class [ depth ];
		
			// number of assignments must match depth
			classList[ 0 ]	= classes[ i % numClasses ];
			classList[ 1 ]	= classes[ (i / numClasses) % numClasses ];
			
			if ( classList[ 0 ] == Properties.class || classList[ 1 ] == Properties.class )
			{
				// don't generate any methods with Properties; that is only for named invocation
				continue;
			}
			assert( classList[ 0 ] != Properties.class && classList[ 1 ] != Properties.class );
			
			final MBeanOperationInfo	info	= createVirtualOperationInfo( operationName + i, classList );
			ops.add( info );
		}
			
		
		MBeanOperationInfo []	infos	= new MBeanOperationInfo[ ops.size() ];
		infos	= (MBeanOperationInfo [])ops.toArray( infos );
		return( infos );
	
public java.lang.ObjectgetAttribute(java.lang.String attribute)

    	throw new AttributeNotFoundException();
    
public javax.management.AttributeListgetAttributes(java.lang.String[] attributes)

    	return new AttributeList();
    
public synchronized javax.management.MBeanInfogetMBeanInfo()

		if ( mMBeanInfo == null )
		{
			final MBeanAttributeInfo []		attributeInfo	= null;
			final MBeanConstructorInfo []		constructorInfo	= null;
			final MBeanNotificationInfo []	notificationInfo	= null;
			final MBeanOperationInfo []		operationInfo	= createMBeanOperationInfos();
			
			mMBeanInfo	= new MBeanInfo( this.getClass().getName(),
				"Test MBean for the CLI support code",
				attributeInfo,
				constructorInfo,
				operationInfo,
				notificationInfo );
		}
		
		return( mMBeanInfo );
	
public java.lang.Class[]getSupportedClassList()

	
		  
	
	
		ArrayList	classes	= new ArrayList();
		
		for( int i = 0; i < NUM_BASE_CLASSES; ++i )
		{
			Class	derivedClass	= BASE_CLASSES[ i ];
			
			classes.add( derivedClass );
			if ( derivedClass == Properties.class )
				continue;
			
			// 1D array
			derivedClass	= Array.newInstance( derivedClass, 0 ).getClass();
			classes.add( derivedClass );
			
			// 2D array
			derivedClass	= Array.newInstance( derivedClass, 0 ).getClass();
			classes.add( derivedClass );
			
			// we support any dimension arryas, but 3 is probably excessive from 
			// a testing standpoint
			/*
			// 3D array
			derivedClass	= Array.newInstance( derivedClass, 0 ).getClass();
			classes.add( derivedClass );
			*/
		}
		
		Class []	result	= new Class[ classes.size() ];
		classes.toArray( result );
		return( result );
	
public java.lang.Objectinvoke(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] signature)

    	Object	result	= null;
    	
    	if ( actionName.startsWith( VIRTUAL_OPERATION_NAME ) )
    	{
    		return( signature );
    	}
    	
    	try
    	{
    		// p( "INVOKING HELPER: " + actionName + "(" + AutoStringifier.toString( signature ) + ")");
    		result	= mInvokeHelper.invoke( actionName, params, signature );
    		
    		// ignore result, always return signature of invoked method
    		result	= signature;
    		// p( "SUCCESS: " + actionName + "(" + AutoStringifier.toString( signature ) + ")");
    		
    	}
    	catch( Exception e )
    	{
    		// e.printStackTrace();
    		throw new MBeanException( e );
    	}
    	
    	return( result );
    
private voidp(java.lang.Object o)

	// delimiter

		 
	   
	
		System.out.println( o.toString() );
	
public voidsetAttribute(javax.management.Attribute attribute)

    	throw new AttributeNotFoundException();
	
public javax.management.AttributeListsetAttributes(javax.management.AttributeList attributes)

    	return new AttributeList();
    
public java.lang.String[]testFoo(long[][] p1)

		return( new String [  ] { "[[C", "char" } );
	
public voidtestNamed(java.util.Properties props)

	
public voidtestNamed(java.lang.String p1)

	
public voidtestNamed(java.lang.String p1, java.lang.String p2)

	
public voidtestNamed(java.lang.String p1, java.lang.String p2, java.lang.String p3)

	
public voidtestNamed(java.lang.String p1, java.lang.String p2, java.lang.String p3, java.util.Properties p4)

	
public voidtestProperties1Arg(java.lang.String p1, java.util.Properties p2)

    
public voidtestProperties2Args(java.lang.String p1, java.util.Properties p2, java.lang.String p3)

    
public voidtestPropertiesOnly(java.util.Properties p1)

    
public java.lang.String[]virtualTest()

		return( new String [ 0 ] );