FileDocCategorySizeDatePackage
CompositeDataHelper.javaAPI DocGlassfish v2 API8420Fri May 04 22:31:04 BST 2007com.sun.appserv.management.util.jmx

CompositeDataHelper

public class CompositeDataHelper extends Object

Fields Summary
private static final String[]
EMPTY_STRING_ARRAY
private static final OpenType[]
EMPTY_OPENTYPES
Constructors Summary
public CompositeDataHelper()

	
Methods Summary
public java.io.SerializableasData(java.io.Serializable o)

		Object	result	= null;
		
		if ( o instanceof StackTraceElement )
		{
			result	= stackTraceElementCompositeData( (StackTraceElement)o );
		}
		else if ( o instanceof Throwable )
		{
			result	= throwableToCompositeData( (Throwable)o );
		}
		else if ( o instanceof Map )
		{
		    final Map<String,Serializable> m  = TypeCast.asSerializableMap( o );
		    
			result	= mapToCompositeData( Map.class.getName(), "", m );
		}
		else
		{
			final OpenType	type	= OpenMBeanUtil.getOpenType( o );
			
			if ( type instanceof SimpleType )
			{
				result	= o;
			}
			else if ( type instanceof ArrayType )
			{
				result	= o;
			}
			else
			{
				throw new IllegalArgumentException( "" + o );
			}
		}
		
		return( Serializable.class.cast( result ) );
	
public static javax.management.openmbean.CompositeTypegetEmptyCompositeType()
Get a CompositeType describing a CompositeData which has no elements.

	
			         	 
		  
	
		 
	
		return( new CompositeType(
			CompositeType.class.getName() + ".Empty", 
			"Empty composite type",
			EMPTY_STRING_ARRAY,
			EMPTY_STRING_ARRAY,
			EMPTY_OPENTYPES
			) );
	
public javax.management.openmbean.CompositeTypegetStackTraceElementCompositeType()
Get a CompositeType describing a CompositeData which has no elements.

		final String[]	itemNames	= new String[]
		{
			"ClassName",
			"FileName",
			"LineNumber",
			"isNativeMethod",
		};
		
		final String[]	descriptions	= new String[  ]
		{
			"ClassName",
			"FileName",
			"LineNumber",
			"IsNativeMethod",
		};
		
		final OpenType[]	openTypes	= new OpenType[ itemNames.length ];
		openTypes[ 0 ]	= SimpleType.STRING;
		openTypes[ 1 ]	= SimpleType.STRING;
		openTypes[ 2 ]	= SimpleType.INTEGER;
		openTypes[ 3 ]	= SimpleType.BOOLEAN;
		
		final CompositeType	type = new CompositeType(
			StackTraceElement.class.getName(), 
			"StackTraceElement composite type",
			itemNames,
			descriptions,
			openTypes
			);
		return( type );
	
protected javax.management.openmbean.CompositeDatamapToCompositeData(java.lang.String typeName, java.lang.String description, java.util.Map map)
Create a CompositeData from a Map. Each key in the map must be a String, and each value must be a type consistent with OpenTypes.

param
typeName the arbitrary name of the OpenType to be used
param
description the arbitrary description of the OpenType to be used
param
map a Map keyed by String, whose values may not be null

		final CompositeType	type	= mapToCompositeType( typeName, description, map );
		
		return( new CompositeDataSupport( type, map ) );
	
protected javax.management.openmbean.CompositeTypemapToCompositeType(java.lang.String typeName, java.lang.String description, java.util.Map map)

	    return mapToCompositeType( typeName, description, map, null );
	
protected javax.management.openmbean.CompositeTypemapToCompositeType(java.lang.String typeName, java.lang.String description, java.util.Map map, CompositeTypeFromNameCallback callback)
Create a CompositeType from a Map. Each key in the map must be a String, and each value must be a type consistent with OpenTypes.

param
typeName the arbitrary name of the OpenType to be used
param
description the arbitrary description of the OpenType to be used
param
map a Map keyed by String, whose values may not be null

	    return OpenMBeanUtil.mapToCompositeType( typeName, description, map, callback );
	
public javax.management.openmbean.CompositeDatastackTraceElementCompositeData(java.lang.StackTraceElement elem)
Get a CompositeType describing a CompositeData which has no elements.

		final Map<String,Serializable>	m	= new HashMap<String,Serializable>();
		m.put( "ClassName", elem.getClassName() );
		m.put( "FileName", elem.getFileName() );
		m.put( "LineNumber", new Integer( elem.getLineNumber() ) );
		m.put( "isNativeMethod", Boolean.valueOf( elem.isNativeMethod() ) );
		
		return( new CompositeDataSupport( getStackTraceElementCompositeType(), m ) );
	
public javax.management.openmbean.CompositeDatathrowableToCompositeData(java.lang.Throwable t)
Get a CompositeType describing a CompositeData which has no elements.

		final Throwable	cause	= t.getCause();
		
		final String[]	itemNames	= new String[]
		{
			"Message",
			"Cause",
			"StackTrace",
		};
		
		final String[]	descriptions	= new String[  ]
		{
			"The message from the Throwable",
			"The cause (if any) from the Throwable",
			"The stack trace from the Throwable",
		};
		
		final OpenType[]	openTypes	= new OpenType[ itemNames.length ];
		
		openTypes[ 0 ]	= SimpleType.STRING;
		openTypes[ 1 ]	= cause == null ?
			getEmptyCompositeType() : throwableToCompositeData( cause ).getCompositeType();
		openTypes[ 2 ]	= new ArrayType( t.getStackTrace().length,
							getStackTraceElementCompositeType() );
		
		
		final CompositeType	type	= new CompositeType(
			t.getClass().getName(), 
			"Throwable composite type",
			itemNames,
			descriptions,
			openTypes
			);
		
		
		final Map<String,Object>	m	= new HashMap<String,Object>();
		m.put( "Message", t.getMessage() );
		m.put( "Cause", cause == null ? null : throwableToCompositeData( cause ) );
		m.put( "StackTrace", t.getStackTrace() );
		
		return( new CompositeDataSupport( type, m ) );