KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ssh > SSHServerConnection


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ssh;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.io.OutputStream JavaDoc;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
19 import org.eclipse.team.internal.ccvs.core.IServerConnection;
20 import org.eclipse.team.internal.ccvs.core.connection.CVSAuthenticationException;
21
22 public class SSHServerConnection implements IServerConnection {
23     
24     // command to start remote cvs in server mode
25
private static final String JavaDoc INVOKE_SVR_CMD = "cvs server"; //$NON-NLS-1$
26

27     private static final int DEFAULT_PORT = 22;
28     
29     // cvs format for the repository (e.g. :extssh:user@host:/home/cvs/repo)
30
private ICVSRepositoryLocation location;
31     
32     // password for user specified in repository location string
33
private String JavaDoc password;
34     
35     // incoming from remote host
36
InputStream JavaDoc inputStream;
37     
38     // outgoing to remote host
39
OutputStream JavaDoc outputStream;
40     
41     // ssh client
42
Client client;
43
44     public SSHServerConnection(ICVSRepositoryLocation location, String JavaDoc password) {
45         if (password == null) {
46             password = ""; //$NON-NLS-1$
47
}
48         this.location = location;
49         this.password = password;
50     }
51
52     public void close() throws IOException JavaDoc {
53         client.disconnect();
54     }
55     /**
56      * Returns the <code>InputStream</code> used to read data from the
57      * server.
58      */

59     public InputStream JavaDoc getInputStream() {
60         return inputStream;
61     }
62     /**
63      * Returns the <code>OutputStream</code> used to send data to the
64      * server.
65      */

66     public OutputStream JavaDoc getOutputStream() {
67         return outputStream;
68     }
69
70     /**
71      * Opens the connection and invokes cvs in server mode.
72      *
73      * @see Connection.open()
74      */

75     public void open(IProgressMonitor monitor) throws IOException JavaDoc, CVSAuthenticationException {
76         monitor.subTask(CVSSSHMessages.SSHServerConnection_authenticating);
77         monitor.worked(1);
78         String JavaDoc hostname = location.getHost();
79         String JavaDoc username = location.getUsername();
80         int port = location.getPort();
81         if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT)
82             port = DEFAULT_PORT;
83         // create the connection using host, username, and password
84
client = new Client(hostname, port, username, password, INVOKE_SVR_CMD, location.getTimeout());
85         client.connect(monitor);
86         inputStream = client.getInputStream();
87         outputStream = client.getOutputStream();
88     }
89 }
90
Popular Tags