View Javadoc

1   /**
2    * Licensed to jclouds, Inc. (jclouds) under one or more
3    * contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  jclouds licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.jclouds.savvis.vpdc.domain;
20  
21  import org.jclouds.javax.annotation.Nullable;
22  
23  /**
24   * 
25   * 
26   * @author Adrian Cole
27   */
28  public class TaskError {
29  
30     public static Builder builder() {
31        return new Builder();
32     }
33  
34     public static class Builder {
35  
36        private String message;
37        private int majorErrorCode = -1;
38        private int minorErrorCode = -1;
39        private String vendorSpecificErrorCode;
40  
41        public Builder message(String message) {
42           this.message = message;
43           return this;
44        }
45  
46        public Builder majorErrorCode(int majorErrorCode) {
47           this.majorErrorCode = majorErrorCode;
48           return this;
49        }
50  
51        public Builder minorErrorCode(int minorErrorCode) {
52           this.minorErrorCode = minorErrorCode;
53           return this;
54        }
55  
56        public Builder vendorSpecificErrorCode(String vendorSpecificErrorCode) {
57           this.vendorSpecificErrorCode = vendorSpecificErrorCode;
58           return this;
59        }
60  
61        public TaskError build() {
62           return new TaskError(message, majorErrorCode, minorErrorCode, vendorSpecificErrorCode);
63        }
64     }
65  
66     private final String message;
67     private final int majorErrorCode;
68     private final int minorErrorCode;
69     private final String vendorSpecificErrorCode;
70  
71     public TaskError(String message, int majorErrorCode, int minorErrorCode, @Nullable String vendorSpecificErrorCode) {
72        this.message = message;
73        this.majorErrorCode = majorErrorCode;
74        this.minorErrorCode = minorErrorCode;
75        this.vendorSpecificErrorCode = vendorSpecificErrorCode;
76     }
77  
78     /**
79      * 
80      * @return message describing the error
81      */
82     public String getMessage() {
83        return message;
84     }
85  
86     /**
87      * 
88      * @return matches the HTTP status code
89      */
90     public int getMajorErrorCode() {
91        return majorErrorCode;
92     }
93  
94     /**
95      * 
96      * @return matches the minor code, typically -1
97      */
98     public int getMinorErrorCode() {
99        return minorErrorCode;
100    }
101 
102    /**
103     * 
104     * @return optional additional information about the source of the error
105     */
106    @Nullable
107    public String getVendorSpecificErrorCode() {
108       return vendorSpecificErrorCode;
109    }
110 
111    @Override
112    public int hashCode() {
113       final int prime = 31;
114       int result = 1;
115       result = prime * result + majorErrorCode;
116       result = prime * result + ((message == null) ? 0 : message.hashCode());
117       result = prime * result + minorErrorCode;
118       result = prime * result + ((vendorSpecificErrorCode == null) ? 0 : vendorSpecificErrorCode.hashCode());
119       return result;
120    }
121 
122    @Override
123    public boolean equals(Object obj) {
124       if (this == obj)
125          return true;
126       if (obj == null)
127          return false;
128       if (getClass() != obj.getClass())
129          return false;
130       TaskError other = (TaskError) obj;
131       if (majorErrorCode != other.majorErrorCode)
132          return false;
133       if (message == null) {
134          if (other.message != null)
135             return false;
136       } else if (!message.equals(other.message))
137          return false;
138       if (minorErrorCode != other.minorErrorCode)
139          return false;
140       if (vendorSpecificErrorCode == null) {
141          if (other.vendorSpecificErrorCode != null)
142             return false;
143       } else if (!vendorSpecificErrorCode.equals(other.vendorSpecificErrorCode))
144          return false;
145       return true;
146    }
147 
148    @Override
149    public String toString() {
150       return "[message=" + message + ", majorErrorCode=" + majorErrorCode + ", minorErrorCode=" + minorErrorCode
151             + ", vendorSpecificErrorCode=" + vendorSpecificErrorCode + "]";
152    }
153 
154 }