KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > error > RegistryException


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.error;
17
18 import org.apache.juddi.datatype.RegistryObject;
19 import org.apache.juddi.datatype.response.DispositionReport;
20 import org.apache.juddi.datatype.response.Result;
21
22 /**
23  * Thrown to indicate that a UDDI Exception was encountered.
24  *
25  * @author Steve Viens (sviens@apache.org)
26  */

27 public class RegistryException extends Exception JavaDoc implements RegistryObject
28 {
29   // SOAP SOAPFault Actor
30
private String JavaDoc faultActor;
31
32   // SOAP SOAPFault Code
33
private String JavaDoc faultCode;
34
35   // SOAP SOAPFault SOAPMessage
36
private String JavaDoc faultString;
37
38   // UDDI DispositionReport
39
private DispositionReport dispReport;
40
41   /**
42    * Constructs a RegistryException instance.
43    * @param msg additional error information
44    */

45   public RegistryException(String JavaDoc msg)
46   {
47     super(msg);
48
49     setFaultCode(null);
50     setFaultString(msg);
51     setFaultActor(null);
52   }
53
54   /**
55    * Constructs a RegistryException instance.
56    * @param ex the original exception
57    */

58   public RegistryException(Exception JavaDoc ex)
59   {
60     super(ex);
61     
62     if (ex != null)
63     {
64       // Not sure why this would ever happen but
65
// just in case we are asked to create a new
66
// RegistryException using values from another
67
// let's be sure to grab all relevant values.
68
//
69
if (ex instanceof RegistryException)
70       {
71         RegistryException regex = (RegistryException)ex;
72         setFaultCode(regex.getFaultCode());
73         setFaultString(regex.getFaultString());
74         setFaultActor(regex.getFaultActor());
75         setDispositionReport(regex.getDispositionReport());
76       }
77       else // Not a RegistryException (or subclass)
78
{
79         setFaultString(ex.getMessage());
80       }
81     }
82   }
83
84   /**
85    * Constructs a RegistryException instance.
86    * @param ex the original exception
87    */

88   public RegistryException(String JavaDoc fCode,String JavaDoc fString,String JavaDoc fActor,DispositionReport dispRpt)
89   {
90     super(fString);
91
92     setFaultCode(fCode);
93     setFaultString(fString);
94     setFaultActor(fActor);
95     setDispositionReport(dispRpt);
96   }
97
98   /**
99    * Constructs a RegistryException instance.
100    * @param ex the original exception
101    */

102   RegistryException(String JavaDoc fCode,int errno,String JavaDoc msg)
103   {
104     super(buildMessage(errno,msg));
105
106     String JavaDoc errCode = Result.lookupErrCode(errno);
107
108     setFaultCode(fCode);
109     setFaultString(getMessage());
110     addResult(new Result(errno,errCode,getMessage()));
111   }
112
113   /**
114    * Sets the fault actor of this SOAP SOAPFault to the given value.
115    * @param actor The new actor value for this SOAP SOAPFault.
116    */

117   public void setFaultActor(String JavaDoc actor)
118   {
119     this.faultActor = actor;
120   }
121
122   /**
123    * Returns the fault actor of this SOAP SOAPFault.
124    * @return The fault actor of this SOAP SOAPFault.
125    */

126   public String JavaDoc getFaultActor()
127   {
128     return this.faultActor;
129   }
130
131   /**
132    * Sets the fault code of this SOAP SOAPFault to the given value.
133    * @param code The new code number for this SOAP SOAPFault.
134    */

135   public void setFaultCode(String JavaDoc code)
136   {
137     this.faultCode = code;
138   }
139
140   /**
141    * Returns the fault code of this SOAP SOAPFault.
142    * @return The fault code of this SOAP SOAPFault.
143    */

144   public String JavaDoc getFaultCode()
145   {
146     return this.faultCode;
147   }
148
149   /**
150    * Sets the fault string of this SOAP SOAPFault to the given value.
151    * @param value The new fault string for this SOAP SOAPFault.
152    */

153   public void setFaultString(String JavaDoc value)
154   {
155     this.faultString = value;
156   }
157
158   /**
159    * Returns the fault string of this SOAP SOAPFault.
160    * @return The fault string of this SOAP SOAPFault.
161    */

162   public String JavaDoc getFaultString()
163   {
164     return this.faultString;
165   }
166
167   /**
168    * Sets the UDDI DispositionReport value to the instance
169    * specified
170    * @param dispRpt The new UDDI DispositionReport instance for
171    * this SOAP Fault.
172    */

173   public void setDispositionReport(DispositionReport dispRpt)
174   {
175     this.dispReport = dispRpt;
176   }
177
178   /**
179    * Returns the disposition report associated with this jUDDI exception. It
180    * uses the results Vector to determine if a disposition report is present
181    * and should be returned.
182    * @return The disposition report associated with this jUDDI exception.
183    */

184   public DispositionReport getDispositionReport()
185   {
186     return this.dispReport;
187   }
188
189   /**
190    * Adds a result instance to this Exception. Multiple result objects
191    * may exist within a DispositionReport
192    */

193   public void addResult(Result result)
194   {
195     if (this.dispReport==null)
196       this.dispReport = new DispositionReport();
197     this.dispReport.addResult(result);
198   }
199
200   /**
201    *
202    */

203   public String JavaDoc toString()
204   {
205     String JavaDoc msg = getMessage();
206     if (msg == null)
207       return "";
208     else
209       return getMessage();
210   }
211   
212   private static final String JavaDoc buildMessage(int errno,String JavaDoc msg)
213   {
214     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
215     
216     String JavaDoc errCode = Result.lookupErrCode(errno);
217     if (errCode != null)
218     {
219       buffer.append(errCode);
220       buffer.append(" ");
221     }
222     
223     buffer.append("(");
224     buffer.append(errno);
225     buffer.append(") ");
226     
227     String JavaDoc errText = Result.lookupErrText(errno);
228     if (errText != null)
229     {
230       buffer.append(errText);
231       buffer.append(" ");
232     }
233     
234     if ((msg != null) && (msg.trim().length() > 0))
235     {
236       buffer.append(msg);
237     }
238     
239     return buffer.toString();
240   }
241
242   
243   /***************************************************************************/
244   /***************************** TEST DRIVER *********************************/
245   /***************************************************************************/
246
247
248   public static void main(String JavaDoc[] args)
249     throws RegistryException
250   {
251     System.out.println(new AccountLimitExceededException("Additional error information."));
252     System.out.println(new AssertionNotFoundException("Additional error information."));
253     System.out.println(new AuthTokenExpiredException("Additional error information."));
254     System.out.println(new AuthTokenRequiredException("Additional error information."));
255     System.out.println(new BusyException("Additional error information."));
256     System.out.println(new CategorizationNotAllowedException("Additional error information."));
257     System.out.println(new FatalErrorException("Additional error information."));
258     System.out.println(new InvalidCategoryException("Additional error information."));
259     System.out.println(new InvalidCompletionStatusException("Additional error information."));
260     System.out.println(new InvalidKeyPassedException("Additional error information."));
261     System.out.println(new InvalidProjectionException("Additional error information."));
262     System.out.println(new InvalidTimeException("Additional error information."));
263     System.out.println(new InvalidURLPassedException("Additional error information."));
264     System.out.println(new InvalidValueException("Additional error information."));
265     System.out.println(new KeyRetiredException("Additional error information."));
266     System.out.println(new LanguageErrorException("Additional error information."));
267     System.out.println(new MessageTooLargeException("Additional error information."));
268     System.out.println(new NameTooLongException("Additional error information."));
269     System.out.println(new OperatorMismatchException("Additional error information."));
270     System.out.println(new PublisherCancelledException("Additional error information."));
271     System.out.println(new RequestDeniedException("Additional error information."));
272     System.out.println(new RequestTimeoutException("Additional error information."));
273     System.out.println(new ResultSetTooLargeException("Additional error information."));
274     System.out.println(new SecretUnknownException("Additional error information."));
275     System.out.println(new TooManyOptionsException("Additional error information."));
276     System.out.println(new TransferAbortedException("Additional error information."));
277     System.out.println(new UnknownUserException("Additional error information."));
278     System.out.println(new UnknownUserException("Additional error information."));
279     System.out.println(new UnrecognizedVersionException("Additional error information."));
280     System.out.println(new UnsupportedException("Additional error information."));
281     System.out.println(new UnvalidatableException("Additional error information."));
282     System.out.println(new UserMismatchException("Additional error information."));
283     System.out.println(new ValueNotAllowedException("Additional error information."));
284  
285     System.out.println("\n----- RegistryException(String) -----");
286     
287     System.out.println(new RegistryException((String JavaDoc)null));
288     System.out.println(new RegistryException("Additional error information."));
289     
290     System.out.println("\n----- RegistryException(Exception) -----");
291     
292     System.out.println(new RegistryException((Exception JavaDoc)null));
293     System.out.println(new RegistryException((Exception JavaDoc)new Exception JavaDoc("Additional error information.")));
294     System.out.println(new RegistryException((Exception JavaDoc)new RegistryException("Additional error information.")));
295     System.out.println(new RegistryException((Exception JavaDoc)new UnknownUserException("Additional error information.")));
296     
297     System.out.println("\n----- RegistryException(FaultCode,errno,String) -----");
298     
299     System.out.println(new RegistryException(null,-1,null));
300     System.out.println(new RegistryException("Server",-1,null));
301     System.out.println(new RegistryException("Server",Result.E_BUSY,null));
302     System.out.println(new RegistryException("Server",Result.E_BUSY,"Additional error information."));
303   }
304 }
Popular Tags