FileDocCategorySizeDatePackage
MBeanLocatorImpl.javaAPI DocGlassfish v2 API4809Fri May 04 22:33:34 BST 2007com.sun.enterprise.admin.event

MBeanLocatorImpl

public class MBeanLocatorImpl extends Object implements MBeanLocator
Implementation of mbeanLocator by using QueryNames
author
Satish Viswanatham

Fields Summary
static Logger
logger
static final String
UNSUPPORTED_TYPE
static final String
MALFORMED_OBJECT_KEY
Constructors Summary
Methods Summary
public java.lang.Objectlocate(java.lang.Object objectKey)
This method returns the mbean of interest for the event/notification

param
Object object key -- it could EventKey, ObjectName or String
return
Object proxy for the mbean that is of interest


                                         
        
                 
        ObjectName on = null;
        QueryExp e = null;

        if ( objectKey instanceof EventKey ) {
            EventKey eKey = (EventKey) objectKey;
            on = eKey.getObjectName();
            e = eKey.getQuery();
        } else if ( objectKey instanceof ObjectName) {
            on = (ObjectName) objectKey;
        } else if ( objectKey instanceof String ) {
            try {
                on = new ObjectName( (String) objectKey);
            } catch ( Exception exp ) {
               logger.log(Level.WARNING, MALFORMED_OBJECT_KEY, objectKey);
               return null;
            }
        } else {
            if ( objectKey != null ) 
                logger.log(Level.WARNING, UNSUPPORTED_TYPE, objectKey.getClass().getName());
            return null;
        }

        return MBeanServerFactory.getMBeanServer().queryMBeans(on, e);
    
public static voidmain(java.lang.String[] args)


        /* fix this later so that
         *  local can take MBeanServerproxy can be tested that way
         */
        if ( args.length < 1 ) 
        {
            System.out.println("Usage:  <object name> ");
            System.exit(3);
        }

        String name = args[0];
        System.out.println("name is " + args[0]);
        MBeanLocatorImpl m = new MBeanLocatorImpl();
        Set s = null;
        try {
           s = (Set)m.locate(new ObjectName(name));
        } catch (MalformedObjectNameException e ) {
            System.out.println("Please enter a valid object name ");
            System.exit(1);
        } catch ( NullPointerException  e) {
            System.out.println("Please enter a non null object name ");
            System.exit(2);
        }
        System.out.println(" The number of beans matched that description " + s.size());