james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1400047 - in /james/server/trunk/cli: ./ src/main/java/org/apache/james/cli/ src/main/java/org/apache/james/cli/probe/ src/main/java/org/apache/james/cli/probe/impl/ src/main/java/org/apache/james/cli/type/
Date Fri, 19 Oct 2012 11:35:14 GMT
Author: eric
Date: Fri Oct 19 11:35:13 2012
New Revision: 1400047

URL: http://svn.apache.org/viewvc?rev=1400047&view=rev
Log:
Copy mailbox from CLI (JAMES-1439)

Modified:
    james/server/trunk/cli/pom.xml
    james/server/trunk/cli/src/main/java/org/apache/james/cli/ServerCmd.java
    james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
    james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
    james/server/trunk/cli/src/main/java/org/apache/james/cli/type/CmdType.java

Modified: james/server/trunk/cli/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/cli/pom.xml?rev=1400047&r1=1400046&r2=1400047&view=diff
==============================================================================
--- james/server/trunk/cli/pom.xml (original)
+++ james/server/trunk/cli/pom.xml Fri Oct 19 11:35:13 2012
@@ -48,6 +48,10 @@
             <artifactId>james-server-data-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.james</groupId>
+            <artifactId>james-server-container-spring</artifactId>
+        </dependency>
+        <dependency>
             <groupId>commons-cli</groupId>
             <artifactId>commons-cli</artifactId>
         </dependency>

Modified: james/server/trunk/cli/src/main/java/org/apache/james/cli/ServerCmd.java
URL: http://svn.apache.org/viewvc/james/server/trunk/cli/src/main/java/org/apache/james/cli/ServerCmd.java?rev=1400047&r1=1400046&r2=1400047&view=diff
==============================================================================
--- james/server/trunk/cli/src/main/java/org/apache/james/cli/ServerCmd.java (original)
+++ james/server/trunk/cli/src/main/java/org/apache/james/cli/ServerCmd.java Fri Oct 19 11:35:13 2012
@@ -41,261 +41,268 @@ import org.apache.james.cli.type.CmdType
  * Command line utility for managing various aspect of the James server.
  */
 public class ServerCmd {
-    private static final String HOST_OPT_LONG = "host";
-    private static final String HOST_OPT_SHORT = "h";
-    private static final String PORT_OPT_LONG = "port";
-    private static final String PORT_OPT_SHORT = "p";
-    private static final int defaultPort = 9999;
-    private static Options options = null;
-
-    static {
-        options = new Options();
-        Option optHost = new Option(HOST_OPT_SHORT, HOST_OPT_LONG, true, "node hostname or ip address");
-        optHost.setRequired(true);
-        options.addOption(optHost);
-        options.addOption(PORT_OPT_SHORT, PORT_OPT_LONG, true, "remote jmx agent port number");
-    }
-
-    /**
-     * Main method to initialize the class.
-     * 
-     * @param args
-     *            Command-line arguments.
-     * @throws IOException
-     * @throws InterruptedException
-     * @throws ParseException
-     */
-    public static void main(String[] args) throws IOException, InterruptedException, ParseException {
-        
-        long start = Calendar.getInstance().getTimeInMillis();
-        
-        CommandLineParser parser = new PosixParser();
-        CommandLine cmd = null;
-
-        try {
-            cmd = parser.parse(options, args);
-        } catch (ParseException parseExcep) {
-            System.err.println(parseExcep);
-            printUsage();
-            System.exit(1);
-        }
-
-        // Verify arguments
-        if (cmd.getArgs().length < 1) {
-            System.err.println("Missing argument for command.");
-            printUsage();
-            System.exit(1);
-        }
-        
-        String host = cmd.getOptionValue(HOST_OPT_LONG);
-        int port = defaultPort;
-
-        String portNum = cmd.getOptionValue(PORT_OPT_LONG);
-        if (portNum != null) {
-            try {
-                port = Integer.parseInt(portNum);
-            } 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)) {
-                    sCmd.print(probe.listUserDomainMappings(arguments[1], arguments[2]).toArray(new String[0]), 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 {
-                System.err.println("Unrecognized command: " + cmdName + ".");
-                printUsage();
-                System.exit(1);
-            }
-        } catch (Exception e) {
-            sCmd.onException(e, System.err);
-            System.exit(1);
-        }
-        
-        sCmd.print(new String[]{cmdType.getCommand() + " command executed sucessfully in " 
-                + (Calendar.getInstance().getTimeInMillis() - start) + " ms."}, System.out);
-        System.exit(0);
-    }
-
-    /**
-     * Print data to an output stream.
-     * 
-     * @param data
-     *            The data to print, each element representing a line.
-     * @param out
-     *            The output stream to which printing should occur.
-     */
-    public void print(String[] data, PrintStream out) {
-        if (data == null)
-            return;
-        
-        for (int i = 0; i < data.length; i++) {
-            String u = data[i];
-            out.println(u);
-        }
-        
-        out.println();
-    }
-
-    public void print(Map<String,Collection<String>> map, PrintStream out) {
-        if (map == null)
-            return;
-        
-        Iterator<Entry<String, Collection<String>>> entries = map.entrySet().iterator();
-        while(entries.hasNext()) {
-            Entry<String, Collection<String>> entry = entries.next();
-            out.print(entry.getKey());
-            out.print("=");
-            out.println(entry.getValue().toString());
-        }
-        out.println();
-    }
-
-    
-    /*
-     * Prints usage information to stdout.
-     */
-    private static void printUsage() {
-        HelpFormatter hf = new HelpFormatter();
-        String header = String.format("%nAvailable commands:%n" 
-                + "adduser <username> <password>%n"
-                + "setpassword <username> <password>%n"
-                + "removeuser <username>%n" 
-                + "listusers%n" 
-                + "adddomain <domainname>%n"
-                + "containsdomain <domainname>%n" 
-                + "removedomain <domainname>%n" 
-                + "listdomains%n"
-                + "addAddressMapping <user> <domain> <fromaddress>%n"
-                + "removeAddressMapping <user> <domain> <fromaddress>%n"
-                + "addRegexMapping <user> <domain> <regex>%n"
-                + "removeRegexMapping <user> <domain> <regex>%n"
-                + "listuserdomainmappings <user> <domain>%n"
-                + "listmappings%n"
-                );
-        String usage = String.format("java %s --host <arg> <command>%n", ServerCmd.class.getName());
-        hf.printHelp(usage, "", options, header);
-    }
-
-    /*
-     * Handle an exception.
-     */
-    private void onException(Exception e, PrintStream out) {
-        out.println("Error while execute command:");
-        out.println(e.getMessage());
-    }
+	private static final String HOST_OPT_LONG = "host";
+	private static final String HOST_OPT_SHORT = "h";
+	private static final String PORT_OPT_LONG = "port";
+	private static final String PORT_OPT_SHORT = "p";
+	private static final int defaultPort = 9999;
+	private static Options options = null;
+
+	static {
+		options = new Options();
+		Option optHost = new Option(HOST_OPT_SHORT, HOST_OPT_LONG, true, "node hostname or ip address");
+		optHost.setRequired(true);
+		options.addOption(optHost);
+		options.addOption(PORT_OPT_SHORT, PORT_OPT_LONG, true, "remote jmx agent port number");
+	}
+
+	/**
+	 * Main method to initialize the class.
+	 * 
+	 * @param args
+	 *            Command-line arguments.
+	 * @throws IOException
+	 * @throws InterruptedException
+	 * @throws ParseException
+	 */
+	public static void main(String[] args) throws IOException, InterruptedException, ParseException {
+
+		long start = Calendar.getInstance().getTimeInMillis();
+
+		CommandLineParser parser = new PosixParser();
+		CommandLine cmd = null;
+
+		try {
+			cmd = parser.parse(options, args);
+		} catch (ParseException parseExcep) {
+			System.err.println(parseExcep);
+			printUsage();
+			System.exit(1);
+		}
+
+		// Verify arguments
+		if (cmd.getArgs().length < 1) {
+			System.err.println("Missing argument for command.");
+			printUsage();
+			System.exit(1);
+		}
+
+		String host = cmd.getOptionValue(HOST_OPT_LONG);
+		int port = defaultPort;
+
+		String portNum = cmd.getOptionValue(PORT_OPT_LONG);
+		if (portNum != null) {
+			try {
+				port = Integer.parseInt(portNum);
+			} 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)) {
+					sCmd.print(probe.listUserDomainMappings(arguments[1], arguments[2]).toArray(new String[0]),
+					        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 {
+				System.err.println("Unrecognized command: " + cmdName + ".");
+				printUsage();
+				System.exit(1);
+			}
+		} catch (Exception e) {
+			sCmd.onException(e, System.err);
+			System.exit(1);
+		}
+
+		sCmd.print(new String[] { cmdType.getCommand() + " command executed sucessfully in "
+		        + (Calendar.getInstance().getTimeInMillis() - start) + " ms." }, System.out);
+		System.exit(0);
+	}
+
+	/**
+	 * Print data to an output stream.
+	 * 
+	 * @param data
+	 *            The data to print, each element representing a line.
+	 * @param out
+	 *            The output stream to which printing should occur.
+	 */
+	public void print(String[] data, PrintStream out) {
+		if (data == null)
+			return;
+
+		for (int i = 0; i < data.length; i++) {
+			String u = data[i];
+			out.println(u);
+		}
+
+		out.println();
+	}
+
+	public void print(Map<String, Collection<String>> map, PrintStream out) {
+		if (map == null)
+			return;
+
+		Iterator<Entry<String, Collection<String>>> entries = map.entrySet().iterator();
+		while (entries.hasNext()) {
+			Entry<String, Collection<String>> entry = entries.next();
+			out.print(entry.getKey());
+			out.print("=");
+			out.println(entry.getValue().toString());
+		}
+		out.println();
+	}
+
+	/**
+	 * Prints usage information to stdout.
+	 */
+	private static void printUsage() {
+		HelpFormatter hf = new HelpFormatter();
+		String header = String.format("%nAvailable commands:%n" + //
+		        "adduser <username> <password>%n" + //
+		        "setpassword <username> <password>%n" + //
+		        "removeuser <username>%n" + "listusers%n" + //
+		        "adddomain <domainname>%n" + //
+		        "containsdomain <domainname>%n" + //
+		        "removedomain <domainname>%n" + //
+		        "listdomains%n" + //
+		        "addaddressmapping <user> <domain> <fromaddress>%n" + //
+		        "removeaddressmapping <user> <domain> <fromaddress>%n" + //
+		        "addregexmapping <user> <domain> <regex>%n" + //
+		        "removeregexmapping <user> <domain> <regex>%n" + //
+		        "listuserdomainmappings <user> <domain>%n" + //
+		        "listmappings%n" + //
+		        "copymailbox <srcbean> <dstbean>%n" //
+		);
+		String usage = String.format("java %s --host <arg> <command>%n", ServerCmd.class.getName());
+		hf.printHelp(usage, "", options, header);
+	}
+
+	/**
+	 * Handle an exception.
+	 */
+	private void onException(Exception e, PrintStream out) {
+		out.println("Error while execute command:");
+		out.println(e.getMessage());
+	}
 }

Modified: james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java
URL: http://svn.apache.org/viewvc/james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java?rev=1400047&r1=1400046&r2=1400047&view=diff
==============================================================================
--- james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java (original)
+++ james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/ServerProbe.java Fri Oct 19 11:35:13 2012
@@ -22,152 +22,164 @@ import java.util.Collection;
 import java.util.Map;
 
 public interface ServerProbe {
-    /**
-     * Add a user to this mail server.
-     * 
-     * @param userName
-     *            The name of the user being added.
-     * @param password
-     *            The password of the user being added.
-     * @throws Exception
-     */
-    public void addUser(String userName, String password) throws Exception;
-
-    /**
-     * Delete a user from this mail server.
-     * 
-     * @param username
-     *            The name of the user being deleted.
-     * @throws Exception
-     */
-    public void removeUser(String username) throws Exception;
-
-    /**
-     * Get a List the names of all users.
-     * 
-     * @return a List of all user names.
-     * @throws Exception
-     */
-    public String[] listUsers() throws Exception;
-
-    /**
-     * Set a user's password.
-     * 
-     * @param userName
-     *            The name of the user whose password will be changed.
-     * @param password
-     *            The new password.
-     * @throws Exception
-     */
-    public void setPassword(String userName, String password) throws Exception;
-
-    /**
-     * Add domain to the service.
-     * 
-     * @param domain
-     *            The domain to add.
-     * @throws Exception
-     */
-    public void addDomain(String domain) throws Exception;
-
-    /**
-     * Return true if the domain exists in the service
-     * 
-     * @param domain
-     *            The domain to remove.
-     * @throws Exception
-     */
-    public boolean containsDomain(String domain) throws Exception;
-
-    /**
-     * Remove domain from the service
-     * 
-     * @param domain
-     *            The domain to remove.
-     * @throws Exception
-     */
-    public void removeDomain(String domain) throws Exception;
-
-    /**
-     * Get a list of domains for the service.
-     * 
-     * @return domains an array of domains, or null if no domains exist.
-     * @throws Exception
-     */
-    public String[] listDomains() throws Exception;
-
-    /**
-     * Get a Map which holds all mappings. The key is the user@domain and the
-     * value is a Collection which holds all mappings.
-     * 
-     * @return a Map which holds all mappings.
-     * @throws Exception
-     */
-    public Map<String, Collection<String>> listMappings() throws Exception;
-
-    /**
-     * Add address mapping.
-     * 
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used.
-     * @param toAddress
-     *            The address.
-     * @throws Exception
-     */
-    public void addAddressMapping(String user, String domain, String toAddress) throws Exception;
-
-    /**
-     * Remove address mapping.
-     * 
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used
-     * @param fromAddress
-     *            The address.
-     * @throws Exception
-     */
-    public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception;
-
-    /**
-     * Return the explicit mapping stored for the given user and domain. Return
-     * null if no mapping was found
-     * 
-     * @param user
-     *            The username.
-     * @param domain
-     *            The domain.
-     * @return the collection which holds the mappings, or null if no mapping is
-     *         found.
-     * @throws Exception
-     */
-    public Collection<String> listUserDomainMappings(String user, String domain) throws Exception;
-
-    /**
-     * Remove regex mapping.
-     * 
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used.
-     * @param regex
-     *            The regex.
-     * @throws Exception
-     */
-    public void addRegexMapping(String user, String domain, String regex) throws Exception;
-
-    /**
-     * Remove regex mapping.
-     * 
-     * @param user
-     *            The username, or null if no username should be used.
-     * @param domain
-     *            The domain, or null if no domain should be used.
-     * @param regex
-     *            The regex.
-     * @throws Exception
-     */
-    public void removeRegexMapping(String user, String domain, String regex) throws Exception;
+	/**
+	 * Add a user to this mail server.
+	 * 
+	 * @param userName
+	 *            The name of the user being added.
+	 * @param password
+	 *            The password of the user being added.
+	 * @throws Exception
+	 */
+	public void addUser(String userName, String password) throws Exception;
+
+	/**
+	 * Delete a user from this mail server.
+	 * 
+	 * @param username
+	 *            The name of the user being deleted.
+	 * @throws Exception
+	 */
+	public void removeUser(String username) throws Exception;
+
+	/**
+	 * Get a List the names of all users.
+	 * 
+	 * @return a List of all user names.
+	 * @throws Exception
+	 */
+	public String[] listUsers() throws Exception;
+
+	/**
+	 * Set a user's password.
+	 * 
+	 * @param userName
+	 *            The name of the user whose password will be changed.
+	 * @param password
+	 *            The new password.
+	 * @throws Exception
+	 */
+	public void setPassword(String userName, String password) throws Exception;
+
+	/**
+	 * Add domain to the service.
+	 * 
+	 * @param domain
+	 *            The domain to add.
+	 * @throws Exception
+	 */
+	public void addDomain(String domain) throws Exception;
+
+	/**
+	 * Return true if the domain exists in the service
+	 * 
+	 * @param domain
+	 *            The domain to remove.
+	 * @throws Exception
+	 */
+	public boolean containsDomain(String domain) throws Exception;
+
+	/**
+	 * Remove domain from the service
+	 * 
+	 * @param domain
+	 *            The domain to remove.
+	 * @throws Exception
+	 */
+	public void removeDomain(String domain) throws Exception;
+
+	/**
+	 * Get a list of domains for the service.
+	 * 
+	 * @return domains an array of domains, or null if no domains exist.
+	 * @throws Exception
+	 */
+	public String[] listDomains() throws Exception;
+
+	/**
+	 * Get a Map which holds all mappings. The key is the user@domain and the
+	 * value is a Collection which holds all mappings.
+	 * 
+	 * @return a Map which holds all mappings.
+	 * @throws Exception
+	 */
+	public Map<String, Collection<String>> listMappings() throws Exception;
+
+	/**
+	 * Add address mapping.
+	 * 
+	 * @param user
+	 *            The username, or null if no username should be used.
+	 * @param domain
+	 *            The domain, or null if no domain should be used.
+	 * @param toAddress
+	 *            The address.
+	 * @throws Exception
+	 */
+	public void addAddressMapping(String user, String domain, String toAddress) throws Exception;
+
+	/**
+	 * Remove address mapping.
+	 * 
+	 * @param user
+	 *            The username, or null if no username should be used.
+	 * @param domain
+	 *            The domain, or null if no domain should be used
+	 * @param fromAddress
+	 *            The address.
+	 * @throws Exception
+	 */
+	public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception;
+
+	/**
+	 * Return the explicit mapping stored for the given user and domain. Return
+	 * null if no mapping was found
+	 * 
+	 * @param user
+	 *            The username.
+	 * @param domain
+	 *            The domain.
+	 * @return the collection which holds the mappings, or null if no mapping is
+	 *         found.
+	 * @throws Exception
+	 */
+	public Collection<String> listUserDomainMappings(String user, String domain) throws Exception;
+
+	/**
+	 * Remove regex mapping.
+	 * 
+	 * @param user
+	 *            The username, or null if no username should be used.
+	 * @param domain
+	 *            The domain, or null if no domain should be used.
+	 * @param regex
+	 *            The regex.
+	 * @throws Exception
+	 */
+	public void addRegexMapping(String user, String domain, String regex) throws Exception;
+
+	/**
+	 * Remove regex mapping.
+	 * 
+	 * @param user
+	 *            The username, or null if no username should be used.
+	 * @param domain
+	 *            The domain, or null if no domain should be used.
+	 * @param regex
+	 *            The regex.
+	 * @throws Exception
+	 */
+	public void removeRegexMapping(String user, String domain, String regex) throws Exception;
+
+	/**
+	 * Copy Mailbox.
+	 * 
+	 * @param srcBean
+	 *            The name of the bean that manages the source mailbox.
+	 * @param dstBean
+	 *            The name of the bean that manages the destination mailbox.
+	 * @throws Exception
+	 */
+	void copyMailbox(String srcBean, String dstBean) throws Exception;
+
 }

Modified: james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java
URL: http://svn.apache.org/viewvc/james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java?rev=1400047&r1=1400046&r2=1400047&view=diff
==============================================================================
--- james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java (original)
+++ james/server/trunk/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java Fri Oct 19 11:35:13 2012
@@ -31,175 +31,244 @@ import javax.management.remote.JMXConnec
 import javax.management.remote.JMXServiceURL;
 
 import org.apache.james.cli.probe.ServerProbe;
+import org.apache.james.container.spring.mailbox.MailboxCopierManagementMBean;
 import org.apache.james.domainlist.api.DomainListManagementMBean;
 import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean;
 import org.apache.james.user.api.UsersRepositoryManagementMBean;
 
+/**
+ * @author eric
+ * 
+ */
 public class JmxServerProbe implements ServerProbe {
 
-    // TODO: Move this to somewhere else
-    private final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist";
-    private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable";
-    private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository";
-
-    private MBeanServerConnection mbeanServerConn;
-    private DomainListManagementMBean domainListProcxy;
-    private RecipientRewriteTableManagementMBean virtualUserTableProxy;
-    private UsersRepositoryManagementMBean usersRepositoryProxy;
-
-    private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi";
-    private static final int defaultPort = 9999;
-    private String host;
-    private int port;
-
-    /**
-     * Creates a ServerProbe using the specified JMX host and port.
-     * 
-     * @param host
-     *            hostname or IP address of the JMX agent
-     * @param port
-     *            TCP port of the remote JMX agent
-     * @throws IOException
-     *             on connection failures
-     */
-    public JmxServerProbe(String host, int port) throws IOException, InterruptedException {
-        this.host = host;
-        this.port = port;
-        connect();
-    }
-
-    /**
-     * Creates a NodeProbe using the specified JMX host and default port.
-     * 
-     * @param host
-     *            hostname or IP address of the JMX agent
-     * @throws IOException
-     *             on connection failures
-     */
-    public JmxServerProbe(String host) throws IOException, InterruptedException {
-        this.host = host;
-        this.port = defaultPort;
-        connect();
-    }
-
-    /*
-     * Create a connection to the JMX agent and setup the M[X]Bean proxies.
-     * 
-     * @throws IOException
-     *             on connection failures
-     */
-    private void connect() throws IOException {
-        JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
-        JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl, null);
-        mbeanServerConn = jmxc.getMBeanServerConnection();
-
-        try {
-            ObjectName name = new ObjectName(DOMAINLIST_OBJECT_NAME);
-            domainListProcxy = (DomainListManagementMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServerConn, name, DomainListManagementMBean.class, true);
-            name = new ObjectName(VIRTUALUSERTABLE_OBJECT_NAME);
-            virtualUserTableProxy = (RecipientRewriteTableManagementMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServerConn, name, RecipientRewriteTableManagementMBean.class, true);
-            name = new ObjectName(USERSREPOSITORY_OBJECT_NAME);
-            usersRepositoryProxy = (UsersRepositoryManagementMBean) MBeanServerInvocationHandler.newProxyInstance(mbeanServerConn, name, UsersRepositoryManagementMBean.class, true);
-        } catch (MalformedObjectNameException e) {
-            throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e);
-        }
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#addUser(java.lang.String, java.lang.String)
-     */
-    public void addUser(String userName, String password) throws Exception {
-        usersRepositoryProxy.addUser(userName, password);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#removeUser(java.lang.String)
-     */
-    public void removeUser(String username) throws Exception {
-        usersRepositoryProxy.deleteUser(username);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#listUsers()
-     */
-    public String[] listUsers() throws Exception {
-        return usersRepositoryProxy.listAllUsers();
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#setPassword(java.lang.String, java.lang.String)
-     */
-    public void setPassword(String userName, String password) throws Exception {
-        usersRepositoryProxy.setPassword(userName, password);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#containsDomain(java.lang.String)
-     */
-    public boolean containsDomain(String domain) throws Exception {
-        return domainListProcxy.containsDomain(domain);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#addDomain(java.lang.String)
-     */
-    public void addDomain(String domain) throws Exception {
-        domainListProcxy.addDomain(domain);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#removeDomain(java.lang.String)
-     */
-    public void removeDomain(String domain) throws Exception {
-        domainListProcxy.removeDomain(domain);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#listDomains()
-     */
-    public String[] listDomains() throws Exception {
-        return domainListProcxy.getDomains();
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#listMappings()
-     */
-    public Map<String, Collection<String>> listMappings() throws Exception {
-        return virtualUserTableProxy.getAllMappings();
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#addAddressMapping(java.lang.String, java.lang.String, java.lang.String)
-     */
-    public void addAddressMapping(String user, String domain, String toAddress) throws Exception {
-        virtualUserTableProxy.addAddressMapping(user, domain, toAddress);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#removeAddressMapping(java.lang.String, java.lang.String, java.lang.String)
-     */
-    public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception {
-        virtualUserTableProxy.removeAddressMapping(user, domain, fromAddress);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#listUserDomainMappings(java.lang.String, java.lang.String)
-     */
-    public Collection<String> listUserDomainMappings(String user, String domain) throws Exception {
-        return virtualUserTableProxy.getUserDomainMappings(user, domain);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#addRegexMapping(java.lang.String, java.lang.String, java.lang.String)
-     */
-    public void addRegexMapping(String user, String domain, String regex) throws Exception {
-        virtualUserTableProxy.addRegexMapping(user, domain, regex);
-    }
-
-    /**
-     * @see org.apache.james.cli.probe.ServerProbe#removeRegexMapping(java.lang.String, java.lang.String, java.lang.String)
-     */
-    public void removeRegexMapping(String user, String domain, String regex) throws Exception {
-        virtualUserTableProxy.removeRegexMapping(user, domain, regex);
-    }
+	// TODO: Move this to somewhere else
+	private final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist";
+	private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable";
+	private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository";
+	private final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier";
+
+	private MBeanServerConnection mbeanServerConn;
+	private DomainListManagementMBean domainListProcxy;
+	private RecipientRewriteTableManagementMBean virtualUserTableProxy;
+	private UsersRepositoryManagementMBean usersRepositoryProxy;
+	private MailboxCopierManagementMBean mailboxCopierManagement;
+
+	private static final String fmtUrl = "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi";
+	private static final int defaultPort = 9999;
+	private String host;
+	private int port;
+
+	/**
+	 * Creates a ServerProbe using the specified JMX host and port.
+	 * 
+	 * @param host
+	 *            hostname or IP address of the JMX agent
+	 * @param port
+	 *            TCP port of the remote JMX agent
+	 * @throws IOException
+	 *             on connection failures
+	 */
+	public JmxServerProbe(String host, int port) throws IOException, InterruptedException {
+		this.host = host;
+		this.port = port;
+		connect();
+	}
+
+	/**
+	 * Creates a NodeProbe using the specified JMX host and default port.
+	 * 
+	 * @param host
+	 *            hostname or IP address of the JMX agent
+	 * @throws IOException
+	 *             on connection failures
+	 */
+	public JmxServerProbe(String host) throws IOException, InterruptedException {
+		this.host = host;
+		this.port = defaultPort;
+		connect();
+	}
+
+	/**
+	 * Create a connection to the JMX agent and setup the M[X]Bean proxies.
+	 * 
+	 * @throws IOException
+	 *             on connection failures
+	 */
+	private void connect() throws IOException {
+		JMXServiceURL jmxUrl = new JMXServiceURL(String.format(fmtUrl, host, port));
+		JMXConnector jmxc = JMXConnectorFactory.connect(jmxUrl, null);
+		mbeanServerConn = jmxc.getMBeanServerConnection();
+
+		try {
+			ObjectName name = new ObjectName(DOMAINLIST_OBJECT_NAME);
+			domainListProcxy = (DomainListManagementMBean) MBeanServerInvocationHandler.newProxyInstance(
+			        mbeanServerConn, name, DomainListManagementMBean.class, true);
+			name = new ObjectName(VIRTUALUSERTABLE_OBJECT_NAME);
+			virtualUserTableProxy = (RecipientRewriteTableManagementMBean) MBeanServerInvocationHandler
+			        .newProxyInstance(mbeanServerConn, name, RecipientRewriteTableManagementMBean.class, true);
+			name = new ObjectName(USERSREPOSITORY_OBJECT_NAME);
+			usersRepositoryProxy = (UsersRepositoryManagementMBean) MBeanServerInvocationHandler.newProxyInstance(
+			        mbeanServerConn, name, UsersRepositoryManagementMBean.class, true);
+			name = new ObjectName(MAILBOXCOPIER_OBJECT_NAME);
+			mailboxCopierManagement = (MailboxCopierManagementMBean) MBeanServerInvocationHandler.newProxyInstance(
+			        mbeanServerConn, name, MailboxCopierManagementMBean.class, true);
+		} catch (MalformedObjectNameException e) {
+			throw new RuntimeException("Invalid ObjectName? Please report this as a bug.", e);
+		}
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.james.cli.probe.ServerProbe#addUser(java.lang.String,
+	 * java.lang.String)
+	 */
+	@Override
+	public void addUser(String userName, String password) throws Exception {
+		usersRepositoryProxy.addUser(userName, password);
+	}
+
+	/*
+	 * @see org.apache.james.cli.probe.ServerProbe#removeUser(java.lang.String)
+	 */
+	@Override
+	public void removeUser(String username) throws Exception {
+		usersRepositoryProxy.deleteUser(username);
+	}
+
+	/*
+	 * @see org.apache.james.cli.probe.ServerProbe#listUsers()
+	 */
+	@Override
+	public String[] listUsers() throws Exception {
+		return usersRepositoryProxy.listAllUsers();
+	}
+
+	/*
+	 * @see org.apache.james.cli.probe.ServerProbe#setPassword(java.lang.String,
+	 * java.lang.String)
+	 */
+	@Override
+	public void setPassword(String userName, String password) throws Exception {
+		usersRepositoryProxy.setPassword(userName, password);
+	}
+
+	/*
+	 * @see
+	 * org.apache.james.cli.probe.ServerProbe#containsDomain(java.lang.String)
+	 */
+	@Override
+	public boolean containsDomain(String domain) throws Exception {
+		return domainListProcxy.containsDomain(domain);
+	}
+
+	/*
+	 * @see org.apache.james.cli.probe.ServerProbe#addDomain(java.lang.String)
+	 */
+	@Override
+	public void addDomain(String domain) throws Exception {
+		domainListProcxy.addDomain(domain);
+	}
+
+	/*
+	 * @see
+	 * org.apache.james.cli.probe.ServerProbe#removeDomain(java.lang.String)
+	 */
+	@Override
+	public void removeDomain(String domain) throws Exception {
+		domainListProcxy.removeDomain(domain);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.james.cli.probe.ServerProbe#listDomains()
+	 */
+	@Override
+	public String[] listDomains() throws Exception {
+		return domainListProcxy.getDomains();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.james.cli.probe.ServerProbe#listMappings()
+	 */
+	@Override
+	public Map<String, Collection<String>> listMappings() throws Exception {
+		return virtualUserTableProxy.getAllMappings();
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.james.cli.probe.ServerProbe#addAddressMapping(java.lang.String
+	 * , java.lang.String, java.lang.String)
+	 */
+	@Override
+	public void addAddressMapping(String user, String domain, String toAddress) throws Exception {
+		virtualUserTableProxy.addAddressMapping(user, domain, toAddress);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.james.cli.probe.ServerProbe#removeAddressMapping(java.lang
+	 * .String, java.lang.String, java.lang.String)
+	 */
+	@Override
+	public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception {
+		virtualUserTableProxy.removeAddressMapping(user, domain, fromAddress);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.james.cli.probe.ServerProbe#listUserDomainMappings(java.lang
+	 * .String, java.lang.String)
+	 */
+	@Override
+	public Collection<String> listUserDomainMappings(String user, String domain) throws Exception {
+		return virtualUserTableProxy.getUserDomainMappings(user, domain);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.james.cli.probe.ServerProbe#addRegexMapping(java.lang.String,
+	 * java.lang.String, java.lang.String)
+	 */
+	@Override
+	public void addRegexMapping(String user, String domain, String regex) throws Exception {
+		virtualUserTableProxy.addRegexMapping(user, domain, regex);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see
+	 * org.apache.james.cli.probe.ServerProbe#removeRegexMapping(java.lang.String
+	 * , java.lang.String, java.lang.String)
+	 */
+	@Override
+	public void removeRegexMapping(String user, String domain, String regex) throws Exception {
+		virtualUserTableProxy.removeRegexMapping(user, domain, regex);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.james.cli.probe.ServerProbe#copyMailbox(java.lang.String,
+	 * java.lang.String)
+	 */
+	@Override
+	public void copyMailbox(String srcBean, String dstBean) throws Exception {
+		mailboxCopierManagement.copy(srcBean, dstBean);
+	}
+
 }

Modified: james/server/trunk/cli/src/main/java/org/apache/james/cli/type/CmdType.java
URL: http://svn.apache.org/viewvc/james/server/trunk/cli/src/main/java/org/apache/james/cli/type/CmdType.java?rev=1400047&r1=1400046&r2=1400047&view=diff
==============================================================================
--- james/server/trunk/cli/src/main/java/org/apache/james/cli/type/CmdType.java (original)
+++ james/server/trunk/cli/src/main/java/org/apache/james/cli/type/CmdType.java Fri Oct 19 11:35:13 2012
@@ -22,74 +22,76 @@ package org.apache.james.cli.type;
  * Enumeration of valid command types.
  */
 public enum CmdType {
-    ADDUSER("adduser", 3), 
-    REMOVEUSER("removeuser", 2), 
-    LISTUSERS("listusers", 1), 
-    ADDDOMAIN("adddomain", 2), 
-    REMOVEDOMAIN("removedomain", 2), 
-    CONTAINSDOMAIN("containsdomain", 2), 
-    LISTDOMAINS("listdomains", 1),
-    LISTMAPPINGS("listmappings", 1),
-    LISTUSERDOMAINMAPPINGS("listuserdomainmappings", 3),
-    ADDADDRESSMAPPING("addaddressmapping", 4),
-    REMOVEADDRESSMAPPING("removeaddressmapping", 4),
-    ADDREGEXMAPPING("addregexmapping", 4),
-    REMOVEREGEXMAPPING("removeregexmapping", 4),
-    SETPASSWORD("setpassword", 3);
-    private String command;
-    private int arguments;
-
-    private CmdType(String command, int arguments) {
-        this.command = command;
-        this.arguments = arguments;
-    }
-
-    /**
-     * Validate that the number of arguments match the passed value.
-     * 
-     * @param arguments
-     *            The number of argument to compare.
-     * @return true if values match, false otherwise.
-     */
-    public boolean hasCorrectArguments(int arguments) {
-        if (this.arguments == arguments)
-            return true;
-
-        return false;
-    }
-
-    /**
-     * Return a CmdType enumeration that matches the passed command.
-     * 
-     * @param command
-     *            The command to use for lookup.
-     * @return the CmdType enumeration that matches the passed command, or null
-     *         if not found.
-     */
-    public static CmdType lookup(String command) {
-        if (command != null) {
-            for (CmdType cmd : values())
-                if (cmd.getCommand().equalsIgnoreCase(command))
-                    return cmd;
-        }
-        return null;
-    }
-    
-    /**
-     * Return the value of command.
-     * 
-     * @return the value of command.
-     */
-    public String getCommand() {
-        return this.command;
-    }
-
-    /**
-     * Return the value of arguments.
-     * 
-     * @return the value of arguments.
-     */
-    public int getArguments() {
-        return this.arguments;
-    }
+	ADDUSER("adduser", 3), //
+	REMOVEUSER("removeuser", 2), //
+	LISTUSERS("listusers", 1), //
+	ADDDOMAIN("adddomain", 2), //
+	REMOVEDOMAIN("removedomain", 2), //
+	CONTAINSDOMAIN("containsdomain", 2), //
+	LISTDOMAINS("listdomains", 1), //
+	LISTMAPPINGS("listmappings", 1), //
+	LISTUSERDOMAINMAPPINGS("listuserdomainmappings", 3), //
+	ADDADDRESSMAPPING("addaddressmapping", 4), //
+	REMOVEADDRESSMAPPING("removeaddressmapping", 4), //
+	ADDREGEXMAPPING("addregexmapping", 4), //
+	REMOVEREGEXMAPPING("removeregexmapping", 4), //
+	SETPASSWORD("setpassword", 3), //
+	COPYMAILBOX("copymailbox", 3) //
+	;
+	private String command;
+	private int arguments;
+
+	private CmdType(String command, int arguments) {
+		this.command = command;
+		this.arguments = arguments;
+	}
+
+	/**
+	 * Validate that the number of arguments match the passed value.
+	 * 
+	 * @param arguments
+	 *            The number of argument to compare.
+	 * @return true if values match, false otherwise.
+	 */
+	public boolean hasCorrectArguments(int arguments) {
+		if (this.arguments == arguments)
+			return true;
+
+		return false;
+	}
+
+	/**
+	 * Return a CmdType enumeration that matches the passed command.
+	 * 
+	 * @param command
+	 *            The command to use for lookup.
+	 * @return the CmdType enumeration that matches the passed command, or null
+	 *         if not found.
+	 */
+	public static CmdType lookup(String command) {
+		if (command != null) {
+			for (CmdType cmd : values())
+				if (cmd.getCommand().equalsIgnoreCase(command))
+					return cmd;
+		}
+		return null;
+	}
+
+	/**
+	 * Return the value of command.
+	 * 
+	 * @return the value of command.
+	 */
+	public String getCommand() {
+		return this.command;
+	}
+
+	/**
+	 * Return the value of arguments.
+	 * 
+	 * @return the value of arguments.
+	 */
+	public int getArguments() {
+		return this.arguments;
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message