1 22 package org.jboss.console.twiddle.command; 23 24 import java.util.Set ; 25 26 import javax.management.ObjectName ; 27 import javax.management.MBeanServerConnection ; 28 import javax.management.MalformedObjectNameException ; 29 30 31 38 public abstract class MBeanServerCommand 39 extends AbstractCommand 40 { 41 protected MBeanServerCommand(final String name, final String desc) 42 { 43 super(name, desc); 44 } 45 46 protected ObjectName createObjectName(final String name) 47 throws CommandException 48 { 49 try { 50 return new ObjectName (name); 51 } 52 catch (MalformedObjectNameException e) { 53 throw new CommandException("Invalid object name: " + name); 54 } 55 } 56 57 protected MBeanServerConnection getMBeanServer() 58 { 59 return context.getServer(); 60 } 61 62 protected ObjectName [] queryMBeans(final String query) 63 throws Exception 64 { 65 MBeanServerConnection server = getMBeanServer(); 67 68 Set matches = server.queryNames(new ObjectName (query), null); 69 log.debug("Query matches: " + matches); 70 71 if (matches.size() == 0) { 72 throw new CommandException("No MBean matches for query: " + query); 73 } 74 75 ObjectName [] names = 76 (ObjectName [])matches.toArray(new ObjectName [matches.size()]); 77 78 return names; 79 } 80 } 81 | Popular Tags |