瀏覽代碼

Tidy up now child implementations are handled in BaseParser

Change-Id: Ib43769c82b0a5ca1a0ac3bd6fd91e4105b0c2a87
Depends-On: I7178085b05baaf1923f0d41e936c863e4f79a0aa
Reviewed-on: http://gerrit.dmdirc.com/1991
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.7rc1
Chris Smith 13 年之前
父節點
當前提交
282ba93598

+ 15
- 3
src/com/dmdirc/parser/common/BaseParser.java 查看文件

@@ -29,7 +29,10 @@ import java.util.HashMap;
29 29
 import java.util.Map;
30 30
 
31 31
 /**
32
- * Implements common base functionality for parsers.
32
+ * Implements common base functionality for parsers.<p>
33
+ * Implementations of this class must be annotated with
34
+ * {@link ChildImplementations} to define the implementations to use for
35
+ * instances of {@link ClientInfo}, {@link ChannelInfo}, etc.
33 36
  */
34 37
 public abstract class BaseParser implements Parser {
35 38
 
@@ -55,10 +58,19 @@ public abstract class BaseParser implements Parser {
55 58
      * Creates a new base parser for the specified URI.
56 59
      *
57 60
      * @param uri The URI this parser will connect to.
58
-     * @param implementations A map of interface implementations for this parser
59 61
      */
60
-    public BaseParser(final URI uri, final Map<Class<?>, Class<?>> implementations) {
62
+    public BaseParser(final URI uri) {
61 63
         this.uri = uri;
64
+
65
+        final Map<Class<?>, Class<?>> implementations
66
+                = new HashMap<Class<?>, Class<?>>();
67
+
68
+        for (Class<?> child : this.getClass().getAnnotation(ChildImplementations.class).value()) {
69
+            for (Class<?> iface : child.getInterfaces()) {
70
+                implementations.put(iface, child);
71
+            }
72
+        }
73
+
62 74
         this.callbackManager = new CallbackManager(this, implementations);
63 75
     }
64 76
 

+ 2
- 4
src/com/dmdirc/parser/common/BaseSocketAwareParser.java 查看文件

@@ -26,7 +26,6 @@ import java.io.IOException;
26 26
 import java.net.InetAddress;
27 27
 import java.net.Socket;
28 28
 import java.net.URI;
29
-import java.util.Map;
30 29
 
31 30
 import javax.net.SocketFactory;
32 31
 
@@ -49,10 +48,9 @@ public abstract class BaseSocketAwareParser extends BaseParser {
49 48
      * Creates a new base parser for the specified URI.
50 49
      *
51 50
      * @param uri The URI this parser will connect to.
52
-     * @param implementations A map of interface implementations for this parser
53 51
      */
54
-    public BaseSocketAwareParser(final URI uri, final Map<Class<?>, Class<?>> implementations) {
55
-        super(uri, implementations);
52
+    public BaseSocketAwareParser(final URI uri) {
53
+        super(uri);
56 54
     }
57 55
 
58 56
     /** {@inheritDoc} */

+ 44
- 0
src/com/dmdirc/parser/common/ChildImplementations.java 查看文件

@@ -0,0 +1,44 @@
1
+/*
2
+ * Copyright (c) 2006-2011 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 com.dmdirc.parser.common;
24
+
25
+import java.lang.annotation.ElementType;
26
+import java.lang.annotation.Retention;
27
+import java.lang.annotation.RetentionPolicy;
28
+import java.lang.annotation.Target;
29
+
30
+/**
31
+ * Defines implementations of child classes for a parser.
32
+ */
33
+@Retention(RetentionPolicy.RUNTIME)
34
+@Target(ElementType.TYPE)
35
+public @interface ChildImplementations {
36
+
37
+    /**
38
+     * Gets the class names of implementations for children of a parser.
39
+     *
40
+     * @return An array of child classes
41
+     */
42
+    Class[] value();
43
+
44
+}

Loading…
取消
儲存