[Cherbot-commit] SF.net SVN: cherbot:[141] trunk/src/prj/net/sf/cherbot/connection
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2008-12-14 18:12:26
|
Revision: 141
http://cherbot.svn.sourceforge.net/cherbot/?rev=141&view=rev
Author: christianhujer
Date: 2008-12-14 18:12:23 +0000 (Sun, 14 Dec 2008)
Log Message:
-----------
Started creating an SPI for connections.
Modified Paths:
--------------
trunk/src/prj/net/sf/cherbot/connection/package-info.java
Added Paths:
-----------
trunk/src/prj/net/sf/cherbot/connection/ConnectionFactory.java
trunk/src/prj/net/sf/cherbot/connection/ConnectionProvider.java
trunk/src/prj/net/sf/cherbot/connection/UnknownConnectionTypeException.java
Added: trunk/src/prj/net/sf/cherbot/connection/ConnectionFactory.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/ConnectionFactory.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/ConnectionFactory.java 2008-12-14 18:12:23 UTC (rev 141)
@@ -0,0 +1,23 @@
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+
+/** Factory for connections.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public interface ConnectionFactory {
+
+ /** Returns whether or not this ConnectionFactory supports creating a connection for type <code>connectionTypeName</code>.
+ * @param connectionTypeName Name of the connection type.
+ * @return <code>true</code> if this Factory supports <code>connectionTypeName</code>, otherwise <code>false</code>.
+ */
+ boolean supports(@NotNull final String connectionTypeName);
+
+ /** Creates a connection for the specified connectionTypeName.
+ * @param connectionTypeName Name of the connection type.
+ * @return The connection that was created for <code>connectionTypeName</code>.
+ * @throws UnknownConnectionTypeException if this factory does not support <code>connectionTypeName</code>,
+ * which is exactly the case if {@link #supports(String)} returns false.
+ */
+ Connection createConnection(@NotNull final String connectionTypeName) throws UnknownConnectionTypeException;
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/ConnectionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/ConnectionProvider.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/ConnectionProvider.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/ConnectionProvider.java 2008-12-14 18:12:23 UTC (rev 141)
@@ -0,0 +1,24 @@
+package net.sf.cherbot.connection;
+
+import org.jetbrains.annotations.NotNull;
+import java.util.ServiceLoader;
+
+/** Provider for connections.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class ConnectionProvider {
+
+ private static final ServiceLoader<ConnectionFactory> connectionFactories = ServiceLoader.load(ConnectionFactory.class);
+
+ /** Gets a Connection instance for the specified connection type name.
+ * @param connectionTypeName Name of the connection type for which to get a Connection.
+ */
+ public static Connection getConnection(@NotNull final String connectionTypeName) throws UnknownConnectionTypeException {
+ for (final ConnectionFactory factory : connectionFactories) {
+ if (factory.supports(connectionTypeName)) {
+ return factory.createConnection(connectionTypeName);
+ }
+ }
+ throw new UnknownConnectionTypeException(connectionTypeName);
+ }
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/ConnectionProvider.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ LF
Added: trunk/src/prj/net/sf/cherbot/connection/UnknownConnectionTypeException.java
===================================================================
--- trunk/src/prj/net/sf/cherbot/connection/UnknownConnectionTypeException.java (rev 0)
+++ trunk/src/prj/net/sf/cherbot/connection/UnknownConnectionTypeException.java 2008-12-14 18:12:23 UTC (rev 141)
@@ -0,0 +1,15 @@
+package net.sf.cherbot.connection;
+
+/** Exception that's thrown when a Connection for an unknown connection type was reqeuested.
+ * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
+ */
+public class UnknownConnectionTypeException extends Throwable {
+
+ /** Creates an UnknownConnectionTypeException.
+ * @param connectionTypeName Name of the Connection type that was not known.
+ */
+ public UnknownConnectionTypeException(final String connectionTypeName) {
+ super(connectionTypeName);
+ }
+
+}
Property changes on: trunk/src/prj/net/sf/cherbot/connection/UnknownConnectionTypeException.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 17:04:15 UTC (rev 140)
+++ trunk/src/prj/net/sf/cherbot/connection/package-info.java 2008-12-14 18:12:23 UTC (rev 141)
@@ -8,6 +8,7 @@
*
* 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.
* @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.
|