Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ReplyException |
|
| 1.0;1 |
1 | /* | |
2 | * #%L | |
3 | * ReplyException.java - mongodb-async-driver - Allanbank Consulting, Inc. | |
4 | * %% | |
5 | * Copyright (C) 2011 - 2014 Allanbank Consulting, Inc. | |
6 | * %% | |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
8 | * you may not use this file except in compliance with the License. | |
9 | * You may obtain a copy of the License at | |
10 | * | |
11 | * http://www.apache.org/licenses/LICENSE-2.0 | |
12 | * | |
13 | * Unless required by applicable law or agreed to in writing, software | |
14 | * distributed under the License is distributed on an "AS IS" BASIS, | |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
16 | * See the License for the specific language governing permissions and | |
17 | * limitations under the License. | |
18 | * #L% | |
19 | */ | |
20 | package com.allanbank.mongodb.error; | |
21 | ||
22 | import com.allanbank.mongodb.MongoDbException; | |
23 | import com.allanbank.mongodb.client.Message; | |
24 | import com.allanbank.mongodb.client.message.Reply; | |
25 | ||
26 | /** | |
27 | * Base class exception for all reply errors. | |
28 | * | |
29 | * @api.yes This class is part of the driver's API. Public and protected members | |
30 | * will be deprecated for at least 1 non-bugfix release (version | |
31 | * numbers are <major>.<minor>.<bugfix>) before being | |
32 | * removed or modified. | |
33 | * @copyright 2011-2013, Allanbank Consulting, Inc., All Rights Reserved | |
34 | */ | |
35 | public class ReplyException extends MongoDbException { | |
36 | ||
37 | /** The serialization version of the class. */ | |
38 | private static final long serialVersionUID = -2597835377434607342L; | |
39 | ||
40 | /** The value of the "errNo" field in the reply document. */ | |
41 | private final int myErrorNumber; | |
42 | ||
43 | /** The value of the "ok" field in the reply document. */ | |
44 | private final int myOkValue; | |
45 | ||
46 | /** The reply. */ | |
47 | private transient final Reply myReply; | |
48 | ||
49 | /** The original request message, if known. */ | |
50 | private transient final Message myRequest; | |
51 | ||
52 | /** | |
53 | * Create a new ReplyException. | |
54 | * | |
55 | * @param okValue | |
56 | * The value of the "ok" field in the reply document. | |
57 | * @param errorNumber | |
58 | * The value of the "errNo" field in the reply document. | |
59 | * @param errorMessage | |
60 | * The value of the 'errormsg" field in the reply document. | |
61 | * @param request | |
62 | * The request that caused the error. | |
63 | * @param reply | |
64 | * The reply with the error. | |
65 | */ | |
66 | public ReplyException(final int okValue, final int errorNumber, | |
67 | final String errorMessage, final Message request, final Reply reply) { | |
68 | 46 | super(errorMessage); |
69 | 46 | myOkValue = okValue; |
70 | 46 | myErrorNumber = errorNumber; |
71 | 46 | myRequest = request; |
72 | 46 | myReply = reply; |
73 | 46 | } |
74 | ||
75 | /** | |
76 | * Create a new ReplyException. | |
77 | * | |
78 | * @param okValue | |
79 | * The value of the "ok" field in the reply document. | |
80 | * @param errorNumber | |
81 | * The value of the "errNo" field in the reply document. | |
82 | * @param errorMessage | |
83 | * The value of the 'errmsg" field in the reply document. | |
84 | * @param reply | |
85 | * The reply with the error. | |
86 | */ | |
87 | public ReplyException(final int okValue, final int errorNumber, | |
88 | final String errorMessage, final Reply reply) { | |
89 | 1 | this(okValue, errorNumber, errorMessage, null, reply); |
90 | 1 | } |
91 | ||
92 | /** | |
93 | * Create a new ReplyException. | |
94 | * | |
95 | * @param reply | |
96 | * The reply that raised the exception. | |
97 | */ | |
98 | public ReplyException(final Reply reply) { | |
99 | 1 | super(); |
100 | ||
101 | 1 | myOkValue = -1; |
102 | 1 | myErrorNumber = -1; |
103 | 1 | myRequest = null; |
104 | 1 | myReply = reply; |
105 | 1 | } |
106 | ||
107 | /** | |
108 | * Create a new ReplyException. | |
109 | * | |
110 | * @param reply | |
111 | * The reply that raised the exception. | |
112 | * @param message | |
113 | * Reason for the error. | |
114 | */ | |
115 | public ReplyException(final Reply reply, final String message) { | |
116 | 31 | super(message); |
117 | 31 | myOkValue = -1; |
118 | 31 | myErrorNumber = -1; |
119 | 31 | myRequest = null; |
120 | 31 | myReply = reply; |
121 | 31 | } |
122 | ||
123 | /** | |
124 | * Create a new ReplyException. | |
125 | * | |
126 | * @param reply | |
127 | * The reply that raised the exception. | |
128 | * @param cause | |
129 | * If known the cause of the exception. | |
130 | */ | |
131 | public ReplyException(final Reply reply, final Throwable cause) { | |
132 | 18 | super(cause); |
133 | ||
134 | 18 | myOkValue = -1; |
135 | 18 | myErrorNumber = -1; |
136 | 18 | myRequest = null; |
137 | 18 | myReply = reply; |
138 | 18 | } |
139 | ||
140 | /** | |
141 | * Returns the value of the "errNo" field in the reply document or -1. | |
142 | * | |
143 | * @return The value of the "errNo" field in the reply document. | |
144 | */ | |
145 | public int getErrorNumber() { | |
146 | 15 | return myErrorNumber; |
147 | } | |
148 | ||
149 | /** | |
150 | * Returns the value of the "ok" field in the reply document or -1. | |
151 | * | |
152 | * @return The value of the "ok" field in the reply document. | |
153 | */ | |
154 | public int getOkValue() { | |
155 | 14 | return myOkValue; |
156 | } | |
157 | ||
158 | /** | |
159 | * Returns the reply. | |
160 | * | |
161 | * @return The reply. | |
162 | */ | |
163 | public Reply getReply() { | |
164 | 13 | return myReply; |
165 | } | |
166 | ||
167 | /** | |
168 | * Returns the original request message, if known. | |
169 | * | |
170 | * @return The original request message, if known. | |
171 | */ | |
172 | public Message getRequest() { | |
173 | 9 | return myRequest; |
174 | } | |
175 | } |