001/* 002 * Copyright 2010-2013 Ning, Inc. 003 * 004 * Ning licenses this file to you under the Apache License, version 2.0 005 * (the "License"); you may not use this file except in compliance with the 006 * License. You may obtain a copy of the License at: 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations 014 * under the License. 015 */ 016 017package com.ning.billing.recurly.model; 018 019import java.util.Map; 020 021import javax.xml.bind.annotation.XmlElement; 022import javax.xml.bind.annotation.XmlRootElement; 023 024@XmlRootElement(name = "errors") 025public class Errors extends RecurlyObject { 026 027 @XmlElement(name = "transaction_error") 028 private TransactionError transactionError; 029 030 @XmlElement(name = "transaction") 031 private Transaction transaction; 032 033 @XmlElement(name = "error") 034 private RecurlyErrors recurlyErrors; 035 036 public TransactionError getTransactionError() { 037 return transactionError; 038 } 039 040 public void setTransactionError(final TransactionError transactionError) { 041 this.transactionError = transactionError; 042 } 043 044 public Transaction getTransaction() { 045 return transaction; 046 } 047 048 public void setTransaction(final Transaction transaction) { 049 this.transaction = transaction; 050 } 051 052 public RecurlyErrors getRecurlyErrors() { 053 return recurlyErrors; 054 } 055 056 public void setRecurlyErrors(final Object recurlyError) { 057 if (recurlyError instanceof Map) { 058 final RecurlyError error = new RecurlyError(); 059 error.setField((String) ((Map) recurlyError).get("field")); 060 error.setSymbol((String) ((Map) recurlyError).get("symbol")); 061 error.setMessage((String) ((Map) recurlyError).get("")); 062 063 if (this.recurlyErrors == null) { 064 this.recurlyErrors = new RecurlyErrors(); 065 } 066 this.recurlyErrors.add(error); 067 } else { 068 this.recurlyErrors = (RecurlyErrors) recurlyErrors; 069 } 070 } 071 072 @Override 073 public String toString() { 074 final StringBuilder sb = new StringBuilder("Errors{"); 075 sb.append("transactionError=").append(transactionError); 076 sb.append(", transaction=").append(transaction); 077 sb.append(", recurlyErrors=").append(recurlyErrors); 078 sb.append('}'); 079 return sb.toString(); 080 } 081 082 @Override 083 public boolean equals(final Object o) { 084 if (this == o) { 085 return true; 086 } 087 if (o == null || getClass() != o.getClass()) { 088 return false; 089 } 090 091 final Errors errors = (Errors) o; 092 093 if (recurlyErrors != null ? !recurlyErrors.equals(errors.recurlyErrors) : errors.recurlyErrors != null) { 094 return false; 095 } 096 if (transaction != null ? !transaction.equals(errors.transaction) : errors.transaction != null) { 097 return false; 098 } 099 if (transactionError != null ? !transactionError.equals(errors.transactionError) : errors.transactionError != null) { 100 return false; 101 } 102 103 return true; 104 } 105 106 @Override 107 public int hashCode() { 108 int result = transactionError != null ? transactionError.hashCode() : 0; 109 result = 31 * result + (transaction != null ? transaction.hashCode() : 0); 110 result = 31 * result + (recurlyErrors != null ? recurlyErrors.hashCode() : 0); 111 return result; 112 } 113}