Sun Java System Application Server Platform Edition 8.1 2005Q2 Update 2 Developer's Guide

- Previous: Accessing AMX MBeans
- Next: Listing AMX MBean Properties

## Accessing and Displaying the Attributes of an AMX MBean

The `displayAllAttributes()` method demonstrates how to access and display the attributes of an AMX MBean.

##### Example 16–9 Accessing and Displaying the Attributes of an AMX MBean

    [...]
    displayAllAttributes( final AMX item )
    {
        println( "\n--- Attributes for " + item.getJ2EEType() +
            "=" + item.getName() + " ---" );
        final Extra extra = Util.getExtra( item );
        final Map attrs    = extra.getAllAttributes();
        final Iterator iter = attrs.keySet().iterator();
        while ( iter.hasNext() )
        {
            final String name = (String)iter.next();
            final Object value = attrs.get( name );
            println( name + "=" + toString( value ) );
        }
    }
    public void
    displayAllAttributes( final String j2eeType )
    {
        final Set items = queryForJ2EEType( j2eeType );
        if ( items.size() == 0 )
        {
            println( "No {@link AMX} of j2eeType "
                + SampleUtil.quote( j2eeType ) + " found" );
        }
        else
        {
            final Iterator iter= items.iterator();
            while ( iter.hasNext() )
            {
                final AMX amx = (AMX)iter.next();
                displayAllAttributes( amx );
                println( "" );
            }
        }
    }
    [...]

The `displayAllAttributes()` method calls the `AMX.getName()` and `AMX.getJ2EEType()` methods for an AMX MBean and prints the results onscreen. It then gets all the attributes for that MBean by calling `com.sun.appserv.management.base.Extra.getAllAttributes()` on the `Extra` instance returned by `com.sun.appserv.management.base.Util.getExtra()`. This is repeated for every MBean.

The attributes of AMX MBeans of a certain J2EE type can be displayed by specifying the J2EE type when the command is run. In this case, `displayAllAttributes()` calls `queryForJ2EEType()`. The `queryForJ2EEType()` method calls the `com.sun.appserv.management.base.QueryManager.queryPropSet()` method on the specified J2EE type to identify all elements of that type in the domain.

- Previous: Accessing AMX MBeans
- Next: Listing AMX MBean Properties

- © 2010, Oracle Corporation and/or its affiliates