|
From: <cr...@us...> - 2008-05-12 11:23:35
|
Revision: 4088
http://jnode.svn.sourceforge.net/jnode/?rev=4088&view=rev
Author: crawley
Date: 2008-05-12 04:23:29 -0700 (Mon, 12 May 2008)
Log Message:
-----------
Converted ResolverCommand.
Modified Paths:
--------------
trunk/net/descriptors/org.jnode.net.command.xml
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
Modified: trunk/net/descriptors/org.jnode.net.command.xml
===================================================================
--- trunk/net/descriptors/org.jnode.net.command.xml 2008-05-12 11:21:57 UTC (rev 4087)
+++ trunk/net/descriptors/org.jnode.net.command.xml 2008-05-12 11:23:29 UTC (rev 4088)
@@ -66,6 +66,17 @@
<syntax alias="ping">
<argument argLabel="host" description="Ping a remote host"/>
</syntax>
+ <syntax alias="resolver">
+ <empty description="List the DNS servers used by the resolver's list"/>
+ <sequence description="Add a DNS server to the resolver">
+ <option argLabel="add" shortName="a" longName="add"/>
+ <argument argLabel="server"/>
+ </sequence>
+ <sequence description="Remove a DNS server from the resolver's list">
+ <option argLabel="del" shortName="d" longName="del"/>
+ <argument argLabel="server"/>
+ </sequence>
+ </syntax>
<syntax alias="tcpinout">
<argument argLabel="localPort" description="Run tcpinout in server mode"/>
<sequence description="Run tcpinout in client mode">
Modified: trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
===================================================================
--- trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2008-05-12 11:21:57 UTC (rev 4087)
+++ trunk/net/src/net/org/jnode/net/command/ResolverCommand.java 2008-05-12 11:23:29 UTC (rev 4088)
@@ -25,16 +25,14 @@
import java.io.PrintStream;
import java.util.Collection;
-import org.jnode.net.help.argument.HostArgument;
+import org.jnode.driver.net.NetworkException;
import org.jnode.net.ipv4.IPv4Address;
import org.jnode.net.ipv4.util.ResolverImpl;
+import org.jnode.net.syntax.IPv4AddressArgument;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.FlagArgument;
/**
* This command class manages the DNS resolver.
@@ -43,48 +41,43 @@
*/
public class ResolverCommand extends AbstractCommand
{
- private static final String FUNC_ADD = "add";
- private static final String FUNC_DEL = "del";
+ // FIXME this should not be restricted to IPv4 addresses.
+ private final FlagArgument FLAG_ADD =
+ new FlagArgument("add", Argument.OPTIONAL, "if set, add a DNS server");
+ private final FlagArgument FLAG_DEL =
+ new FlagArgument("del", Argument.OPTIONAL, "if set, remove a DNS server");
- private static final OptionArgument ARG_FUNCTION =
- new OptionArgument(
- "function",
- "the function to perform",
- new OptionArgument.Option[] {
- new OptionArgument.Option(FUNC_ADD, "add a dns server"),
- new OptionArgument.Option(FUNC_DEL, "delete a dns server")});
+ private final IPv4AddressArgument ARG_DNS_SERVER =
+ new IPv4AddressArgument("server", Argument.OPTIONAL,
+ "the DNS server's hostname or IP address");
- private static final HostArgument ARG_DNSSERVER =
- new HostArgument("dns server", "the dns server IP address");
+ public ResolverCommand() {
+ super("Manage JNode's DNS resolver");
+ registerArguments(FLAG_ADD, FLAG_DEL, ARG_DNS_SERVER);
+ }
- public static Help.Info HELP_INFO =
- new Help.Info(
- "resolver",
- new Syntax[] {
- new Syntax("Print the dns servers"),
- new Syntax(
- "Add or remove a dns server",
- new Parameter[] {
- new Parameter(ARG_FUNCTION, Parameter.MANDATORY),
- new Parameter(ARG_DNSSERVER, Parameter.MANDATORY)
- })
- });
-
-
public static void main(String[] args) throws Exception {
new ResolverCommand().execute(args);
}
-
public void execute(CommandLine commandLine, InputStream in,
- PrintStream out, PrintStream err) throws Exception {
- ParsedArguments cmdLine = HELP_INFO.parse(commandLine);
-
- if (cmdLine.size() == 0) {
+ PrintStream out, PrintStream err)
+ throws NetworkException {
+ IPv4Address server = ARG_DNS_SERVER.getValue();
+ if (FLAG_ADD.isSet()) {
+ // Add a DNS server
+ ResolverImpl.addDnsServer(server);
+ }
+ else if (FLAG_DEL.isSet()) {
+ // Remove a DNS server
+ ResolverImpl.removeDnsServer(server);
+ }
+ else {
+ // List the DNS servers that the resolver uses
Collection<String> resolvers = ResolverImpl.getDnsServers();
- if (resolvers == null) {
+ if (resolvers.size() == 0) {
out.println("No DNS servers found.");
}
else {
@@ -94,18 +87,5 @@
}
}
}
- else {
- String func = ARG_FUNCTION.getValue(cmdLine);
- IPv4Address server = ARG_DNSSERVER.getAddress(cmdLine);
-
- if (FUNC_ADD.equals(func)) {
- ResolverImpl.addDnsServer(server);
- }
- else if (FUNC_DEL.equals(func)) {
- ResolverImpl.removeDnsServer(server);
- }
- }
-
- out.println();
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|