FileDocCategorySizeDatePackage
MBeanInfoConverter.javaAPI DocGlassfish v2 API9848Fri May 04 22:23:42 BST 2007com.sun.enterprise.management.support

MBeanInfoConverter

public final class MBeanInfoConverter extends Object
Convert MBeanInfo which was derived from public client-side interface into MBeanInfo useable by server-side MBeans.

Fields Summary
private final Map
mConvertedInfos
private static MBeanInfoConverter
INSTANCE
private static final Map
NAMES_TO_CLASSES
private static final String
OBJECT_NAME_SUFFIX
private static final String
SET_SUFFIX
private static final String
MAP_SUFFIX
private static final String
LIST_SUFFIX
private static final String
OBJECT_NAME_MAP_SUFFIX
private static final String
OBJECT_NAME_SET_SUFFIX
private static final String
OBJECT_NAME_LIST_SUFFIX
Constructors Summary
private MBeanInfoConverter()

	
		
	 
	
		mConvertedInfos	= Collections.synchronizedMap( new HashMap<Class,MBeanInfo>() );
	
Methods Summary
public final javax.management.MBeanInfoconvert(java.lang.Class theInterface, javax.management.MBeanAttributeInfo[] extraAttributeInfos)

		MBeanInfo	result	= null;
		
        result	= find( theInterface );
        if ( result == null )
        {
        // no big deal if this were threaded; we'd do it twice; last one wins
            final MBeanInfo	origInfo	= JMXUtil.interfaceToMBeanInfo( theInterface );
            
            final MBeanAttributeInfo[]	origAttrInfos	= origInfo.getAttributes();
            final MBeanAttributeInfo[]	attrInfos	= extraAttributeInfos == null ?
                origAttrInfos :
                JMXUtil.mergeMBeanAttributeInfos( origAttrInfos, extraAttributeInfos);
            
            result	= new MBeanInfo(
                    origInfo.getClassName(),
                    origInfo.getDescription(),
                    convertAttributes( attrInfos ),
                    origInfo.getConstructors(),
                    convertOperations( origInfo.getOperations() ),
                    origInfo.getNotifications() );
            
            mConvertedInfos.put( theInterface, result );
        }
        return( result );
    
private final javax.management.MBeanAttributeInfoconvert(javax.management.MBeanAttributeInfo info)

		MBeanAttributeInfo	result	= info;
		final String	name	= info.getName();
		
		final Class	type	= toClass( info.getType() );
		
		String	newName	= null;
		Class	newType	= type;
		
		if ( AMX.class.isAssignableFrom( type ) )
		{
			newName	= name + OBJECT_NAME_SUFFIX;
			newType	= ObjectName.class;
		}
		else if ( name.endsWith( SET_SUFFIX ) &&
		     ! name.endsWith( OBJECT_NAME_SET_SUFFIX ) ) 
		{
			newName	= convertMethodName( name, SET_SUFFIX, OBJECT_NAME_SET_SUFFIX );
		}
		else if ( name.endsWith( MAP_SUFFIX ) &&
		     ! name.endsWith( OBJECT_NAME_MAP_SUFFIX )
		    ) 
		{
			newName	= convertMethodName( name, MAP_SUFFIX, OBJECT_NAME_MAP_SUFFIX );
		}
		else if ( name.endsWith( LIST_SUFFIX ) &&
		     ! name.endsWith( OBJECT_NAME_LIST_SUFFIX )
		    ) 
		{
			newName	= convertMethodName( name, LIST_SUFFIX, OBJECT_NAME_LIST_SUFFIX );
		}
		
		if ( newName != null )
		{
			trace( ClassUtil.stripPackageName( type.getName() ) + " " + name +
				" => " + ClassUtil.stripPackageName( newType.getName() ) + " " + newName );
				
			result	= new MBeanAttributeInfo( newName, newType.getName(),
				info.getDescription(), info.isReadable(), info.isWritable(), info.isIs() );
		}
		
		return( result );
	
private final javax.management.MBeanOperationInfoconvert(javax.management.MBeanOperationInfo info)

		MBeanOperationInfo	result	= info;
		final String	name	= info.getName();
		
		final Class	returnClass	= toClass( info.getReturnType() );
		
		String	newName	= null;
		Class	newReturnClass	= returnClass;
		
		if ( AMX.class.isAssignableFrom( returnClass ) )
		{
			/*
				Anything returning an AMX (or sub-interface) must necessarily
				return an ObjectName from the MBean.
			 */
			newReturnClass	= ObjectName.class;
			
			/*
				Except for create() and createAbc() methods, we tack on 
				OBJECT_NAME_SUFFIX to the MBean operation.  AMXProxyHandler
				expects this convention.
			 */
			if ( name.startsWith( "create" ) )
			{
				newName			= name;
			}
			else
			{
				newName			= name + OBJECT_NAME_SUFFIX;
			}
		}
		else if ( Map.class.isAssignableFrom( returnClass ) &&
			name.endsWith( MAP_SUFFIX ) &&
			! name.endsWith( OBJECT_NAME_MAP_SUFFIX ) )
		{
			newName			= convertMethodName( name, MAP_SUFFIX, OBJECT_NAME_MAP_SUFFIX );
		}
		else if ( Set.class.isAssignableFrom( returnClass ) &&
			name.endsWith( SET_SUFFIX ) &&
			! name.endsWith( OBJECT_NAME_SET_SUFFIX ))
		{
			newName			= convertMethodName( name, SET_SUFFIX, OBJECT_NAME_SET_SUFFIX );
		}
		else if ( Set.class.isAssignableFrom( returnClass ) &&
			name.endsWith( LIST_SUFFIX ) &&
			! name.endsWith( OBJECT_NAME_LIST_SUFFIX ))
		{
			newName			= convertMethodName( name, LIST_SUFFIX, OBJECT_NAME_LIST_SUFFIX );
		}
		
		if ( newName != null )
		{
			trace( ClassUtil.stripPackageName( returnClass.getName() ) + " " + name + "(...)" +
				" => " + ClassUtil.stripPackageName( newReturnClass.getName() ) + " " + newName + "(...)" );
				
			result	= new MBeanOperationInfo(
				newName,
				info.getDescription(),
				info.getSignature(),
				newReturnClass.getName(),
				info.getImpact() );
		}
		
		return( result );
	
private final javax.management.MBeanAttributeInfo[]convertAttributes(javax.management.MBeanAttributeInfo[] origInfos)

		final MBeanAttributeInfo[]	infos	= new MBeanAttributeInfo[ origInfos.length ];
		
		for( int i = 0; i < infos.length; ++i )
		{
			infos[ i ]	= convert( origInfos[ i ] );
		}
		
		return( infos );
	
protected static java.lang.StringconvertMethodName(java.lang.String srcName, java.lang.String srcSuffix, java.lang.String resultSuffix)

		return( StringUtil.replaceSuffix( srcName, srcSuffix, resultSuffix ) );
	
private final javax.management.MBeanOperationInfo[]convertOperations(javax.management.MBeanOperationInfo[] origInfos)

		final MBeanOperationInfo[]	infos	= new MBeanOperationInfo[ origInfos.length ];
		
		for( int i = 0; i < infos.length; ++i )
		{
			infos[ i ]	= convert( origInfos[ i ] );
		}
		
		return( infos );
	
private final javax.management.MBeanInfofind(java.lang.Class theInterface)

		return( mConvertedInfos.get( theInterface ) );
	
public static synchronized com.sun.enterprise.management.support.MBeanInfoConvertergetInstance()

		if ( INSTANCE == null )
		{
			INSTANCE	= new MBeanInfoConverter();
		}
		
		return( INSTANCE );
	
protected static java.lang.ClasstoClass(java.lang.String className)

    
		  
	    
	
        Class theClass  = NAMES_TO_CLASSES.get( className );
        if ( theClass != null )
            return theClass;
            
		try
		{
			theClass    = ClassUtil.getClassFromName( className );
            NAMES_TO_CLASSES.put( className, theClass );
            return theClass;
		}
		catch( ClassNotFoundException e )
		{
			assert( false );
			throw new RuntimeException( e );
		}
	
protected voidtrace(java.lang.Object o)

		
		
		 
	   
	
		//System.out.println( com.sun.appserv.management.util.stringifier.SmartStringifier.toString( o ) );