KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > connection > ConnectionFactory


1 /*****************************************************************************
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14
15  * The Original Software is the CVS Client Library.
16  * The Initial Developer of the Original Software is Gerrit Riessen.
17  * Portions created by Gerrit Riessen are Copyright (C) 2000.
18  * All Rights Reserved.
19
20  * Contributor(s): Gerrit Riessen.
21  *****************************************************************************/

22
23 package org.netbeans.lib.cvsclient.connection;
24
25 import org.netbeans.lib.cvsclient.CVSRoot;
26
27 /**
28  Simple class for managing the mapping from CVSROOT specifications to
29  Connection classes.
30  @author <a HREF="mailto:gerrit.riessen@wiwi.hu-berlin.de">Gerrit Riessen</a>, OAR Development AG
31  @author <a HREF="mailto:rami.ojares@elisa.fi">Rami Ojares</a>, Elisa Internet Oy
32  */

33 public class ConnectionFactory {
34     
35     /**
36      <b>Protected Constructor</b>
37      */

38     protected ConnectionFactory() {}
39     
40     /**
41      * Returns a Connection object to handle the specific CVSRoot
42      * specification. This returns null if not suitable connection
43      * was found.
44      *
45      * If the return value is an instance of the PServerConnection class,
46      * then the encoded password needs to be set if not defined in the CVSRoot.
47      * This is left up to the client to set.
48      */

49     public static Connection getConnection(String JavaDoc cvsRoot) throws IllegalArgumentException JavaDoc {
50         
51         CVSRoot root = CVSRoot.parse(cvsRoot);
52         return getConnection(root);
53         
54     }
55     
56     /**
57      * Returns a Connection object to handle the specific CVSRoot
58      * specification. This returns null if not suitable connection
59      * was found.
60      *
61      * If the return value is an instance of the PServerConnection class,
62      * then the encoded password needs to be set if not defined in the CVSRoot.
63      * This is left up to the client to set.
64      */

65     public static Connection getConnection(CVSRoot root) throws IllegalArgumentException JavaDoc {
66         
67         // LOCAL CONNECTIONS (no-method, local & fork)
68
if (root.isLocal()) {
69             LocalConnection con = new LocalConnection();
70             con.setRepository(root.getRepository());
71             return con;
72         }
73         
74         String JavaDoc method = root.getMethod();
75         // SSH2Connection (server, ext)
76
/* SSH2Connection is TBD
77         if (
78             method == null || CVSRoot.METHOD_SERVER == method || CVSRoot.METHOD_EXT == method
79         ) {
80             // NOTE: If you want to implement your own authenticator you have to construct SSH2Connection yourself
81             SSH2Connection con = new SSH2Connection(
82                 root,
83                 new ConsoleAuthenticator()
84             );
85             return con;
86         }
87          */

88         
89         // PServerConnection (pserver)
90
if (CVSRoot.METHOD_PSERVER == method) {
91             PServerConnection con = new PServerConnection(root);
92             return con;
93         }
94         
95         throw new IllegalArgumentException JavaDoc("Unrecognized CVS Root: " + root);
96         
97     }
98
99 }
100
Popular Tags