FileDocCategorySizeDatePackage
UnregisterCommand.javaAPI DocJBoss 4.2.13852Fri Jul 13 21:02:16 BST 2007org.jboss.console.twiddle.command

UnregisterCommand

public class UnregisterCommand extends MBeanServerCommand
Unregister one or more MBeans.
version
$Revision: 57191 $
author
Jason Dillon
author
Scott.Stark@jboss.com

Fields Summary
private List
names
Constructors Summary
public UnregisterCommand()

   
    
   
      super("unregister", "Unregister one or more MBeans");
   
Methods Summary
public voiddisplayHelp()

      PrintWriter out = context.getWriter();
      
      out.println(desc);
      out.println();
      out.println("usage: " + name + " [options] (<name>)+");
      out.println();
      out.println("options:");
      out.println("    --    Stop processing options");

      out.flush();
   
public voidexecute(java.lang.String[] args)

      processArguments(args);

      log.debug("object names: " + names);

      if (names.size() == 0)
         throw new CommandException("At least one object name is required");

      MBeanServerConnection server = getMBeanServer();

      Iterator iter = names.iterator();
      while (iter.hasNext())
      {
         ObjectName name = (ObjectName)iter.next();
         server.unregisterMBean(name);
      }
   
private voidprocessArguments(java.lang.String[] args)

      log.debug("processing arguments: " + Strings.join(args, ","));

      if (args.length == 0) {
         throw new CommandException("Command requires arguments");
      }
      
      String sopts = "-:";
      LongOpt[] lopts =
      {
         // new LongOpt("count", LongOpt.NO_ARGUMENT, null, 'c'),
      };

      Getopt getopt = new Getopt(null, args, sopts, lopts);
      getopt.setOpterr(false);
      
      int code;
      int argidx = 0;
      
      while ((code = getopt.getopt()) != -1)
      {
         switch (code)
         {
            case ':":
               throw new CommandException
                  ("Option requires an argument: "+ args[getopt.getOptind() - 1]);

            case '?":
               throw new CommandException
                  ("Invalid (or ambiguous) option: " + args[getopt.getOptind() - 1]);

            // non-option arguments
            case 1:
            {
               String arg = getopt.getOptarg();
               
               switch (argidx++) {
                  default:
                     names.add(createObjectName(arg));
                     break;
               }
               break;
            }
         }
      }