source: contrib/MailArchiver/sources/src/serpro/mailarchiver/service/dto/TFault.java @ 6785

Revision 6785, 7.0 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
1/**
2 * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface.
3 * Copyright (C) 2012  Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/******************************************************************************\
20*
21*  This product was developed by
22*
23*        SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO),
24*
25*  a government company established under Brazilian law (5.615/70),
26*  at Department of Development of Porto Alegre.
27*
28\******************************************************************************/
29
30package serpro.mailarchiver.service.dto;
31
32import java.util.ArrayList;
33import java.util.HashMap;
34import java.util.List;
35import java.util.Map;
36import java.util.Map.Entry;
37
38import javax.xml.bind.annotation.XmlAccessType;
39import javax.xml.bind.annotation.XmlAccessorType;
40import javax.xml.bind.annotation.XmlRootElement;
41import javax.xml.bind.annotation.XmlType;
42import javax.xml.bind.annotation.adapters.XmlAdapter;
43import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
44
45@XmlAccessorType(XmlAccessType.FIELD)
46@XmlType(name="Fault", propOrder = {
47    "soapFaultCode", "soapFaultSubCode", "soapFaultString", "soapFaultActor",
48    "context",
49    "stackTrace",
50    "causeClass", "causeMessage", "causeStackTrace"
51})
52@XmlRootElement(name="Fault")
53public class TFault {
54
55    public TFault() {}
56
57    //--------------------------------------------------------------------------
58    private String soapFaultCode;
59
60    public String getSoapFaultCode() {
61        return soapFaultCode;
62    }
63
64    public void setSoapFaultCode(String soapFaultCode) {
65        this.soapFaultCode = soapFaultCode;
66    }
67
68    //--------------------------------------------------------------------------
69    private String soapFaultSubCode;
70
71    public String getSoapFaultSubCode() {
72        return soapFaultSubCode;
73    }
74
75    public void setSoapFaultSubCode(String soapFaultSubCode) {
76        this.soapFaultSubCode = soapFaultSubCode;
77    }
78
79    //--------------------------------------------------------------------------
80    private String soapFaultString;
81
82    public String getSoapFaultString() {
83        return soapFaultString;
84    }
85
86    public void setSoapFaultString(String soapFaultString) {
87        this.soapFaultString = soapFaultString;
88    }
89
90    //--------------------------------------------------------------------------
91    private String soapFaultActor;
92
93    public String getSoapFaultActor() {
94        return soapFaultActor;
95    }
96
97    public void setSoapFaultActor(String soapFaultActor) {
98        this.soapFaultActor = soapFaultActor;
99    }
100
101    //--------------------------------------------------------------------------
102    @XmlJavaTypeAdapter(FaultContextAdapter.class)
103    private Map<String, String> context;
104
105    public Map<String, String> getContext() {
106        return context;
107    }
108
109    public void setContext(Map<String, String> context) {
110        this.context = context;
111    }
112
113    //--------------------------------------------------------------------------
114    private String stackTrace;
115
116    public String getStackTrace() {
117        return stackTrace;
118    }
119
120    public void setStackTrace(String stackTrace) {
121        this.stackTrace = stackTrace;
122    }
123
124    //--------------------------------------------------------------------------
125    private String causeClass;
126
127    public String getCauseClass() {
128        return causeClass;
129    }
130
131    public void setCauseClass(String causeClass) {
132        this.causeClass = causeClass;
133    }
134
135    //--------------------------------------------------------------------------
136    private String causeMessage;
137
138    public String getCauseMessage() {
139        return causeMessage;
140    }
141
142    public void setCauseMessage(String causeMessage) {
143        this.causeMessage = causeMessage;
144    }
145
146    //--------------------------------------------------------------------------
147    private String causeStackTrace;
148
149    public String getCauseStackTrace() {
150        return causeStackTrace;
151    }
152
153    public void setCauseStackTrace(String causeStackTrace) {
154        this.causeStackTrace = causeStackTrace;
155    }
156
157    //--------------------------------------------------------------------------
158    @Override
159    public String toString() {
160        StringBuilder sb = new StringBuilder();
161        sb.append("FaultInfo")
162                .append("\n\tfaultCode: ").append(getSoapFaultCode())
163                .append("\n\tfaultSubCode: ").append(getSoapFaultSubCode())
164                .append("\n\tfaultActor: ").append(getSoapFaultActor())
165                .append("\n\tfaultString: ").append(getSoapFaultString());
166
167        if(getContext() != null) {
168            for(Map.Entry<String, String> entry : getContext().entrySet()) {
169                sb.append("\n\t").append(entry.getKey()).append(": ").append(entry.getValue());
170            }
171        }
172
173        if(getCauseStackTrace() != null) {
174            sb.append("\n\tcause:\n\n").append(getCauseStackTrace());
175        }
176
177        return sb.toString();
178    }
179}
180
181class FaultContext {
182    public List<FaultContextEntry> ctxEntry = new ArrayList<FaultContextEntry>();
183}
184
185class FaultContextEntry {
186
187//    @XmlAttribute
188    private String ctxKey;
189    public String getKey() { return ctxKey; }
190    public void setKey(String key) { ctxKey = key; }
191
192//    @XmlValue
193    private String ctxValue;
194    public String getValue() { return ctxValue; }
195    public void setValue(String value) { ctxValue = value; }
196}
197
198class FaultContextAdapter extends XmlAdapter<FaultContext, Map<String, String>> {
199
200    @Override
201    public FaultContext marshal(Map<String, String> map) throws Exception {
202        FaultContext faultContext = new FaultContext();
203        for(Entry<String, String> entry : map.entrySet()) {
204            FaultContextEntry faultContextEntry = new FaultContextEntry();
205            faultContextEntry.setKey(entry.getKey());
206            faultContextEntry.setValue(entry.getValue());
207            faultContext.ctxEntry.add(faultContextEntry);
208        }
209        return faultContext;
210    }
211
212    @Override
213    public Map<String, String> unmarshal(FaultContext faultContext) throws Exception {
214        HashMap<String, String> map = new HashMap<String, String>();
215        for(FaultContextEntry faultContextEntry : faultContext.ctxEntry) {
216            map.put(faultContextEntry.getKey(), faultContextEntry.getValue());
217        }
218        return map;
219    }
220}
Note: See TracBrowser for help on using the repository browser.