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 public static final String LOCAL_EN = "en";
62
63
64
65
66 private static final String DESCRIPTION_MESSAGE = "{0}: {1}";
67
68
69
70
71 private static final String CAUSE_MESSAGE = "Caused by {0}: {1}";
72
73
74
75
76 private static final String STACKTRACE_MESSAGE = "\tat {0}";
77
78
79
80
81 private final Calendar timestamp = new GregorianCalendar();
82
83 private static final long serialVersionUID = 1L;
84
85
86
87
88 public AgreementFactoryException()
89 {
90 super();
91 }
92
93
94
95
96
97 public AgreementFactoryException( String message )
98 {
99 super( message );
100
101 }
102
103
104
105
106
107
108
109
110
111 public AgreementFactoryException( String message, ContinuingFaultType fault )
112 {
113 super( message );
114 FaultCause cause = fault.getFaultCause();
115 if ( cause != null )
116 {
117 XmlObject[] causeDoc =
118 cause.selectChildren( ContinuingFaultDocument.type.getDocumentElementName() );
119
120 if ( causeDoc.length > 0 )
121 {
122 ContinuingFaultType cf = (ContinuingFaultType) causeDoc[0];
123 AgreementFactoryException rootEx =
124 new AgreementFactoryException( cf.getDescriptionArray( 0 ).getStringValue(), cf );
125 initCause( rootEx );
126 }
127 }
128 }
129
130
131
132
133
134
135
136 public AgreementFactoryException( String message, Throwable cause )
137 {
138 super( message, cause );
139 }
140
141
142
143
144
145 public AgreementFactoryException( Throwable cause )
146 {
147 super( cause );
148 }
149
150
151
152
153 public BaseFaultType getBaseFault()
154 {
155 BaseFaultDocument baseFaultDocument = BaseFaultDocument.Factory.newInstance();
156 BaseFaultType baseFault = baseFaultDocument.addNewBaseFault();
157
158 baseFault.addNewErrorCode();
159 baseFault.getErrorCode().setDialect( WsagConstants.WSAG4J_NAMESPACE );
160 baseFault.getErrorCode().set( XmlString.Factory.newValue( getErrorCode() ) );
161
162 baseFault.setTimestamp( timestamp );
163
164 Description description = baseFault.addNewDescription();
165 description.setLang( LOCAL_EN );
166 description.setStringValue( MessageFormat.format( DESCRIPTION_MESSAGE, new Object[] {
167 this.getClass().getName(), getMessage() } ) );
168
169 StackTraceElement[] stackTrace = getStackTrace();
170 for ( int i = 0; i < stackTrace.length; i++ )
171 {
172 description = baseFault.addNewDescription();
173 description.setLang( LOCAL_EN );
174 description.setStringValue( MessageFormat.format( STACKTRACE_MESSAGE,
175 new Object[] { stackTrace[i] } ) );
176 }
177
178 if ( getCause() != null )
179 {
180 description = baseFault.addNewDescription();
181 description.setLang( LOCAL_EN );
182 description.setStringValue( MessageFormat.format( CAUSE_MESSAGE, new Object[] {
183 getCause().getClass().getName(), getCause().getMessage() } ) );
184 }
185
186 return baseFault;
187 }
188
189 @Override
190 public int getErrorCode()
191 {
192 return AGREEMENT_FACTORY_ERROR;
193 }
194 }