KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > spap > AssetManagementException


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.spap;
20
21 /**
22  * This exception represents an error for the asset management.
23  *
24  * @version $Id: AssetManagementException.java,v 1.3 2005/01/19 11:18:36 fabius Exp $
25  * @author Stefano Nichele
26  */

27 public class AssetManagementException extends Exception JavaDoc {
28
29
30     private Asset asset = null;
31     private String JavaDoc idAsset = null;
32     private Throwable JavaDoc cause = null;
33
34     // ------------------------------------------------------------ Constructors
35

36     /**
37      * Constructs an instance of <code>AssetManagementException</code> with the
38      * specified detail message.
39      *
40      * @param message the detail message.
41      */

42     public AssetManagementException(String JavaDoc message) {
43         super(message);
44     }
45
46     /**
47      * Constructs an instance of <code>AssetManagementException</code> with the
48      * specified detail message.
49      *
50      * and the cause.
51      * @param message the detail message.
52      * @param cause the cause of this error.
53      */

54     public AssetManagementException(String JavaDoc message, Throwable JavaDoc cause) {
55         this(message);
56         this.cause = cause;
57     }
58
59     /**
60      * Constructs an instance of <code>AssetManagementException</code> with the
61      * specified <code>Asset</code> and the specified message.
62      *
63      * @param asset the asset involved in this error.
64      * @param message the detail message.
65      */

66     public AssetManagementException(Asset asset, String JavaDoc message) {
67         super(message);
68         this.asset = asset;
69     }
70
71     /**
72      * Constructs an instance of <code>AssetManagementException</code> with
73      * the specified <code>Asset</code> and the specified message and the cause.
74      * @param asset the asset involved in this error.
75      * @param message the detail message.
76      * @param cause the cause of this error.
77      */

78     public AssetManagementException(Asset asset, String JavaDoc message, Throwable JavaDoc cause) {
79         this(asset,message);
80         this.cause = cause;
81     }
82
83     /**
84      * Constructs an instance of <code>AssetManagementException</code> with
85      * the specified idAsset and the specified message
86      * @param idAsset the idAsset involved in this error.
87      * @param message the detail message.
88      */

89     public AssetManagementException(String JavaDoc idAsset, String JavaDoc message) {
90         super(message);
91         this.idAsset = idAsset;
92     }
93
94     /**
95      * Constructs an instance of <code>AssetManagementException</code> with the specified
96      * idAsset and the specified message and the cause.
97      * @param idAsset the idAsset involved in this error.
98      * @param message the detail message.
99      * @param cause the cause of this error.
100      */

101     public AssetManagementException(String JavaDoc idAsset, String JavaDoc message, Throwable JavaDoc cause) {
102         this(idAsset,message);
103         this.cause = cause;
104     }
105
106     //---------------------------------------------------
107
// Overrides java.lang.Object method
108
//---------------------------------------------------
109

110     public String JavaDoc toString() {
111         StringBuffer JavaDoc message = new StringBuffer JavaDoc();
112         if (asset!=null) {
113             message.append(super.toString());
114             message.append(" (id: ");
115             message.append(asset.getId());
116             message.append(", manufacturer: ");
117             message.append(asset.getManufacturer());
118             message.append(", name: ");
119             message.append(asset.getName());
120             message.append(")");
121         } else if (idAsset != null) {
122             message.append(super.toString());
123             message.append(" (id: ");
124             message.append(idAsset);
125             message.append(")");
126         } else {
127             message.append(super.toString());
128         }
129
130         return message.toString();
131     }
132
133     /**
134      * Prints the exception and its cause (if any) stack trace
135      */

136     public void printStackTrace() {
137         super.printStackTrace();
138         if (cause != null) {
139             System.err.println("Caused by:");
140             cause.printStackTrace();
141         }
142     }
143
144 }
Popular Tags