소스 검색

Major changes to the command parser framework

git-svn-id: http://svn.dmdirc.com/trunk@137 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith 17 년 전
부모
커밋
9781dc12e8

+ 7
- 9
src/uk/org/ownage/dmdirc/commandparser/ChannelCommand.java 파일 보기

@@ -22,21 +22,19 @@
22 22
 
23 23
 package uk.org.ownage.dmdirc.commandparser;
24 24
 
25
-import uk.org.ownage.dmdirc.parser.ChannelInfo;
25
+import uk.org.ownage.dmdirc.Channel;
26
+import uk.org.ownage.dmdirc.Server;
26 27
 
27 28
 /**
28 29
  *
29 30
  * @author chris
30 31
  */
31 32
 public abstract class ChannelCommand extends Command {
32
-    
33
-    protected ChannelInfo channel;
34
-    
33
+       
35 34
     /** Creates a new instance of ChannelCommand */
36
-    public ChannelCommand(ChannelInfo channel) {
35
+    public ChannelCommand() {
37 36
         super();
38
-        
39
-        this.channel = channel;
40 37
     }
41
-        
42
-}
38
+    
39
+    public abstract void Execute(Server server, Channel channel, String... args);    
40
+}

+ 27
- 3
src/uk/org/ownage/dmdirc/commandparser/ChannelCommandParser.java 파일 보기

@@ -22,16 +22,40 @@
22 22
 
23 23
 package uk.org.ownage.dmdirc.commandparser;
24 24
 
25
+import uk.org.ownage.dmdirc.Channel;
26
+import uk.org.ownage.dmdirc.Server;
27
+
25 28
 /**
26 29
  *
27 30
  * @author chris
28 31
  */
29
-public class ChannelCommandParser extends ServerCommandParser {
32
+public class ChannelCommandParser extends CommandParser {
33
+    
34
+    private Server server;
35
+    private Channel channel;
30 36
     
31 37
     /** Creates a new instance of ChannelCommandParser */
32
-    public ChannelCommandParser() {
38
+    public ChannelCommandParser(Server server, Channel channel) {
39
+        super();
40
+        
41
+        this.server = server;
42
+        this.channel = channel;
33 43
     }
34 44
 
35
-    
45
+    protected void LoadCommands() {
46
+        throw new UnsupportedOperationException("Not implemented yet");
47
+    }
48
+
49
+    protected void executeCommand(Command command, String... args) {
50
+        throw new UnsupportedOperationException("Not implemented yet");
51
+    }
52
+
53
+    protected void handleInvalidCommand(String command, String... args) {
54
+        throw new UnsupportedOperationException("Not implemented yet");
55
+    }
56
+
57
+    protected void handleNonCommand(String line) {
58
+        throw new UnsupportedOperationException("Not implemented yet");
59
+    }
36 60
     
37 61
 }

+ 18
- 2
src/uk/org/ownage/dmdirc/commandparser/Command.java 파일 보기

@@ -22,17 +22,23 @@
22 22
 
23 23
 package uk.org.ownage.dmdirc.commandparser;
24 24
 
25
+import uk.org.ownage.dmdirc.Server;
26
+
25 27
 /**
26 28
  *
27 29
  * @author chris
28 30
  */
29 31
 public abstract class Command {
30 32
     
33
+    protected static Command instance;
34
+    
31 35
     protected String name;
32 36
     protected int arity = 0;
33 37
     protected boolean polyadic;
38
+    protected boolean show = true;
39
+    protected String arguments = "<unknown>";
40
+    protected String description = "unknown";
34 41
     
35
-    /** Creates a new instance of Command */
36 42
     public Command() {
37 43
     }
38 44
     
@@ -44,6 +50,16 @@ public abstract class Command {
44 50
         }
45 51
     }
46 52
     
47
-    public abstract void Execute(String... args);
53
+    public boolean showInHelp() {
54
+        return show;
55
+    }
56
+    
57
+    public String getHelp() {
58
+        return name+" "+arguments+" - "+description;
59
+    }
60
+    
61
+    public static Command getInstance() {
62
+        return instance;
63
+    }
48 64
     
49 65
 }

+ 39
- 0
src/uk/org/ownage/dmdirc/commandparser/CommandManager.java 파일 보기

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.commandparser;
24
+
25
+/**
26
+ *
27
+ * @author chris
28
+ */
29
+public class CommandManager {
30
+           
31
+    public static void loadChannelCommands(CommandParser parser) {
32
+        throw new UnsupportedOperationException("Not implemented yet");        
33
+    }
34
+    
35
+    public static void loadServerCommands(CommandParser parser) {
36
+        throw new UnsupportedOperationException("Not implemented yet");        
37
+    }    
38
+    
39
+}

+ 24
- 13
src/uk/org/ownage/dmdirc/commandparser/CommandParser.java 파일 보기

@@ -23,6 +23,7 @@
23 23
 package uk.org.ownage.dmdirc.commandparser;
24 24
 
25 25
 import java.util.Hashtable;
26
+import uk.org.ownage.dmdirc.Config;
26 27
 
27 28
 /**
28 29
  *
@@ -46,23 +47,33 @@ abstract public class CommandParser {
46 47
     
47 48
     /** Parses the specified string as a command */
48 49
     public void parseCommand(String line) {
49
-        String[] args = line.split(" ");
50
-        
51
-        assert(args.length > 0);
52
-        
53
-        String command = args[0];
54
-        String signature = command+"/"+(args.length-1);
55
-        
56
-        // Check the specific signature first, so that polyadic commands can
57
-        // have error handlers if there are too few arguments (e.g., msg/0 and
58
-        // msg/1 would return errors, so msg only gets called with 2+ args).
59
-        if (commands.containsKey(signature)) {
50
+        if (line.charAt(0) == Config.getOption("general","commandchar").charAt(0)) {
51
+            String[] args = line.split(" ");
60 52
             
61
-        } else if (commands.containsKey(command)) {
53
+            assert(args.length > 0);
62 54
             
63
-        } else {
55
+            String command = args[0];
56
+            
57
+            String signature = command+"/"+(args.length-1);
64 58
             
59
+            // Check the specific signature first, so that polyadic commands can
60
+            // have error handlers if there are too few arguments (e.g., msg/0 and
61
+            // msg/1 would return errors, so msg only gets called with 2+ args).
62
+            if (commands.containsKey(signature)) {
63
+                executeCommand(commands.get(signature), args);
64
+            } else if (commands.containsKey(command)) {
65
+                executeCommand(commands.get(command), args);
66
+            } else {
67
+                handleInvalidCommand(command, args);
68
+            }
69
+        } else {
70
+            handleNonCommand(line);
65 71
         }
66 72
     }
67 73
     
74
+    abstract protected void executeCommand(Command command, String... args);
75
+    
76
+    abstract protected void handleInvalidCommand(String command, String... args);
77
+
78
+    abstract protected void handleNonCommand(String line);
68 79
 }

+ 40
- 0
src/uk/org/ownage/dmdirc/commandparser/ServerCommand.java 파일 보기

@@ -0,0 +1,40 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.commandparser;
24
+
25
+import uk.org.ownage.dmdirc.Channel;
26
+import uk.org.ownage.dmdirc.Server;
27
+
28
+/**
29
+ *
30
+ * @author chris
31
+ */
32
+public abstract class ServerCommand extends Command {
33
+       
34
+    /** Creates a new instance of ChannelCommand */
35
+    public ServerCommand() {
36
+        super();
37
+    }
38
+    
39
+    public abstract void Execute(Server server, String... args);
40
+}

+ 21
- 1
src/uk/org/ownage/dmdirc/commandparser/ServerCommandParser.java 파일 보기

@@ -22,17 +22,37 @@
22 22
 
23 23
 package uk.org.ownage.dmdirc.commandparser;
24 24
 
25
+import uk.org.ownage.dmdirc.Server;
26
+
25 27
 /**
26 28
  *
27 29
  * @author chris
28 30
  */
29 31
 public class ServerCommandParser extends CommandParser {
30 32
     
33
+    private Server server;
34
+    
31 35
     /** Creates a new instance of ServerCommandParser */
32
-    public ServerCommandParser() {
36
+    public ServerCommandParser(Server server) {
37
+        super();
38
+        
39
+        this.server = server;
33 40
     }
34 41
 
35 42
     protected void LoadCommands() {
43
+        throw new UnsupportedOperationException("Not implemented yet");
44
+    }
45
+
46
+    protected void executeCommand(Command command, String... args) {
47
+        throw new UnsupportedOperationException("Not implemented yet");
48
+    }
49
+
50
+    protected void handleInvalidCommand(String command, String... args) {
51
+        throw new UnsupportedOperationException("Not implemented yet");
52
+    }
53
+
54
+    protected void handleNonCommand(String line) {
55
+        throw new UnsupportedOperationException("Not implemented yet");
36 56
     }
37 57
     
38 58
 }

+ 51
- 0
src/uk/org/ownage/dmdirc/commandparser/commands/Test.java 파일 보기

@@ -0,0 +1,51 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.commandparser.commands;
24
+
25
+import uk.org.ownage.dmdirc.Server;
26
+import uk.org.ownage.dmdirc.commandparser.Command;
27
+import uk.org.ownage.dmdirc.commandparser.ServerCommand;
28
+
29
+/**
30
+ *
31
+ * @author chris
32
+ */
33
+public class Test extends ServerCommand {
34
+    
35
+    protected static Command instance = new Test();
36
+    
37
+    /** Creates a new instance of Test */
38
+    public Test() {
39
+        description = "a test command";
40
+        arguments = "";
41
+        polyadic = false;
42
+        arity = 0;            
43
+        name = "test";        
44
+        show = true;
45
+    }
46
+
47
+    public void Execute(Server server, String... args) {
48
+        throw new UnsupportedOperationException("Not implemented yet");
49
+    }
50
+    
51
+}

Loading…
취소
저장