1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.api.exceptions;
36
37 import java.text.MessageFormat;
38 import java.util.Calendar;
39 import java.util.GregorianCalendar;
40
41 import org.apache.xmlbeans.XmlObject;
42 import org.apache.xmlbeans.XmlString;
43 import org.oasisOpen.docs.wsrf.bf2.BaseFaultDocument;
44 import org.oasisOpen.docs.wsrf.bf2.BaseFaultType;
45 import org.oasisOpen.docs.wsrf.bf2.BaseFaultType.Description;
46 import org.oasisOpen.docs.wsrf.bf2.BaseFaultType.FaultCause;
47 import org.ogf.graap.wsag.api.WsagConstants;
48 import org.ogf.schemas.graap.wsAgreement.ContinuingFaultDocument;
49 import org.ogf.schemas.graap.wsAgreement.ContinuingFaultType;
50
51
52
53
54
55
56 public class AgreementFactoryException extends WSAgreementException
57 {
58
59
60
61
62 private static final int ERROR_CODE = 1000;
63
64
65
66
67 public static final String LOCAL_EN = "en";
68
69
70
71
72 private static final String DESCRIPTION_MESSAGE = "{0}: {1}";
73
74
75
76
77 private static final String CAUSE_MESSAGE = "Caused by {0}: {1}";
78
79
80
81
82 private static final String STACKTRACE_MESSAGE = "\tat {0}";
83
84
85
86
87 private Calendar timestamp = new GregorianCalendar();
88
89 private static final long serialVersionUID = 1L;
90
91
92
93
94 public AgreementFactoryException()
95 {
96 super();
97 }
98
99
100
101
102
103 public AgreementFactoryException( String message )
104 {
105 super( message );
106
107 }
108
109
110
111
112
113
114
115
116
117 public AgreementFactoryException( String message, ContinuingFaultType fault )
118 {
119 super( message );
120 FaultCause cause = fault.getFaultCause();
121 if ( cause != null )
122 {
123 XmlObject[] causeDoc =
124 cause.selectChildren( ContinuingFaultDocument.type.getDocumentElementName() );
125
126 if ( causeDoc.length > 0 )
127 {
128 ContinuingFaultType cf = (ContinuingFaultType) causeDoc[0];
129 AgreementFactoryException rootEx =
130 new AgreementFactoryException( cf.getDescriptionArray( 0 ).getStringValue(), cf );
131 initCause( rootEx );
132 }
133 }
134 }
135
136
137
138
139
140
141
142 public AgreementFactoryException( String message, Throwable cause )
143 {
144 super( message, cause );
145 }
146
147
148
149
150
151 public AgreementFactoryException( Throwable cause )
152 {
153 super( cause );
154 }
155
156
157
158
159 public BaseFaultType getBaseFault()
160 {
161 BaseFaultDocument baseFaultDocument = BaseFaultDocument.Factory.newInstance();
162 BaseFaultType baseFault = baseFaultDocument.addNewBaseFault();
163
164 baseFault.addNewErrorCode();
165 baseFault.getErrorCode().setDialect( WsagConstants.WSAG4J_NAMESPACE );
166 baseFault.getErrorCode().set( XmlString.Factory.newValue( getErrorCode() ) );
167
168 baseFault.setTimestamp( timestamp );
169
170 Description description = baseFault.addNewDescription();
171 description.setLang( LOCAL_EN );
172 description.setStringValue( MessageFormat.format( DESCRIPTION_MESSAGE, new Object[] {
173 this.getClass().getName(), getMessage() } ) );
174
175 StackTraceElement[] stackTrace = getStackTrace();
176 for ( int i = 0; i < stackTrace.length; i++ )
177 {
178 description = baseFault.addNewDescription();
179 description.setLang( LOCAL_EN );
180 description.setStringValue( MessageFormat.format( STACKTRACE_MESSAGE,
181 new Object[] { stackTrace[i] } ) );
182 }
183
184 if ( getCause() != null )
185 {
186 description = baseFault.addNewDescription();
187 description.setLang( LOCAL_EN );
188 description.setStringValue( MessageFormat.format( CAUSE_MESSAGE, new Object[] {
189 getCause().getClass().getName(), getCause().getMessage() } ) );
190 }
191
192 return baseFault;
193 }
194
195
196
197
198
199
200 protected String getErrorCode()
201 {
202 return Integer.toString( ERROR_CODE );
203 }
204
205 }