| 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.vcloud.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import org.jclouds.javax.annotation.Nullable; |
| 24 | |
| 25 | import org.jclouds.vcloud.domain.VCloudError; |
| 26 | |
| 27 | /** |
| 28 | * |
| 29 | * @author Adrian Cole |
| 30 | * |
| 31 | */ |
| 32 | public class ErrorImpl implements VCloudError { |
| 33 | private final String message; |
| 34 | private final int majorErrorCode; |
| 35 | private final MinorCode minorErrorCode; |
| 36 | @Nullable |
| 37 | private final String vendorSpecificErrorCode; |
| 38 | @Nullable |
| 39 | private final String stackTrace; |
| 40 | |
| 41 | public ErrorImpl(String message, int majorErrorCode, @Nullable MinorCode minorErrorCode, |
| 42 | @Nullable String vendorSpecificErrorCode, @Nullable String stackTrace) { |
| 43 | this.message = checkNotNull(message, "message"); |
| 44 | this.majorErrorCode = majorErrorCode; |
| 45 | this.minorErrorCode = minorErrorCode; // check null after 0.8 is gone |
| 46 | this.vendorSpecificErrorCode = vendorSpecificErrorCode; |
| 47 | this.stackTrace = stackTrace; |
| 48 | } |
| 49 | |
| 50 | public String getMessage() { |
| 51 | return message; |
| 52 | } |
| 53 | |
| 54 | public int getMajorErrorCode() { |
| 55 | return majorErrorCode; |
| 56 | } |
| 57 | |
| 58 | public MinorCode getMinorErrorCode() { |
| 59 | return minorErrorCode; |
| 60 | } |
| 61 | |
| 62 | public String getVendorSpecificErrorCode() { |
| 63 | return vendorSpecificErrorCode; |
| 64 | } |
| 65 | |
| 66 | public String getStackTrace() { |
| 67 | return stackTrace; |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public int hashCode() { |
| 72 | final int prime = 31; |
| 73 | int result = 1; |
| 74 | result = prime * result + majorErrorCode; |
| 75 | result = prime * result + ((message == null) ? 0 : message.hashCode()); |
| 76 | result = prime * result + ((minorErrorCode == null) ? 0 : minorErrorCode.hashCode()); |
| 77 | result = prime * result + ((stackTrace == null) ? 0 : stackTrace.hashCode()); |
| 78 | result = prime * result + ((vendorSpecificErrorCode == null) ? 0 : vendorSpecificErrorCode.hashCode()); |
| 79 | return result; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean equals(Object obj) { |
| 84 | if (this == obj) |
| 85 | return true; |
| 86 | if (obj == null) |
| 87 | return false; |
| 88 | if (getClass() != obj.getClass()) |
| 89 | return false; |
| 90 | ErrorImpl other = (ErrorImpl) obj; |
| 91 | if (majorErrorCode != other.majorErrorCode) |
| 92 | return false; |
| 93 | if (message == null) { |
| 94 | if (other.message != null) |
| 95 | return false; |
| 96 | } else if (!message.equals(other.message)) |
| 97 | return false; |
| 98 | if (minorErrorCode == null) { |
| 99 | if (other.minorErrorCode != null) |
| 100 | return false; |
| 101 | } else if (!minorErrorCode.equals(other.minorErrorCode)) |
| 102 | return false; |
| 103 | if (stackTrace == null) { |
| 104 | if (other.stackTrace != null) |
| 105 | return false; |
| 106 | } else if (!stackTrace.equals(other.stackTrace)) |
| 107 | return false; |
| 108 | if (vendorSpecificErrorCode == null) { |
| 109 | if (other.vendorSpecificErrorCode != null) |
| 110 | return false; |
| 111 | } else if (!vendorSpecificErrorCode.equals(other.vendorSpecificErrorCode)) |
| 112 | return false; |
| 113 | return true; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public String toString() { |
| 118 | return "[majorErrorCode=" + majorErrorCode + ", message=" + message + ", minorErrorCode=" + minorErrorCode |
| 119 | + ", stackTrace=" + stackTrace + ", vendorSpecificErrorCode=" + vendorSpecificErrorCode + "]"; |
| 120 | } |
| 121 | |
| 122 | } |