FileDocCategorySizeDatePackage
AMXConfigImplBase.javaAPI DocGlassfish v2 API31640Fri May 04 22:23:16 BST 2007com.sun.enterprise.management.config

AMXConfigImplBase

public class AMXConfigImplBase extends com.sun.enterprise.management.support.AMXImplBase implements com.sun.appserv.management.config.AMXConfig
Base class from which all AMX Config MBeans should derive (but not "must").

Fields Summary
private static final String
CREATE
private static final String
CREATE_PREFIX
private static final String
REMOVE_PREFIX
private static final String
CONFIG_SUFFIX
private static final String
FACTORY_SUFFIX
private static final Class[]
STRING_SIG
private static final Set
CR_PREFIXES
private static final Class[]
FACTORY_CONSTRUCTOR_SIG
Constructors Summary
protected AMXConfigImplBase(com.sun.enterprise.management.support.Delegate delegate)

		super( delegate );
	
Methods Summary
protected final voidcheckInterfaceSupport(java.lang.Class theInterface, java.lang.String attributeToCheck)

        if ( getDelegate() != null)
        {
            final boolean   delegateSupports  =
                getDelegate().supportsAttribute( attributeToCheck );
            
            final boolean   supported   = theInterface.isAssignableFrom( getInterface() );
            
            if ( delegateSupports != supported )
            {
                final String msg    = "ERROR: " + getJ2EEType() + ": " +
                    "AMX interface does not match Delegate capabilities for " +
                    "interface " + theInterface.getName() + ", " +
                    "delegate support = " + delegateSupports +
                    ", AMX support = " + supported;
                logSevere( msg );
                throw new Error( msg );
            }
        }
	
protected final voidcheckPropertiesAccessSupport()
Verify that the AMX support for system properties is the same as its Delegate.

        if ( getDelegate() != null)
        {
            final boolean   delegateHasProperties   = delegateSupportsProperties();
            
            if ( delegateHasProperties != supportsProperties() )
            {
                final String msg = getJ2EEType() + ": " +
                    "delegateSupportsProperties=" + delegateHasProperties +
                    ", but supportsProperties=" + supportsProperties();
                // implementation error
                logWarning( msg );
                throw new Error( msg );
            }
        }
        else if ( supportsProperties() )
        {
            final String msg    =  getJ2EEType() + ": " +
                "AMX interface supports properties, but has no delegate";
            logSevere( msg );
            throw new Error( msg );
        }
	
protected final voidcheckSystemPropertiesAccessSupport()
Verify that the AMX support for properties is the same as its Delegate.

        if ( getDelegate() != null)
        {
            final boolean   delegateSupports    = delegateSupportsSystemProperties();
            
            if ( delegateSupports != supportsSystemProperties() )
            {
                final String msg = getJ2EEType() + ": " +
                    "delegateSupportsSystemProperties=" + delegateSupports +
                    ", but supportsSystemProperties=" + supportsSystemProperties();
                // implementation error
                logWarning( msg );
                throw new Error( msg );
            }
        }
        else if ( supportsSystemProperties() )
        {
            final String msg    =  getJ2EEType() + ": " +
                "AMX interface supports system properties, but has no delegate";
            logSevere( msg );
            throw new Error( msg );
        }
	
protected javax.management.ObjectNamecreateConfig(java.lang.String simpleInterfaceName, java.lang.Object[] args, java.lang.String[] types)

        ObjectName  result  = null;
    
        final Class[]   sig = ClassUtil.signatureFromClassnames( types );
            
        final ConfigFactory factory = createConfigFactory( simpleInterfaceName );
        if ( factory == null )
        {
            // look for the appropriate method
            final String createMethodName   = CREATE + simpleInterfaceName;
            final Method m   = this.getClass().getMethod( createMethodName, sig);
            if ( m == null )
            {
                throw new RuntimeException( "Can't find ConfigFactory for " + simpleInterfaceName );
            }
        }
        else
        {
			final Method createMethod	=
			    factory.getClass().getDeclaredMethod( CREATE, sig);
			if ( createMethod != null )
			{
			    result  = (ObjectName)createMethod.invoke( factory, args );
			}
			else
			{
			    final String msg    = "Can't find method " + CREATE +
			        " in factory " + factory.getClass().getName();
			    
			    throw new NoSuchMethodException( msg );
			}
        }
        
        return result;
   
protected com.sun.enterprise.management.config.ConfigFactorycreateConfigFactory(java.lang.String simpleClassname)
Create a ConfigFactory or return null if couldn't be created.

        ConfigFactory factory   = null;
        
        try
        {
            final String    classname   = getFactoryPackage() + "." +
                                            simpleClassname + FACTORY_SUFFIX;
            
            final Class factoryClass    = ClassUtil.getClassFromName( classname );
    		final Constructor constructor	= factoryClass.getConstructor( FACTORY_CONSTRUCTOR_SIG );
    		
    		if ( constructor != null )
    		{
                factory   = (ConfigFactory)constructor.newInstance( new Object[] { this } );
            }
            else
            {
                throw new RuntimeException( "No ConfigFactory found for " + classname );
            }
        }
        catch( Exception e )
        {
            debug( ExceptionUtil.toString( e ) );
            throw new RuntimeException( e );
        }
        return factory;
   
public final voidcreateProperty(java.lang.String propertyName, java.lang.String propertyValue)

		validatePropertyName( propertyName );
		
		setPropertyValue( propertyName, propertyValue );
	
public final voidcreateSystemProperty(java.lang.String propertyName, java.lang.String propertyValue)

		setSystemPropertyValue( propertyName, propertyValue );
	
private booleandelegateSupportsProperties()

        boolean supports   = true;
        final OldProperties old    = getOldProperties();
        try
        {
          final AttributeList props    =  old.getProperties();
          supports   = true;
        }
        catch( Exception e )
        {
            supports   = false;
        }
        return supports;
	
private booleandelegateSupportsSystemProperties()

        boolean supports   = true;
        final OldSystemProperties old    = getOldSystemProperties();
        try
        {
            final AttributeList props    =  old.getSystemProperties();
            supports   = true;
        }
        catch( Exception e )
        {
            supports   = false;
        }
        return supports;
	
public final booleanexistsProperty(java.lang.String propertyName)

		validatePropertyName( propertyName );
		
		return( GSetUtil.newSet( getPropertyNames() ).contains( propertyName ) );
	
public final booleanexistsSystemProperty(java.lang.String propertyName)

		validatePropertyName( propertyName );
		
		return( GSetUtil.newSet( getSystemPropertyNames() ).contains( propertyName ) );
	
public java.lang.StringgetConfigName()
Get the name of the config in which this MBean lives.

return
config name, or null if not in a config

		return( (String)getKeyProperty( XTypes.CONFIG_CONFIG ) );
	
public java.lang.StringgetDefaultValue(java.lang.String name)

        try
        {
            return getDelegate().getDefaultValue( name );
        }
        catch( Throwable t )
        {
            throw new RuntimeException( t );
        }
    
protected java.lang.StringgetFactoryPackage()

        // same package as the MBean implementation
        return this.getClass().getPackage().getName();
   
public final java.lang.StringgetGroup()

		return( AMX.GROUP_CONFIGURATION );
	
public javax.management.MBeanNotificationInfo[]getNotificationInfo()

	    final MBeanNotificationInfo[]   superInfos = super.getNotificationInfo();
	    
		// create a NotificationInfo for AttributeChangeNotification
		final String description	= "";
		final String[]	notifTypes	= new String[] { AttributeChangeNotification.ATTRIBUTE_CHANGE };
		final MBeanNotificationInfo	attributeChange = new MBeanNotificationInfo(
				notifTypes,
				AttributeChangeNotification.class.getName(),
				description );
	
		final MBeanNotificationInfo[]	selfInfos	=
			new MBeanNotificationInfo[]	{ attributeChange };

		final MBeanNotificationInfo[]	allInfos	=
			JMXUtil.mergeMBeanNotificationInfos( superInfos, selfInfos );
			
	    return allInfos;
	
protected com.sun.enterprise.management.support.oldconfig.OldPropertiesgetOldProperties()
Get the old mbean's properties API.

	
		if ( ! haveDelegate() )
		{
			final String msg	= "properties not supported (no delegate) by " +
									quote( getObjectName() );
			
			throw new IllegalArgumentException( msg );
		}
		
		return( new OldPropertiesImpl( getDelegate() ) );
	
protected com.sun.enterprise.management.support.oldconfig.OldSystemPropertiesgetOldSystemProperties()

	
		if ( ! haveDelegate() )
		{
			final String msg	= "system properties not supported (no delegate) by " +
									quote( getObjectName() );
			
			throw new IllegalArgumentException( msg );
		}
		
		return( new OldSystemPropertiesImpl( getDelegate() ) );
	
public java.util.MapgetProperties()

		final AttributeList	props	= getOldProperties().getProperties();
		
		return JMXUtil.attributeListToStringMap( props );
	
public java.lang.String[]getPropertyNames()

		final Set<String>	names	= getProperties().keySet();
		
		return( GSetUtil.toStringArray( names ) );
	
public java.lang.StringgetPropertyValue(java.lang.String propertyName)

		return( getOldProperties().getPropertyValue( propertyName ) );
	
private java.lang.StringgetSimpleInterfaceName(com.sun.appserv.management.base.AMX amx)

        final String fullInterfaceName  = Util.getExtra( amx ).getInterfaceName();
        final String interfaceName   = ClassUtil.stripPackageName( fullInterfaceName );
        
        return interfaceName;
    
protected final java.util.SetgetSuperfluousMethods()

	    final Set<String>   items   = super.getSuperfluousMethods();
	    
	    final Method[]  methods = this.getClass().getMethods();
	    for( final Method m : methods )
	    {
	        final String    name    = m.getName();
	        
	        if (    isConfigFactoryGetter( name ) ||
	                isRemoveConfig( name ) ||
	                isCreateConfig( name ) )
	        {
	            if ( m.getParameterTypes().length <= 1 )
	            {
	                items.add( name );
	            }
	        }
	    }
	    
	    return items;
	
public java.util.MapgetSystemProperties()

		final AttributeList	props	= getOldSystemProperties().getSystemProperties();
		
		final Map<String,String> result	= JMXUtil.attributeListToStringMap( props );
		
		return result;
	
public java.lang.String[]getSystemPropertyNames()

		final Set<String>	names	= getSystemProperties().keySet();
		
		return( GSetUtil.toStringArray( names ) );
	
public java.lang.StringgetSystemPropertyValue(java.lang.String propertyName)

		return( getOldSystemProperties().getSystemPropertyValue( propertyName ) );
	
protected final voidimplCheck()

	    super.implCheck();
	    
	    // not sure how to implement these checks in offline mode
	    if ( ! com.sun.enterprise.management.support.BootUtil.getInstance().getOffline() )
	    {
    	    checkPropertiesAccessSupport();
    	    checkSystemPropertiesAccessSupport();
	    }
	    
	    checkInterfaceSupport( Description.class, "Description" );
	    checkInterfaceSupport( ObjectType.class, "ObjectType" );
	    checkInterfaceSupport( Enabled.class, "Enabled" );
    
protected java.lang.ObjectinvokeManually(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)
Automatically figure out getFactory(), createConfig(), removeConfig().

	
                                      
    	 
	
		 		
			
			 
		    
	
	    final int   numArgs = args == null ? 0 : args.length;
	    
	    Object  result  = null;
	    
	    debugMethod( operationName, args );
	    
	    if ( isConfigFactoryGetter( operationName, args, types ) &&
	         ConfigFactoryCallback.class.isAssignableFrom( this.getClass() ) )
	    {
	        debug( "looking for factory denoted by " + operationName );
	        result  = createConfigFactory( operationName );
			if ( result == null )
			{
	            debug( "FAILED TO FIND factory denoted by " + operationName );
	            result  = super.invokeManually( operationName, args, types );
			}
	    }
	    else if ( isRemoveConfig( operationName, args, types ) )
	    {
	        try
	        {
	            if ( numArgs == 0 )
	            {
	                // a single, possibly unnamed containee
	                removeConfig( operationName );
	            }
	            else
	            {
	                removeConfig( operationName, args, types );
	            }
	        }
	        catch( InvocationTargetException e )
	        {
	            throw new MBeanException( e );
	        }
	    }
	    else if ( isCreateConfig( operationName ) )
	    {
	        // name will be of the form create<XXX>Config
	        final String simpleInterfaceName  =
	            operationName.substring( CREATE_PREFIX.length(), operationName.length() );
	            
	        try
	        {
	            result  = createConfig( simpleInterfaceName, args, types);
	        }
	        catch( Exception e )
	        {
	            throw new MBeanException( e );
	        }
	    }
	    else
	    {
	        result  = super.invokeManually( operationName, args, types );
	    }
	    return result;
	
private booleanisConfigFactoryGetter(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)

        final int   numArgs = args == null ? 0 : args.length;
        
        return numArgs == 0  && isConfigFactoryGetter( operationName );
    
private booleanisConfigFactoryGetter(java.lang.String operationName)

        return operationName.startsWith( GET_PREFIX ) &&
	            operationName.endsWith( FACTORY_SUFFIX ) &&
                (! operationName.equals( "getProxyFactory" ) );
    
private booleanisCreateConfig(java.lang.String operationName)

        return operationName.startsWith( CREATE_PREFIX ) &&
	        operationName.endsWith( CONFIG_SUFFIX );
    
private booleanisRemoveConfig(java.lang.String operationName)

        return operationName.startsWith( REMOVE_PREFIX ) &&
	        operationName.endsWith( CONFIG_SUFFIX );
    
private booleanisRemoveConfig(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)

        final int   numArgs = args == null ? 0 : args.length;
        
        boolean isRemove    = numArgs <= 1 && isRemoveConfig( operationName );
        if ( isRemove && numArgs == 1 )
        {
            isRemove    = types[0].equals( String.class.getName() );
        }
        return isRemove;
    
protected java.lang.StringoperationNameToJ2EEType(java.lang.String operationName)

        String  j2eeType   = null;
        
        if ( isRemoveConfig( operationName ) ||
              isCreateConfig( operationName )  )
        {
            j2eeType   = XTypes.PREFIX + operationNameToSimpleClassname( operationName );
        }
        else
        {
            j2eeType    = super.operationNameToJ2EEType( operationName );
        }
        return j2eeType;
    
protected java.lang.StringoperationNameToSimpleClassname(java.lang.String operationName)
Return the simple (no package) classname associated with certain operations:
  • removeAbcConfig => AbcConfig
  • createAbcConfig => AbcConfig
  • getAbcConfig => AbcConfig

        
  
                                                                               
         
	    
    
        return StringUtil.findAndStripPrefix( CR_PREFIXES, operationName );
    
protected voidpreRemove(javax.management.ObjectName objectName)
Do anything necessary prior to removing an AMXConfig.

We have the situation where some of the com.sun.appserv MBeans behave by auto-creating references, even in EE, but not auto-removing, though in PE they are always auto-removed. So the algorithm varies by both release (PE vs EE) and by MBean. This is hopeless.

So first we attempt remove all references to the AMXCOnfig (if any). This will fail in PE, and may or may not fail in EE; we just ignore it so long as there is only one failure.

        final AMXConfig amxConfig = getProxy( objectName, AMXConfig.class );
        
        if ( amxConfig instanceof RefConfigReferent )
        {
            debug( "*** Removing all references to ", objectName );
            
            final Set<RefConfig>  failures    =
                RefHelper.removeAllRefsTo( (RefConfigReferent)amxConfig, true );
            if( failures.size() != 0 )
            {
                debug( "FAILURE removing references to " + objectName  + ": " +
                    CollectionUtil.toString( Util.toObjectNames( failures ) ) );
            }
	    }
	    else
	    {
            debug( "*** not a RefConfigReferent: ", objectName );
	    }
    
protected javax.management.ObjectNamepreRemove(java.util.Map items, java.lang.String name)
Make sure the item exists, then call preRemove( ObjectName ).

        if ( name == null )
        {
            throw new IllegalArgumentException( "null name" );
        }

        final ObjectName    objectName  = items.get( name );
        if ( objectName == null )
        {
            throw new IllegalArgumentException( "Item not found: " + name );
        }
        
        preRemove( objectName );
        
        return objectName;
    
public final voidremoveConfig(java.lang.String j2eeType, java.lang.String name)
Generic removal of any config contained by this config.

        if ( name == null )
        {
            throw new IllegalArgumentException();
        }

	    final Map<String,ObjectName>    items   = getContaineeObjectNameMap( j2eeType );
	    final ObjectName objectName   = preRemove( items, name );
        
        if ( ! removeConfigWithFactory( objectName ) )
        {
            debug( "removeConfigWithFactory failed, using removeConfigWithMethod" );
            removeConfigWithMethod( objectName );
        }
    
protected voidremoveConfig(java.lang.String operationName)
Remove config for a singleton Containee.

        final String        j2eeType    = operationNameToJ2EEType( operationName );
        final ObjectName    objectName  = getContaineeObjectName( j2eeType );
        if ( objectName == null )
        {
            throw new RuntimeException( new InstanceNotFoundException( j2eeType ) );
        }
	    preRemove( objectName );
        
        final String simpleInterfaceName    =
            operationName.substring( REMOVE_PREFIX.length(), operationName.length());
            
        createConfigFactory( simpleInterfaceName ).remove( objectName );
   
protected voidremoveConfig(java.lang.String operationName, java.lang.Object[] args, java.lang.String[] types)
Remove config for a named Containee.

        final String name    = (String)args[ 0 ];
        final String simpleInterfaceName    =
            operationName.substring( REMOVE_PREFIX.length(), operationName.length());
            
        final Set<? extends AMX>  containees  = getFactoryContainer().getContaineeSet();
        ObjectName  objectName  = null;
        for( final AMX containee : containees )
        {
            if ( containee.getName().equals( name ) )
            {
                debug( "removeConfig: found name match: " + Util.getObjectName( containee ) );
                if ( getSimpleInterfaceName( containee ).equals( simpleInterfaceName ) )
	            {
	                objectName  = Util.getObjectName( containee );
	                break;
	            }
	            debug( getSimpleInterfaceName( containee ), " != ", simpleInterfaceName );
            }
        }
        
        if ( objectName != null )
        {
            final AMX   amx = getProxy( objectName, AMX.class);
                
            removeConfig( amx.getJ2EEType(), amx.getName() );
        }
        else
        {
    		throw new IllegalArgumentException( "Not found: " + name );
        }
   
protected final booleanremoveConfigWithFactory(javax.management.ObjectName objectName)
Remove the config by finding its ConfigFactory. The caller must have already called preRemove().

return
true for success.

        ConfigFactory factory    = null;
        
        boolean     attempted   = false;
        try
        {
            final AMXConfig amxConfig   = getProxy( objectName, AMXConfig.class );
            final String interfaceName   = getSimpleInterfaceName( amxConfig );
            debug( "removeConfigWithFactory: " + objectName );
            
            factory  = createConfigFactory( interfaceName );
        }
        catch( Exception e )
        {
            debug( ExceptionUtil.toString( e ) );
        }
        
        if ( factory != null )
        {
            attempted   = true;
                
            // some factories have remove(), because they remove a singleton
            // instance, and some have remove( ObjectName )
            try
            {
                final Method m  = factory.getClass().getMethod( "remove", (Class[])null );
                if ( m != null )
                {
                    m.invoke( factory, (Object[])null );
                }
            }
            catch( NoSuchMethodException e )
            {
                factory.remove( objectName );
            }
            catch( Exception e )
            {
                throw new RuntimeException( e );
            }
        }
        
        return attempted;
    
protected final voidremoveConfigWithMethod(javax.management.ObjectName objectName)
Remove the config, if possible, by finding a method of the appropriate name. Usually, removeConfigWithFactory() should have been used instead.

The caller must have already called preRemove().

A RuntimeException is thrown if an appropriate method cannot be found.

    
                                                                                                          
          
        
    
        final AMXConfig amxConfig   = getProxy( objectName, AMXConfig.class );
        final String interfaceName   = getSimpleInterfaceName( amxConfig );
        if ( ! interfaceName.endsWith( CONFIG_SUFFIX ) )
        {
            throw new IllegalArgumentException(
                "Interface doesn't end in " + CONFIG_SUFFIX + ": " + interfaceName );
        }
            
        // do it generically by constructing the expected method name,
        // and then calling it.
        final String operationName = REMOVE_PREFIX + interfaceName;
        debug( "removing config generically by calling ", operationName, "()" );
        try
        {
			final Method m	=
			    this.getClass().getDeclaredMethod( operationName, STRING_SIG);
			
			m.invoke( this, amxConfig.getName() );
        }
        catch( Exception e )
        {
            throw new RuntimeException( e );
        }
     
public final voidremoveProperty(java.lang.String propertyName)

		validatePropertyName( propertyName );
		
		getOldProperties().setProperty( new Attribute( propertyName, null ) );
	
protected voidremoveRefConfig(java.lang.String j2eeType, java.lang.String name)
Generic removal of RefConfig.

        removeConfig( j2eeType, name );
    
public final voidremoveSystemProperty(java.lang.String propertyName)

		validatePropertyName( propertyName );
		
		getOldSystemProperties().setSystemProperty( new Attribute( propertyName, null ) );
	
public voidsendConfigCreatedNotification(javax.management.ObjectName configObjectName)

		sendNotification( AMXConfig.CONFIG_CREATED_NOTIFICATION_TYPE,
		    AMXConfig.CONFIG_REMOVED_NOTIFICATION_TYPE,
			AMXConfig.CONFIG_OBJECT_NAME_KEY, configObjectName );
	
public voidsendConfigRemovedNotification(javax.management.ObjectName configObjectName)

		sendNotification( AMXConfig.CONFIG_REMOVED_NOTIFICATION_TYPE,
		    AMXConfig.CONFIG_REMOVED_NOTIFICATION_TYPE,
			AMXConfig.CONFIG_OBJECT_NAME_KEY, configObjectName );
	
public final voidsetPropertyValue(java.lang.String propertyName, java.lang.String propertyValue)

		validatePropertyName( propertyName );
		
		if ( propertyValue == null  )
		{
			throw new IllegalArgumentException( "null" );
		}

		final Attribute		attr	= new Attribute( propertyName, propertyValue );
		
		getOldProperties().setProperty( attr );
	
public final voidsetSystemPropertyValue(java.lang.String propertyName, java.lang.String propertyValue)

		validatePropertyName( propertyName );
		
		if ( propertyValue == null  )
		{
			throw new IllegalArgumentException( "" + null );
		}

		final Attribute		attr	= new Attribute( propertyName, propertyValue );
		
		getOldSystemProperties().setSystemProperty( attr );
	
protected booleansupportsProperties()

	    return PropertiesAccess.class.isAssignableFrom( getInterface() );
	
protected booleansupportsSystemProperties()

	    return SystemPropertiesAccess.class.isAssignableFrom( getInterface() );
	
private static voidvalidatePropertyName(java.lang.String propertyName)

		if ( propertyName == null ||
			propertyName.length() == 0 )
		{
			throw new IllegalArgumentException( "Illegal property name: " +
				StringUtil.quote( propertyName ) );
		}