1 23 24 package com.sun.enterprise.admin.event; 25 26 import java.util.Set ; 27 import com.sun.enterprise.admin.common.MBeanServerFactory; 28 import javax.management.ObjectName ; 29 import javax.management.QueryExp ; 30 import javax.management.MalformedObjectNameException ; 31 32 import com.sun.enterprise.admin.common.constant.AdminConstants; 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 36 37 42 public class MBeanLocatorImpl implements MBeanLocator{ 43 44 static Logger logger = Logger.getLogger(AdminConstants.kLoggerName); 45 46 static final String UNSUPPORTED_TYPE = "event.event_key_type_not_supported"; 47 48 static final String MALFORMED_OBJECT_KEY = "event.event_key_is_malformed"; 49 50 56 public Object locate(Object objectKey) { 57 58 ObjectName on = null; 59 QueryExp e = null; 60 61 if ( objectKey instanceof EventKey ) { 62 EventKey eKey = (EventKey) objectKey; 63 on = eKey.getObjectName(); 64 e = eKey.getQuery(); 65 } else if ( objectKey instanceof ObjectName ) { 66 on = (ObjectName ) objectKey; 67 } else if ( objectKey instanceof String ) { 68 try { 69 on = new ObjectName ( (String ) objectKey); 70 } catch ( Exception exp ) { 71 logger.log(Level.WARNING, MALFORMED_OBJECT_KEY, objectKey); 72 return null; 73 } 74 } else { 75 if ( objectKey != null ) 76 logger.log(Level.WARNING, UNSUPPORTED_TYPE, objectKey.getClass().getName()); 77 return null; 78 } 79 80 return MBeanServerFactory.getMBeanServer().queryMBeans(on, e); 81 } 82 83 public static void main (String [] args) { 84 85 88 if ( args.length < 1 ) 89 { 90 System.out.println("Usage: <object name> "); 91 System.exit(3); 92 } 93 94 String name = args[0]; 95 System.out.println("name is " + args[0]); 96 MBeanLocatorImpl m = new MBeanLocatorImpl(); 97 Set s = null; 98 try { 99 s = (Set )m.locate(new ObjectName (name)); 100 } catch (MalformedObjectNameException e ) { 101 System.out.println("Please enter a valid object name "); 102 System.exit(1); 103 } catch ( NullPointerException e) { 104 System.out.println("Please enter a non null object name "); 105 System.exit(2); 106 } 107 System.out.println(" The number of beans matched that description " + s.size()); 108 109 } 110 111 } 112 | Popular Tags |