Coverage Report - org.apache.ws.scout.registry.RegistryException
 
Classes in this File Line Coverage Branch Coverage Complexity
RegistryException
0%
0/112
0%
0/60
5.938
 
 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  0
   private 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  0
     super(msg);
 89  
 
 90  0
     setFaultCode(null);
 91  0
     setFaultString(msg);
 92  0
     setFaultActor(null);
 93  0
   }
 94  
 
 95  
   /**
 96  
    * Constructs a RegistryException instance.
 97  
    * @param ex the original exception
 98  
    */
 99  
   public RegistryException(Exception ex)
 100  
   {
 101  0
     super(ex);
 102  
     
 103  0
     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  0
       if (ex instanceof RegistryException)
 111  
       {
 112  0
         RegistryException regex = (RegistryException)ex;
 113  0
         setFaultCode(regex.getFaultCode());
 114  0
         setFaultString(regex.getFaultString());
 115  0
         setFaultActor(regex.getFaultActor());
 116  0
         setDispositionReport(regex.getDispositionReport());
 117  0
       }
 118  
       else // Not a RegistryException (or subclass)
 119  
       {
 120  0
         setFaultString(ex.getMessage());
 121  
       }
 122  
     }
 123  0
   }
 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  0
     super(fString);
 136  
 
 137  0
     setFaultCode(fCode);
 138  0
     setFaultString(fString);
 139  0
     setFaultActor(fActor);
 140  0
     setDispositionReport(dispRpt);
 141  0
   }
 142  
 
 143  
   /**
 144  
    * Constructs a RegistryException instance.
 145  
    * @param ex the original exception
 146  
    */
 147  
   RegistryException(String fCode,int errno,String msg)
 148  
   {
 149  0
     super(buildMessage(errno,msg));
 150  
 
 151  0
     String errCode = lookupErrCode(errno);
 152  
 
 153  0
     if (fCode != null) {
 154  0
             setFaultCode(fCode);
 155  
     }
 156  
     
 157  0
     setFaultString(getMessage());
 158  
     
 159  0
     Result r = this.objectFactory.createResult();
 160  0
     ErrInfo ei = this.objectFactory.createErrInfo();
 161  
 
 162  0
     if (errCode != null) {
 163  0
             ei.setErrCode(errCode);
 164  
     }
 165  
 
 166  0
     ei.setValue(getMessage());
 167  
 
 168  0
            r.setErrno(errno);
 169  
 
 170  0
     if (ei != null) {
 171  0
             r.setErrInfo(ei);
 172  
     }
 173  
 
 174  0
     addResult(r);
 175  0
   }
 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  0
     this.faultActor = actor;
 184  0
   }
 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  0
     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  0
     this.faultCode = code;
 202  0
   }
 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  0
     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  0
     this.faultString = value;
 220  0
   }
 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  0
     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  0
     this.dispReport = dispRpt;
 240  0
   }
 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  0
     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  0
     if (this.dispReport==null) {
 260  0
       this.dispReport = this.objectFactory.createDispositionReport();
 261  
     }
 262  
 
 263  0
     Result jaxbResult = this.objectFactory.createResult();
 264  0
     this.dispReport.getResult().add(jaxbResult);
 265  
     
 266  0
     if (result.getErrInfo() != null) jaxbResult.setErrInfo(result.getErrInfo());
 267  0
     if (result.getKeyType() != null) jaxbResult.setKeyType(result.getKeyType());
 268  0
     jaxbResult.setErrno(result.getErrno());
 269  0
   }
 270  
 
 271  
   /**
 272  
    *
 273  
    */
 274  
   public String toString()
 275  
   {
 276  0
     String msg = getMessage();
 277  0
     if (msg == null)
 278  0
       return "";
 279  
     else
 280  0
       return getMessage();
 281  
   }
 282  
   
 283  
   private static final String buildMessage(int errno,String msg)
 284  
   {
 285  0
     StringBuffer buffer = new StringBuffer();
 286  
     
 287  0
     String errCode = lookupErrCode(errno);
 288  0
     if (errCode != null)
 289  
     {
 290  0
       buffer.append(errCode);
 291  0
       buffer.append(" ");
 292  
     }
 293  
     
 294  0
     buffer.append("(");
 295  0
     buffer.append(errno);
 296  0
     buffer.append(") ");
 297  
     
 298  
     //String errText = lookupErrText(errno);
 299  
     // FIXME: What should error text be?
 300  0
     String errText = "";
 301  0
     if (errText != null)
 302  
     {
 303  0
       buffer.append(errText);
 304  0
       buffer.append(" ");
 305  
     }
 306  
     
 307  0
     if ((msg != null) && (msg.trim().length() > 0))
 308  
     {
 309  0
       buffer.append(msg);
 310  
     }
 311  
     
 312  0
     return buffer.toString();
 313  
   }
 314  
 
 315  
   public static final String lookupErrCode(int errno)
 316  
   {
 317  0
           switch (errno)
 318  
           {
 319  0
           case E_ACCOUNT_LIMIT_EXCEEDED     : return "E_accountLimitExceeded";
 320  0
           case E_ASSERTION_NOT_FOUND        : return "E_assertionNotFound"; 
 321  0
           case E_AUTH_TOKEN_EXPIRED         : return "E_authTokenExpired";
 322  0
           case E_AUTH_TOKEN_REQUIRED        : return "E_authTokenRequired";
 323  0
           case E_BUSY                       : return "E_busy";
 324  0
           case E_CATEGORIZATION_NOT_ALLOWED : return "E_categorizationNotAllowed";
 325  0
           case E_FATAL_ERROR                : return "E_fatalError";
 326  0
           case E_INVALID_CATEGORY           : return "E_invalidCategory";
 327  0
           case E_INVALID_COMPLETION_STATUS  : return "E_invalidCompletionStatus";
 328  0
           case E_INVALID_KEY_PASSED         : return "E_invalidKeyPassed";
 329  0
           case E_INVALID_PROJECTION         : return "E_invalidProjection";
 330  0
           case E_INVALID_TIME               : return "E_invalidTime";
 331  0
           case E_INVALID_URL_PASSED         : return "E_invalidURLPassed";
 332  0
           case E_INVALID_VALUE              : return "E_invalidValue";
 333  0
           case E_KEY_RETIRED                : return "E_keyRetired";
 334  0
           case E_LANGUAGE_ERROR             : return "E_languageError";
 335  0
           case E_MESSAGE_TOO_LARGE          : return "E_messageTooLarge";
 336  0
           case E_NAME_TOO_LONG              : return "E_nameTooLong";
 337  0
           case E_OPERATOR_MISMATCH          : return "E_operatorMismatch";
 338  0
           case E_PUBLISHER_CANCELLED        : return "E_publisherCancelled";
 339  0
           case E_REQUEST_DENIED             : return "E_requestDenied";
 340  0
           case E_REQUEST_TIMEOUT            : return "E_requestTimeout";
 341  0
           case E_RESULT_SET_TOO_LARGE       : return "E_resultSetTooLarge";
 342  0
           case E_SECRET_UNKNOWN             : return "E_secretUnknown";
 343  0
           case E_SUCCESS                    : return "E_success";
 344  0
           case E_TOO_MANY_OPTIONS           : return "E_tooManyOptions";
 345  0
           case E_TRANSFER_ABORTED           : return "E_transferAborted";
 346  0
           case E_UNKNOWN_USER               : return "E_unknownUser";
 347  0
           case E_UNRECOGNIZED_VERSION       : return "E_unrecognizedVersion";
 348  0
           case E_UNSUPPORTED                : return "E_unsupported";
 349  0
           case E_UNVALIDATABLE              : return "E_unvalidatable";
 350  0
           case E_USER_MISMATCH              : return "E_userMismatch";
 351  0
           case E_VALUE_NOT_ALLOWED          : return "E_valueNotAllowed";
 352  0
           default                           : return null;
 353  
           }
 354  
   }  
 355  
 }