/**
* MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
* Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
/******************************************************************************\
*
* This product was developed by
*
* SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
*
* a government company established under Brazilian law (5.615/70),
* at Department of Development of Porto Alegre.
*
\******************************************************************************/
package serpro.mailarchiver.service.dto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="Fault", propOrder = {
"soapFaultCode", "soapFaultSubCode", "soapFaultString", "soapFaultActor",
"context",
"stackTrace",
"causeClass", "causeMessage", "causeStackTrace"
})
@XmlRootElement(name="Fault")
public class TFault {
public TFault() {}
//--------------------------------------------------------------------------
private String soapFaultCode;
public String getSoapFaultCode() {
return soapFaultCode;
}
public void setSoapFaultCode(String soapFaultCode) {
this.soapFaultCode = soapFaultCode;
}
//--------------------------------------------------------------------------
private String soapFaultSubCode;
public String getSoapFaultSubCode() {
return soapFaultSubCode;
}
public void setSoapFaultSubCode(String soapFaultSubCode) {
this.soapFaultSubCode = soapFaultSubCode;
}
//--------------------------------------------------------------------------
private String soapFaultString;
public String getSoapFaultString() {
return soapFaultString;
}
public void setSoapFaultString(String soapFaultString) {
this.soapFaultString = soapFaultString;
}
//--------------------------------------------------------------------------
private String soapFaultActor;
public String getSoapFaultActor() {
return soapFaultActor;
}
public void setSoapFaultActor(String soapFaultActor) {
this.soapFaultActor = soapFaultActor;
}
//--------------------------------------------------------------------------
@XmlJavaTypeAdapter(FaultContextAdapter.class)
private Map context;
public Map getContext() {
return context;
}
public void setContext(Map context) {
this.context = context;
}
//--------------------------------------------------------------------------
private String stackTrace;
public String getStackTrace() {
return stackTrace;
}
public void setStackTrace(String stackTrace) {
this.stackTrace = stackTrace;
}
//--------------------------------------------------------------------------
private String causeClass;
public String getCauseClass() {
return causeClass;
}
public void setCauseClass(String causeClass) {
this.causeClass = causeClass;
}
//--------------------------------------------------------------------------
private String causeMessage;
public String getCauseMessage() {
return causeMessage;
}
public void setCauseMessage(String causeMessage) {
this.causeMessage = causeMessage;
}
//--------------------------------------------------------------------------
private String causeStackTrace;
public String getCauseStackTrace() {
return causeStackTrace;
}
public void setCauseStackTrace(String causeStackTrace) {
this.causeStackTrace = causeStackTrace;
}
//--------------------------------------------------------------------------
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("FaultInfo")
.append("\n\tfaultCode: ").append(getSoapFaultCode())
.append("\n\tfaultSubCode: ").append(getSoapFaultSubCode())
.append("\n\tfaultActor: ").append(getSoapFaultActor())
.append("\n\tfaultString: ").append(getSoapFaultString());
if(getContext() != null) {
for(Map.Entry entry : getContext().entrySet()) {
sb.append("\n\t").append(entry.getKey()).append(": ").append(entry.getValue());
}
}
if(getCauseStackTrace() != null) {
sb.append("\n\tcause:\n\n").append(getCauseStackTrace());
}
return sb.toString();
}
}
class FaultContext {
public List ctxEntry = new ArrayList();
}
class FaultContextEntry {
// @XmlAttribute
private String ctxKey;
public String getKey() { return ctxKey; }
public void setKey(String key) { ctxKey = key; }
// @XmlValue
private String ctxValue;
public String getValue() { return ctxValue; }
public void setValue(String value) { ctxValue = value; }
}
class FaultContextAdapter extends XmlAdapter> {
@Override
public FaultContext marshal(Map map) throws Exception {
FaultContext faultContext = new FaultContext();
for(Entry entry : map.entrySet()) {
FaultContextEntry faultContextEntry = new FaultContextEntry();
faultContextEntry.setKey(entry.getKey());
faultContextEntry.setValue(entry.getValue());
faultContext.ctxEntry.add(faultContextEntry);
}
return faultContext;
}
@Override
public Map unmarshal(FaultContext faultContext) throws Exception {
HashMap map = new HashMap();
for(FaultContextEntry faultContextEntry : faultContext.ctxEntry) {
map.put(faultContextEntry.getKey(), faultContextEntry.getValue());
}
return map;
}
}