001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.j2ssh.transport;
027:
028: import com.sshtools.j2ssh.util.State;
029:
030: import java.io.IOException;
031:
032: /**
033: *
034: *
035: * @author $author$
036: * @version $Revision: 1.24 $
037: */
038: public class TransportProtocolState extends State {
039: /** */
040: public final static int UNINITIALIZED = 1;
041:
042: /** */
043: public final static int NEGOTIATING_PROTOCOL = 2;
044:
045: /** */
046: public final static int PERFORMING_KEYEXCHANGE = 3;
047:
048: /** */
049: public final static int CONNECTED = 4;
050:
051: /** */
052: public final static int DISCONNECTED = 5;
053:
054: /** */
055: public IOException lastError;
056:
057: /** */
058: public String reason = "";
059:
060: /**
061: * Creates a new TransportProtocolState object.
062: */
063: public TransportProtocolState() {
064: super (UNINITIALIZED);
065: }
066:
067: /**
068: *
069: *
070: * @param lastError
071: */
072: protected void setLastError(IOException lastError) {
073: this .lastError = lastError;
074: }
075:
076: /**
077: *
078: *
079: * @return
080: */
081: public boolean hasError() {
082: return lastError != null;
083: }
084:
085: /**
086: *
087: *
088: * @return
089: */
090: public IOException getLastError() {
091: return lastError;
092: }
093:
094: /**
095: *
096: *
097: * @param reason
098: */
099: protected void setDisconnectReason(String reason) {
100: this .reason = reason;
101: }
102:
103: /**
104: *
105: *
106: * @return
107: */
108: public String getDisconnectReason() {
109: return reason;
110: }
111:
112: /**
113: *
114: *
115: * @param state
116: *
117: * @return
118: */
119: public boolean isValidState(int state) {
120: return ((state == UNINITIALIZED)
121: || (state == NEGOTIATING_PROTOCOL)
122: || (state == PERFORMING_KEYEXCHANGE)
123: || (state == CONNECTED) || (state == DISCONNECTED));
124: }
125: }
|