This project has retired. For details please refer to its Attic page.
RegistryV3Exception xref
View Javadoc
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.ws.scout.registry;
17  
18  import org.uddi.api_v3.*;
19  
20  /**
21   * Thrown to indicate that a UDDI Exception was encountered.
22   * 
23   * <i>Borrowed from jUDDI project.</i>
24   *
25   * @author Steve Viens (sviens@apache.org)
26   */
27  public class RegistryV3Exception extends Exception
28  {
29  	private static final long serialVersionUID = -733955749275810694L;
30  	public static final int E_ASSERTION_NOT_FOUND = 30000;
31  	public static final int E_AUTH_TOKEN_EXPIRED = 10110;
32  	public static final int E_AUTH_TOKEN_REQUIRED = 10120;
33  	public static final int E_ACCOUNT_LIMIT_EXCEEDED = 10160;
34  	public static final int E_BUSY = 10400;
35  	public static final int E_CATEGORIZATION_NOT_ALLOWED = 20100;
36  	public static final int E_FATAL_ERROR = 10500;
37  	public static final int E_INVALID_KEY_PASSED = 10210;
38  	public static final int E_INVALID_PROJECTION = 20230;
39  	public static final int E_INVALID_CATEGORY = 20000;
40  	public static final int E_INVALID_COMPLETION_STATUS = 30100;
41  	public static final int E_INVALID_URL_PASSED = 10220;
42  	public static final int E_INVALID_VALUE = 20200;
43  	public static final int E_KEY_RETIRED = 10310;
44  	public static final int E_LANGUAGE_ERROR = 10060;
45  	public static final int E_MESSAGE_TOO_LARGE = 30110;
46  	public static final int E_NAME_TOO_LONG = 10020;
47  	public static final int E_OPERATOR_MISMATCH = 10130;
48  	public static final int E_PUBLISHER_CANCELLED = 30220;
49  	public static final int E_REQUEST_DENIED = 30210;
50  	public static final int E_SECRET_UNKNOWN = 30230;
51  	public static final int E_SUCCESS = 0;
52  	public static final int E_TOO_MANY_OPTIONS = 10030;
53  	public static final int E_TRANSFER_ABORTED = 30200;
54  	public static final int E_UNRECOGNIZED_VERSION = 10040;
55  	public static final int E_UNKNOWN_USER = 10150;
56  	public static final int E_UNSUPPORTED = 10050;
57  	public static final int E_USER_MISMATCH = 10140;
58  	public static final int E_VALUE_NOT_ALLOWED = 20210;
59  	public static final int E_UNVALIDATABLE = 20220;
60  	public static final int E_REQUEST_TIMEOUT = 20240;
61  	public static final int E_INVALID_TIME = 40030;
62  	public static final int E_RESULT_SET_TOO_LARGE = 40300;
63  
64    // SOAP SOAPFault Actor
65    private String faultActor;
66  
67    // SOAP SOAPFault Code
68    private String faultCode;
69  
70    // SOAP SOAPFault SOAPMessage
71    private String faultString;
72  
73    // UDDI DispositionReport
74    private DispositionReport dispReport;
75    
76    private ObjectFactory objectFactory = new ObjectFactory();
77  
78    /**
79     * Constructs a RegistryException instance.
80     * @param msg additional error information
81     */
82    public RegistryV3Exception(String msg)
83    {
84      super(msg);
85  
86      setFaultCode(null);
87      setFaultString(msg);
88      setFaultActor(null);
89    }
90  
91    /**
92     * Constructs a RegistryException instance.
93     * @param ex the original exception
94     */
95    public RegistryV3Exception(Exception ex)
96    {
97      super(ex);
98      
99      if (ex != null)
100     {
101       // Not sure why this would ever happen but 
102       // just in case we are asked to create a new
103       // RegistryException using values from another
104       // let's be sure to grab all relevant values.
105       //
106       if (ex instanceof RegistryV3Exception)
107       {
108         RegistryV3Exception../org/apache/ws/scout/registry/RegistryV3Exception.html#RegistryV3Exception">RegistryV3Exception regex = (RegistryV3Exception)ex;
109         setFaultCode(regex.getFaultCode());
110         setFaultString(regex.getFaultString());
111         setFaultActor(regex.getFaultActor());
112         setDispositionReport(regex.getDispositionReport());
113       }
114       else // Not a RegistryException (or subclass)
115       {
116         setFaultString(ex.getMessage());
117       }
118     }
119   }
120 
121   /**
122    * Constructs a RegistryException instance.
123    * 
124    * @param fCode
125    * @param fString
126    * @param fActor
127    * @param dispRpt
128    */
129   public RegistryV3Exception(String fCode,String fString,String fActor,DispositionReport dispRpt)
130   {
131     super(fString);
132 
133     setFaultCode(fCode);
134     setFaultString(fString);
135     setFaultActor(fActor);
136     setDispositionReport(dispRpt);
137   }
138 
139   /**
140    * Constructs a RegistryException instance.
141    * @param ex the original exception
142    */
143   RegistryV3Exception(String fCode,int errno,String msg)
144   {
145     super(buildMessage(errno,msg));
146 
147     String errCode = lookupErrCode(errno);
148 
149     if (fCode != null) {
150     	setFaultCode(fCode);
151     }
152     
153     setFaultString(getMessage());
154     
155     Result r = this.objectFactory.createResult();
156     ErrInfo ei = this.objectFactory.createErrInfo();
157 
158     if (errCode != null) {
159     	ei.setErrCode(errCode);
160     }
161 
162     ei.setValue(getMessage());
163 
164    	r.setErrno(errno);
165 
166     if (ei != null) {
167     	r.setErrInfo(ei);
168     }
169 
170     addResult(r);
171   }
172 
173   /**
174    * Sets the fault actor of this SOAP SOAPFault to the given value.
175    * @param actor The new actor value for this SOAP SOAPFault.
176    */
177   public void setFaultActor(String actor)
178   {
179     this.faultActor = actor;
180   }
181 
182   /**
183    * Returns the fault actor of this SOAP SOAPFault.
184    * @return The fault actor of this SOAP SOAPFault.
185    */
186   public String getFaultActor()
187   {
188     return this.faultActor;
189   }
190 
191   /**
192    * Sets the fault code of this SOAP SOAPFault to the given value.
193    * @param code The new code number for this SOAP SOAPFault.
194    */
195   public void setFaultCode(String code)
196   {
197     this.faultCode = code;
198   }
199 
200   /**
201    * Returns the fault code of this SOAP SOAPFault.
202    * @return The fault code of this SOAP SOAPFault.
203    */
204   public String getFaultCode()
205   {
206     return this.faultCode;
207   }
208 
209   /**
210    * Sets the fault string of this SOAP SOAPFault to the given value.
211    * @param value The new fault string for this SOAP SOAPFault.
212    */
213   public void setFaultString(String value)
214   {
215     this.faultString = value;
216   }
217 
218   /**
219    * Returns the fault string of this SOAP SOAPFault.
220    * @return The fault string of this SOAP SOAPFault.
221    */
222   public String getFaultString()
223   {
224     return this.faultString;
225   }
226 
227   /**
228    * Sets the UDDI DispositionReport value to the instance
229    * specified
230    * @param dispRpt The new UDDI DispositionReport instance for
231    *  this SOAP Fault.
232    */
233   public void setDispositionReport(DispositionReport dispRpt)
234   {
235     this.dispReport = dispRpt;
236   }
237 
238   /**
239    * Returns the disposition report associated with this jUDDI exception. It
240    * uses the results Vector to determine if a disposition report is present
241    * and should be returned.
242    * @return The disposition report associated with this jUDDI exception.
243    */
244   public DispositionReport getDispositionReport()
245   {
246     return this.dispReport;
247   }
248 
249   /**
250    * Adds a result instance to this Exception. Multiple result objects
251    * may exist within a DispositionReport
252    */
253   public void addResult(Result result)
254   {
255     if (this.dispReport==null) {
256       this.dispReport = this.objectFactory.createDispositionReport();
257     }
258 
259     Result jaxbResult = this.objectFactory.createResult();
260     this.dispReport.getResult().add(jaxbResult);
261     
262     if (result.getErrInfo() != null) jaxbResult.setErrInfo(result.getErrInfo());
263     if (result.getKeyType() != null) jaxbResult.setKeyType(result.getKeyType());
264     jaxbResult.setErrno(result.getErrno());
265   }
266 
267   /**
268    *
269    */
270   public String toString()
271   {
272     String msg = getMessage();
273     if (msg == null)
274       return "";
275     else
276       return getMessage();
277   }
278   
279   private static final String buildMessage(int errno,String msg)
280   {
281     StringBuffer buffer = new StringBuffer();
282     
283     String errCode = lookupErrCode(errno);
284     if (errCode != null)
285     {
286       buffer.append(errCode);
287       buffer.append(" ");
288     }
289     
290     buffer.append("(");
291     buffer.append(errno);
292     buffer.append(") ");
293     
294     //String errText = lookupErrText(errno);
295     // FIXME: What should error text be?
296     String errText = "";
297     if (errText != null)
298     {
299       buffer.append(errText);
300       buffer.append(" ");
301     }
302     
303     if ((msg != null) && (msg.trim().length() > 0))
304     {
305       buffer.append(msg);
306     }
307     
308     return buffer.toString();
309   }
310 
311   public static final String lookupErrCode(int errno)
312   {
313 	  switch (errno)
314 	  {
315 	  case E_ACCOUNT_LIMIT_EXCEEDED     : return "E_accountLimitExceeded";
316 	  case E_ASSERTION_NOT_FOUND        : return "E_assertionNotFound"; 
317 	  case E_AUTH_TOKEN_EXPIRED         : return "E_authTokenExpired";
318 	  case E_AUTH_TOKEN_REQUIRED        : return "E_authTokenRequired";
319 	  case E_BUSY                       : return "E_busy";
320 	  case E_CATEGORIZATION_NOT_ALLOWED : return "E_categorizationNotAllowed";
321 	  case E_FATAL_ERROR                : return "E_fatalError";
322 	  case E_INVALID_CATEGORY           : return "E_invalidCategory";
323 	  case E_INVALID_COMPLETION_STATUS  : return "E_invalidCompletionStatus";
324 	  case E_INVALID_KEY_PASSED         : return "E_invalidKeyPassed";
325 	  case E_INVALID_PROJECTION         : return "E_invalidProjection";
326 	  case E_INVALID_TIME               : return "E_invalidTime";
327 	  case E_INVALID_URL_PASSED         : return "E_invalidURLPassed";
328 	  case E_INVALID_VALUE              : return "E_invalidValue";
329 	  case E_KEY_RETIRED                : return "E_keyRetired";
330 	  case E_LANGUAGE_ERROR             : return "E_languageError";
331 	  case E_MESSAGE_TOO_LARGE          : return "E_messageTooLarge";
332 	  case E_NAME_TOO_LONG              : return "E_nameTooLong";
333 	  case E_OPERATOR_MISMATCH          : return "E_operatorMismatch";
334 	  case E_PUBLISHER_CANCELLED        : return "E_publisherCancelled";
335 	  case E_REQUEST_DENIED             : return "E_requestDenied";
336 	  case E_REQUEST_TIMEOUT            : return "E_requestTimeout";
337 	  case E_RESULT_SET_TOO_LARGE       : return "E_resultSetTooLarge";
338 	  case E_SECRET_UNKNOWN             : return "E_secretUnknown";
339 	  case E_SUCCESS                    : return "E_success";
340 	  case E_TOO_MANY_OPTIONS           : return "E_tooManyOptions";
341 	  case E_TRANSFER_ABORTED           : return "E_transferAborted";
342 	  case E_UNKNOWN_USER               : return "E_unknownUser";
343 	  case E_UNRECOGNIZED_VERSION       : return "E_unrecognizedVersion";
344 	  case E_UNSUPPORTED                : return "E_unsupported";
345 	  case E_UNVALIDATABLE              : return "E_unvalidatable";
346 	  case E_USER_MISMATCH              : return "E_userMismatch";
347 	  case E_VALUE_NOT_ALLOWED          : return "E_valueNotAllowed";
348 	  default                           : return null;
349 	  }
350   }  
351 }