KickJava   Java API By Example, From Geeks To Geeks.

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


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 NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.cvsclient.connection;
21
22 import org.netbeans.lib.cvsclient.command.CommandAbortedException;
23 import org.netbeans.lib.cvsclient.util.LoggedDataInputStream;
24 import org.netbeans.lib.cvsclient.util.LoggedDataOutputStream;
25
26 import java.io.IOException JavaDoc;
27 import java.io.BufferedInputStream JavaDoc;
28 import java.io.BufferedOutputStream JavaDoc;
29
30 /**
31  * Provides support for the :ext: connection method.
32  *
33  * @author Maros Sandor
34  */

35 public class ExtConnection extends AbstractConnection {
36
37     private final String JavaDoc command;
38
39     private Process JavaDoc process;
40
41     /**
42      * Creates new EXT connection method support class. Given command will be used for getting I/O
43      * streams to CVS server.
44      *
45      * @param command command to execute
46      */

47     public ExtConnection(String JavaDoc command) {
48         this.command = command;
49     }
50
51     public void open() throws AuthenticationException, CommandAbortedException {
52         try {
53             process = Runtime.getRuntime().exec(command);
54             setInputStream(new LoggedDataInputStream(new BufferedInputStream JavaDoc(process.getInputStream())));
55             setOutputStream(new LoggedDataOutputStream(new BufferedOutputStream JavaDoc(process.getOutputStream())));
56         } catch (IOException JavaDoc e) {
57             throw new AuthenticationException(e, "Failed to execute: " + command);
58         }
59     }
60
61     public void verify() throws AuthenticationException {
62         try {
63             open();
64             verifyProtocol();
65             process.destroy();
66         } catch (Exception JavaDoc e) {
67             throw new AuthenticationException(e, "Failed to execute: " + command);
68         }
69     }
70
71     public void close() throws IOException JavaDoc {
72         if (isOpen()) {
73             process.destroy();
74         }
75     }
76
77     public boolean isOpen() {
78         if (process == null) return false;
79         try {
80             process.exitValue();
81             return false;
82         } catch (IllegalThreadStateException JavaDoc e) {
83             return true;
84         }
85     }
86
87     public int getPort() {
88         return 0;
89     }
90
91     public void modifyInputStream(ConnectionModifier modifier) throws IOException JavaDoc {
92         modifier.modifyInputStream(getInputStream());
93     }
94
95     public void modifyOutputStream(ConnectionModifier modifier) throws IOException JavaDoc {
96         modifier.modifyOutputStream(getOutputStream());
97     }
98 }
99
Popular Tags