KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > dcerpc > DcerpcException


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

19
20 package jcifs.dcerpc;
21
22 import java.io.*;
23
24 import jcifs.util.Hexdump;
25 import jcifs.smb.WinError;
26
27 public class DcerpcException extends IOException implements DcerpcError, WinError {
28
29     static String JavaDoc getMessageByDcerpcError(int errcode) {
30         int min = 0;
31         int max = DCERPC_FAULT_CODES.length;
32
33         while (max >= min) {
34             int mid = (min + max) / 2;
35
36             if (errcode > DCERPC_FAULT_CODES[mid]) {
37                 min = mid + 1;
38             } else if (errcode < DCERPC_FAULT_CODES[mid]) {
39                 max = mid - 1;
40             } else {
41                 return DCERPC_FAULT_MESSAGES[mid];
42             }
43         }
44
45         return "0x" + Hexdump.toHexString(errcode, 8);
46     }
47
48     private int error;
49     private Throwable JavaDoc rootCause;
50
51     DcerpcException(String JavaDoc msg) {
52         super(msg);
53     }
54     DcerpcException(int error) {
55         super(getMessageByDcerpcError(error));
56         this.error = error;
57     }
58     DcerpcException(String JavaDoc msg, Throwable JavaDoc rootCause) {
59         super(msg);
60         this.rootCause = rootCause;
61     }
62     public int getErrorCode() {
63         return error;
64     }
65     public Throwable JavaDoc getRootCause() {
66         return rootCause;
67     }
68     public String JavaDoc toString() {
69         if (rootCause != null) {
70             StringWriter sw = new StringWriter();
71             PrintWriter pw = new PrintWriter(sw);
72             rootCause.printStackTrace(pw);
73             return super.toString() + "\n" + sw;
74         }
75         return super.toString();
76     }
77 }
78
Popular Tags