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