Sun Java System Application Server Enterprise Edition 8.1 2005Q2 Developer's Guide

- Previous: Accessing and Displaying the Attributes of an AMX MBean
- Next: Querying

## Listing AMX MBean Properties

The `displayAllProperties()` demonstrates how to list AMX MBean properties.

##### Example 16–10 Listing AMX MBean Properties

    [...]
    getProperties( final PropertiesAccess pa )
    {
        final HashMap m = new HashMap();
        final String[] names = pa.getPropertyNames();
        for( int i = 0; i < names.length; ++i )
        {
            m.put( names[ i ], pa.getPropertyValue( names[ i ] ) );
        }
        return( m );
    }
    public void
    displayAllProperties( )
    {
        final Iterator iter    = getQueryMgr().queryAllSet().iterator();
        while ( iter.hasNext() )
        {
            final AMX amx = (AMX)iter.next();
            if ( amx instanceof PropertiesAccess )
            {
                final PropertiesAccess pa = (PropertiesAccess)amx;
                final Map    props    = getProperties( pa );
                if ( props.keySet().size() != 0 )
                {
                    println( "\nProperties for:
                        " + Util.getObjectName( AMX)pa ) );
                    println( SampleUtil.mapToString(getProperties(pa), "\n") );
                }
            }
        }
    }
    [...]

The `displayAllProperties()` method uses another `Samples` method, `getProperties()`. This method creates an instance of the `com.sun.appserv.management.config.PropertiesAccess` interface, and calls its `getPropertyNames()` method to obtain the names of all the properties for a given AMX MBean. For each property name obtained, its corresponding value is obtained by calling `PropertiesAccess.getPropertyValue()`.

The `displayAllProperties()` method calls the `com.sun.appserv.management.base.QueryMgr.queryAllSet()` method to obtain a set of all the AMX MBeans present in the domain. All AMX MBeans that have properties obligatorily extend the `PropertiesAccess` interface. Any MBean found to extend `PropertiesAccess` is passed to the `getProperties()` method, and the list of property values returned is printed onscreen.

- Previous: Accessing and Displaying the Attributes of an AMX MBean
- Next: Querying

- © 2010, Oracle Corporation and/or its affiliates