1 16 package org.jmanage.cmdui.commands; 17 18 import org.jmanage.cmdui.CommandConstants; 19 import org.jmanage.cmdui.CommandHandler; 20 import org.jmanage.cmdui.HandlerContext; 21 import org.jmanage.cmdui.util.CommandUtils; 22 import org.jmanage.cmdui.util.Out; 23 import org.jmanage.core.data.AttributeListData; 24 import org.jmanage.core.services.MBeanService; 25 import org.jmanage.core.services.ServiceContext; 26 import org.jmanage.core.services.ServiceFactory; 27 import org.jmanage.core.util.Expression; 28 29 35 public class GetHandler implements CommandHandler { 36 37 42 public boolean execute(HandlerContext context) { 43 44 String [] args = context.getCommand().getArgs(); 45 if(args.length == 0){ 46 usage(); 47 return false; 48 } 49 50 Expression expression = new Expression(args[0]); 51 52 MBeanService service = ServiceFactory.getMBeanService(); 53 54 String [] attributeNames = null; 55 if(args.length > 1){ 56 attributeNames = new String [args.length - 1]; 57 for(int i=0; i< attributeNames.length; i++){ 58 attributeNames[i] = args[i+1]; 59 } 60 } 61 ServiceContext serviceContext = 62 context.getServiceContext(expression.getAppName(), 63 expression.getMBeanName()); 64 AttributeListData[] attributeValues = null; 65 if(attributeNames != null){ 66 attributeValues = service.getAttributes(serviceContext, 67 attributeNames, true); 68 }else{ 69 attributeValues = service.getAttributes(serviceContext); 70 } 71 CommandUtils.printAttributeLists(attributeValues); 72 return true; 73 } 74 75 public String getShortHelp() { 76 return "Gets attribute values for given mbean."; 77 } 78 79 public void help() { 80 Out.println(getShortHelp()); 81 Out.println("Usage:"); 82 Out.println(CommandConstants.GET + 83 " <application name>/<mbean name> [attribute1] [attribute2] ..."); 84 Out.println(); 85 Out.println("Examples:"); 86 Out.println(CommandConstants.GET + 87 " myApp/myMBean"); 88 Out.println(CommandConstants.GET + 89 " myApp/jmanage:name=TestMBean testAttr1 testAttr2"); 90 } 91 92 93 private void usage(){ 94 Out.println("Invalid arguments"); 95 help(); 96 } 97 } 98 | Popular Tags |