[Cherbot-commit] SF.net SVN: cherbot:[142] trunk/src/prj
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-14 19:22:59
|
Revision: 142
http://cherbot.svn.sourceforge.net/cherbot/?rev=142&view=rev
Author: christianhujer
Date: 2008-12-14 19:22:53 +0000 (Sun, 14 Dec 2008)
Log Message:
-----------
Added SPI factory implementations.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/connection/package-info.java
Added Paths:
-----------
trunk/src/prj/META-INF/
trunk/src/prj/META-INF/net.sf.cherbot.connection.ConnectionFactory
trunk/src/prj/net/sf/cherbot/connection/AbstractConnectionFactory.java
trunk/src/prj/net/sf/cherbot/connection/ConsoleConnectionFactory.java
trunk/src/prj/net/sf/cherbot/connection/CrossfireConnectionFactory.java
trunk/src/prj/net/sf/cherbot/connection/DaimoninConnectionFactory.java
trunk/src/prj/net/sf/cherbot/connection/IRCConnectionFactory.java
Added: trunk/src/prj/META-INF/net.sf.cherbot.connection.ConnectionFactory
===================================================================
--- trunk/src/prj/META-INF/net.sf.cherbot.connection.ConnectionFactory (rev 0)
+++ trunk/src/prj/META-INF/net.sf.cherbot.connection.ConnectionFactory 2008-12-14 19:22:53 UTC (rev 142)
@@ -0,0 +1,4 @@
+net.sf.cherbot.ConsoleConncectionFactory
+net.sf.cherbot.CrossfireConncectionFactory
+net.sf.cherbot.DaimoninConncectionFactory
+net.sf.cherbot.IRCConncectionFactory
Property changes on: trunk/src/prj/META-INF/net.sf.cherbot.connection.ConnectionFactory
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/AbstractConnectionFactory.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/AbstractConnectionFactory.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/AbstractConnectionFactory.java 2008-12-14 19:22:53 UTC (rev 142)
@@ -0,0 +1,40 @@
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+
+/** Base class for {@link ConnectionFactory ConnectionFactories} which support just one Connection type that is easy to create.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public abstract class AbstractConnectionFactory implements ConnectionFactory {
+
+ /** The name of the supported connection type. */
+ private final String supportedConnectionTypeName;
+
+ /** Creates a ConnectionFactory.
+ * @param supportedConnectionTypeName Name of the supported connection type.
+ */
+ protected AbstractConnectionFactory(@NotNull final String supportedConnectionTypeName) {
+ this.supportedConnectionTypeName = supportedConnectionTypeName;
+ }
+
+ /** {@inheritDoc} */
+ public boolean supports(@NotNull final String connectionTypeName) {
+ return supportedConnectionTypeName.equals(connectionTypeName);
+ }
+
+ /** {@inheritDoc} */
+ public Connection createConnection(@NotNull final String connectionTypeName) throws UnknownConnectionTypeException {
+ if (!supports(connectionTypeName)) {
+ throw new UnknownConnectionTypeException(connectionTypeName);
+ }
+ return createConnectionImpl(connectionTypeName);
+ }
+
+ /** Creates a Connection.
+ * Similar to createConnection, but the check with {@link #supports(String)} is already performed.
+ * Most implementations thus will not need the <code>connectionTypeName</code> parameter.
+ * @param connectionTypeName Connection type name.
+ * @return New connection.
+ */
+ protected abstract Connection createConnectionImpl(@NotNull final String connectionTypeName);
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/AbstractConnectionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/ConsoleConnectionFactory.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/ConsoleConnectionFactory.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/ConsoleConnectionFactory.java 2008-12-14 19:22:53 UTC (rev 142)
@@ -0,0 +1,21 @@
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+
+/** ConnectionFactory for {@link ConsoleConnection}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class ConsoleConnectionFactory extends AbstractConnectionFactory {
+
+ /** Service Constructor.
+ * @see java.util.ServiceLoader
+ */
+ public ConsoleConnectionFactory() {
+ super("console");
+ }
+
+ /** {@inheritDoc} */
+ protected Connection createConnectionImpl(@NotNull final String connectionTypeName) {
+ return new ConsoleConnection();
+ }
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/ConsoleConnectionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/CrossfireConnectionFactory.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/CrossfireConnectionFactory.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/CrossfireConnectionFactory.java 2008-12-14 19:22:53 UTC (rev 142)
@@ -0,0 +1,21 @@
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+
+/** ConnectionFactory for {@link CrossfireConnection}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class CrossfireConnectionFactory extends AbstractConnectionFactory {
+
+ /** Service Constructor.
+ * @see java.util.ServiceLoader
+ */
+ protected CrossfireConnectionFactory() {
+ super("crossfire");
+ }
+
+ /** {@inheritDoc} */
+ protected Connection createConnectionImpl(@NotNull final String connectionTypeName) {
+ return new CrossfireConnection();
+ }
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/CrossfireConnectionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/DaimoninConnectionFactory.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/DaimoninConnectionFactory.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/DaimoninConnectionFactory.java 2008-12-14 19:22:53 UTC (rev 142)
@@ -0,0 +1,21 @@
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+
+/** ConnectionFactory for {@link DaimoninConnection}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class DaimoninConnectionFactory extends AbstractConnectionFactory {
+
+ /** Service Constructor.
+ * @see java.util.ServiceLoader
+ */
+ protected DaimoninConnectionFactory() {
+ super("daimonin");
+ }
+
+ /** {@inheritDoc} */
+ protected Connection createConnectionImpl(@NotNull final String connectionTypeName) {
+ return new DaimoninConnection();
+ }
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/DaimoninConnectionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/IRCConnectionFactory.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/IRCConnectionFactory.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/IRCConnectionFactory.java 2008-12-14 19:22:53 UTC (rev 142)
@@ -0,0 +1,21 @@
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+
+/** ConnectionFactory for {@link IRCConnection}.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class IRCConnectionFactory extends AbstractConnectionFactory {
+
+ /** Service Constructor.
+ * @see java.util.ServiceLoader
+ */
+ protected IRCConnectionFactory() {
+ super("irc");
+ }
+
+ /** {@inheritDoc} */
+ protected Connection createConnectionImpl(@NotNull final String connectionTypeName) {
+ return new IRCConnection();
+ }
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/IRCConnectionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Modified: trunk/src/prj/net/sf/cherbot/connection/package-info.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/package-info.java 2008-12-14 18:12:23 UTC (rev 141)
+++ trunk/src/prj/net/sf/cherbot/connection/package-info.java 2008-12-14 19:22:53 UTC (rev 142)
@@ -8,7 +8,10 @@
*
* The purpose of this package is to represent a layer that encapsulates and abstracts server and protocol specific aspects.
* That way CherBot itself does not need to know about IRC, Daimonin etc..
- * @todo provide a factory for creating connections and channels for CherBot.
+ *
+ * Connections are provided as {@link java.util.ServiceLoader service}.
+ * That way it is possible to "teach" CherBot new server types on the classpath without modifying the original code.
+ *
* @author <a href="mailto:ch...@ri...">Christian Hujer</a>
*/
package net.sf.cherbot.connection;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|