} catch (NumberFormatException e) {
throw new ParseException("Port must be a number");
}
}
ServerProbe probe = null;
try {
probe = new JmxServerProbe(host, port);
} catch (IOException ioe) {
System.err.println("Error connecting to remote JMX agent!");
ioe.printStackTrace();
System.exit(3);
}
ServerCmd sCmd = new ServerCmd();
// Execute the requested command.
String[] arguments = cmd.getArgs();
String cmdName = arguments[0];
CmdType cmdType = null;
try {
cmdType = CmdType.lookup(cmdName);
if (CmdType.ADDUSER.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.addUser(arguments[1], arguments[2]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.REMOVEUSER.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.removeUser(arguments[1]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.LISTUSERS.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
sCmd.print(probe.listUsers(), System.out);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.ADDDOMAIN.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.addDomain(arguments[1]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.REMOVEDOMAIN.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.removeDomain(arguments[1]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.CONTAINSDOMAIN.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.containsDomain(arguments[1]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.LISTDOMAINS.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
sCmd.print(probe.listDomains(), System.out);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.LISTMAPPINGS.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
sCmd.print(probe.listMappings(), System.out);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.LISTUSERDOMAINMAPPINGS.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
Collection<String> userDomainMappings = probe.listUserDomainMappings(arguments[1], arguments[2]);
sCmd.print(userDomainMappings.toArray(new String[userDomainMappings.size()]), System.out);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.ADDADDRESSMAPPING.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.addAddressMapping(arguments[1], arguments[2], arguments[3]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.REMOVEADDRESSMAPPING.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.removeAddressMapping(arguments[1], arguments[2], arguments[3]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.ADDREGEXMAPPING.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.addRegexMapping(arguments[1], arguments[2], arguments[3]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.REMOVEREGEXMAPPING.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.removeRegexMapping(arguments[1], arguments[2], arguments[3]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.SETPASSWORD.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.setPassword(arguments[1], arguments[2]);
} else {
printUsage();
System.exit(1);
}
} else if (CmdType.COPYMAILBOX.equals(cmdType)) {
if (cmdType.hasCorrectArguments(arguments.length)) {
probe.copyMailbox(arguments[1], arguments[2]);
} else {
printUsage();
System.exit(1);
}
} else {