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

LoaderOfOld

public abstract class LoaderOfOld extends Object
Loads MBeans.

Fields Summary
protected final Loader
mLoader
private final com.sun.appserv.management.util.misc.Output
mDebug
private static final Class[]
EMPTY_SIG
private static final Class[]
DELEGATE_SIG
Constructors Summary
LoaderOfOld(Loader loader)

		mLoader	= loader;
		
		mDebug  = AMXDebug.getInstance().getOutput( this.getClass().getName() );
	
Methods Summary
protected final java.util.MapcandidatesToMap(java.util.Set candidates, java.lang.String key)
Create a Map of Set keyed by the ObjectName key value specified. Each Set contains all the ObjectNames with that key.

		final Map<String,Set<ObjectName>> setMap	= new HashMap<String,Set<ObjectName>>();
		for( final ObjectName candidate : candidates )
		{
			final String keyValue	= candidate.getKeyProperty( key );
			
			Set<ObjectName>	typeSet	= setMap.get( keyValue );
			if ( typeSet == null )
			{
				typeSet	= new HashSet<ObjectName>();
				setMap.put( keyValue, typeSet );
			}
			typeSet.add( candidate );
		}
		
		return( setMap );
	
protected final voiddebug(java.lang.Object o)

	    mDebug.println( o.toString() );
	
private final javax.management.ObjectNameensureNew(javax.management.ObjectName newObjectName, javax.management.ObjectName oldObjectName)

		// don't assume this ObjectName is the entire name; query for it
		final ObjectName	pattern	= Util.newObjectNamePattern( newObjectName );
		
		// don't assume this ObjectName is the entire name; query for it
		final Set<ObjectName>	objectNames	= JMXUtil.queryNames( getMBeanServer(), pattern, null );
		
		final ObjectName	existingObjectName	= findExisting( objectNames, oldObjectName );
		
		ObjectName	resultName	= null;
		
		if ( existingObjectName == null )
		{
			// not yet registered, create it
			final Object		impl			= newImpl( newObjectName, oldObjectName );
			
			resultName	= registerNew( impl, newObjectName, oldObjectName );
		}
		else
		{
			resultName	= existingObjectName;
		}
		
		assert( resultName != null );
		
		return( resultName );
	
public final java.util.ListfindAllOld()
Create a list of all old MBeans and return a list in the order in which they must be registered.

		final Set<ObjectName>	all	= findAllOldCandidates();
		final Set<ObjectName>	results	= new HashSet<ObjectName>();
		
		for( final ObjectName objectName : all)
		{
			if ( shouldSync( objectName ) )
			{
				results.add( objectName );
			}
		}
		
		return( ListUtil.newListFromCollection( results ) );
	
protected abstract java.util.SetfindAllOldCandidates()

private java.lang.reflect.ConstructorfindConstructor(java.lang.reflect.Constructor[] constructors, java.lang.Class[] sig)

	
	

		 
	       
	
		Constructor	constructor	= null;
		
		for( int i = 0; i < constructors.length; ++i )
		{
			final Class<?>[]	csig	= constructors[ i ].getParameterTypes();
			
			if ( csig.length == sig.length )
			{
				constructor	= constructors[ i ];
			
				for( int c = 0; c < sig.length; ++c )
				{
					if ( ! csig[ i ].isAssignableFrom( sig[ i ] ) )
					{
						constructor	= null;
						break;
					}
				}
				
				if ( constructor != null )
				{
					break;
				}
			}
		}
		
		return( constructor );
	
protected javax.management.ObjectNamefindExisting(java.util.Set newObjectNames, javax.management.ObjectName oldObjectName)

		ObjectName	resultName	= null;
		
		if ( newObjectNames.size() == 1 )
		{
			// already registered
			resultName	= GSetUtil.getSingleton( newObjectNames );
		}

		return( resultName );
	
public java.lang.StringgetAMXJMXDomainName()

		return( mLoader.getAMXJMXDomainName() );
	
private java.lang.reflect.ConstructorgetDelegateConstructor(java.lang.reflect.Constructor[] constructors)

		return( findConstructor( constructors, DELEGATE_SIG ) );
	
protected com.sun.appserv.management.DomainRootgetDomainRoot()

		return( mLoader.getDomainRoot() );
	
private java.lang.reflect.ConstructorgetEmptyConstructor(java.lang.reflect.Constructor[] constructors)

		return( findConstructor( constructors, EMPTY_SIG ) );
	
protected abstract java.util.SetgetIgnoreTypes()

protected java.lang.ClassgetImplClass(javax.management.ObjectName newObjectName, javax.management.ObjectName oldObjectName)

		final String		newType	= Util.getJ2EEType( newObjectName );
		
		final TypeInfo	info	= TypeInfos.getInstance().getInfo( newType );
		assert( info != null );
		final Class			implClass	= info.getImplClass();
		
		return( implClass );
	
protected java.util.logging.LoggergetLogger()

		return( mLoader.getMBeanLogger() );
	
public javax.management.MBeanServergetMBeanServer()

		return( mLoader.getMBeanServer() );
	
protected abstract java.util.SetgetNeedsSupport()

protected booleanisDefectiveIgnore(javax.management.ObjectName objectName)
Is the com.sun.appserv MBean defective in some way such that it cannot be properly represented in AMX?

	    return false;
	
protected abstract booleanisOldMBean(javax.management.ObjectName objectName)

protected java.lang.ObjectnewImpl(javax.management.ObjectName newObjectName, javax.management.ObjectName oldObjectName)

		Object	impl	= null;
		
		final Class			implClass	= getImplClass( newObjectName, oldObjectName );
		
		try
		{
			final Constructor[]	constructors	= implClass.getConstructors();
			Constructor			constructor	= null;
			
			if ( (constructor = getDelegateConstructor( constructors )) != null )
			{
				final DelegateToMBeanDelegate	delegate	=
					new DelegateToMBeanDelegate( mLoader.getMBeanServer(), oldObjectName );
				assert( delegate != null );
				debug( "created Delegate with target of " + oldObjectName +
				    " for " + newObjectName );
					
				impl = constructor.newInstance( new Object[] { delegate } );
			}
			else if ( getEmptyConstructor( constructors ) != null )
			{
				impl	= implClass.newInstance();
			}
			else
			{
				assert( false );
			    throw new Error( "Delegate has no constructor" );
			}
		}
		catch( Exception e )
		{
		    final Throwable rootCause   = ExceptionUtil.getRootCause( e );
			debug( "Loader.newImpl: exception creating new impl: "  + e + "\n" +
			    ExceptionUtil.getStackTrace( rootCause ) );
			throw e;
		}
		
		return( impl );
	
protected abstract javax.management.ObjectNameoldToNewObjectName(javax.management.ObjectName o)

protected final javax.management.ObjectNameregisterNew(java.lang.Object impl, javax.management.ObjectName implObjectName, javax.management.ObjectName oldObjectName)

				
		if ( impl == null )
		{
		    final String msg    = "unable to create new impl for old: " + oldObjectName;
		    debug( msg );
			throw new IllegalArgumentException( msg );
		}

		return( mLoader.registerNew( impl, implObjectName, oldObjectName ) );
	
public final booleanshouldSync(javax.management.ObjectName o)

		boolean	shouldSync	= isOldMBean( o );
		
		if ( shouldSync )
		{
			final String	type	= o.getKeyProperty( "type" );
			
			if ( getNeedsSupport().contains( type ) )
			{
				shouldSync	= false;
				getLogger().warning(
					"com.sun.appserv MBean not yet supported: " +
					StringUtil.quote(o) );
			}
			else if ( isDefectiveIgnore( o ) )
			{
				shouldSync	= false;
				debug(
					"com.sun.appserv MBean was last determined to be defective " +
					"and will not be represented in AMX: " +
					StringUtil.quote(o) );
			}
		}

		return( shouldSync );
	
protected javax.management.ObjectNamesyncWithOld(javax.management.ObjectName oldObjectName)

		final ObjectName	newObjectName	= oldToNewObjectName( oldObjectName );
		debug( "\nsyncWithOld: " + JMXUtil.toString(oldObjectName) + "=> " + JMXUtil.toString(newObjectName) + "\n" );		
		final ObjectName	resultName	= ensureNew( newObjectName, oldObjectName );
		
		return( resultName );
	
protected java.lang.StringtoString(java.lang.Object o)

		return( com.sun.appserv.management.util.stringifier.SmartStringifier.toString( o ) );
	
protected final voidtrace(java.lang.Object o)

		debug( o );