View Javadoc

1   /*
2    * Copyright (c) 2003 Peter Antman, Teknik i Media  <peter.antman@tim.se>
3    *
4    * $Id: FTPException.java,v 1.1.1.1 2004/05/19 12:26:42 pra Exp $
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version
10   * 
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.backsource.adaptor.ftp;
21  import org.backsource.utils.lang.NestableException;
22  /***
23   * Generic FTPException.
24   *
25   * @author <a href="mailto:pra@tim.se">Peter Antman</a>
26   * @version $Revision: 1.1.1.1 $
27   */
28  
29  public class FTPException extends NestableException {
30     private String reason;
31     private int reasonCode = -1;
32     public FTPException (){
33        
34     }
35     public FTPException(Exception ex) {
36  	super(ex);
37     }
38     
39     public FTPException(String msg) {
40        super(msg);
41     }
42     
43     public FTPException(String msg, Exception ex) {
44        super(msg,ex);
45     }
46     
47     /***
48      * Get the reason the FTP server gave.
49      */
50     public String getReason() {
51        return reason;
52     }
53     
54     public void setReason(String reason) {
55        this.reason = reason;
56     }
57     
58     /***
59      * Get the reasonCode the FTP server gave.
60      */
61     public int getReasonCode() {
62        return reasonCode;
63     }
64     
65     public void setReasonCode(int reasonCode) {
66        this.reasonCode = reasonCode;
67     }
68  
69     public String getMessage() {
70        return super.getMessage() +getReasonString();
71     }
72     public String toString() {
73        return super.toString() +getReasonString();
74     }
75  
76     protected String getReasonString() {
77        StringBuffer buf = new StringBuffer();
78        if ( reason != null || reasonCode != -1) {
79           buf.append(" (");
80        } // end of if ()
81        
82        if ( reason != null) {
83           buf.append("FTP Reason: ").append(reason); 
84        } // end of if ()
85        if ( reasonCode != -1) {
86           buf.append(" FTP ReasonCode: ").append(reasonCode); 
87        } // end of if ()
88        if ( reason != null || reasonCode != -1) {
89           buf.append(")");
90        } // end of if ()
91        return buf.toString();
92     }
93  }// FTPException