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.XmlString;
42 import org.oasisOpen.docs.wsrf.bf2.BaseFaultDocument;
43 import org.oasisOpen.docs.wsrf.bf2.BaseFaultType;
44 import org.oasisOpen.docs.wsrf.bf2.BaseFaultType.Description;
45 import org.ogf.graap.wsag.api.WsagConstants;
46
47
48
49
50
51
52 public class NegotiationException extends WSAgreementException
53 {
54
55
56
57 public static final String LOCAL_EN = "en";
58
59
60
61
62 private static final String DESCRIPTION_MESSAGE = "{0}: {1}";
63
64
65
66
67 private static final String CAUSE_MESSAGE = "Caused by {0}: {1}";
68
69
70
71
72 private static final String STACKTRACE_MESSAGE = "\tat {0}";
73
74
75
76
77 private final Calendar timestamp = new GregorianCalendar();
78
79 private static final long serialVersionUID = 1L;
80
81
82
83
84 public NegotiationException()
85 {
86 super();
87 }
88
89
90
91
92
93
94
95 public NegotiationException( String message, Throwable cause )
96 {
97 super( message, cause );
98 }
99
100
101
102
103
104 public NegotiationException( String message )
105 {
106 super( message );
107 }
108
109
110
111
112
113 public NegotiationException( Throwable cause )
114 {
115 super( cause );
116 }
117
118
119
120
121 public BaseFaultType getBaseFault()
122 {
123 BaseFaultDocument baseFaultDocument = BaseFaultDocument.Factory.newInstance();
124 BaseFaultType baseFault = baseFaultDocument.addNewBaseFault();
125
126 baseFault.addNewErrorCode();
127 baseFault.getErrorCode().setDialect( WsagConstants.WSAG4J_NAMESPACE );
128 baseFault.getErrorCode().set( XmlString.Factory.newValue( Integer.toString( getErrorCode() ) ) );
129
130 baseFault.setTimestamp( timestamp );
131
132 Description description = baseFault.addNewDescription();
133 description.setLang( LOCAL_EN );
134 description.setStringValue( MessageFormat.format( DESCRIPTION_MESSAGE, new Object[] {
135 this.getClass().getName(), getMessage() } ) );
136
137 StackTraceElement[] stackTrace = getStackTrace();
138 for ( int i = 0; i < stackTrace.length; i++ )
139 {
140 description = baseFault.addNewDescription();
141 description.setLang( LOCAL_EN );
142 description.setStringValue( MessageFormat.format( STACKTRACE_MESSAGE,
143 new Object[] { stackTrace[i] } ) );
144 }
145
146 if ( getCause() != null )
147 {
148 description = baseFault.addNewDescription();
149 description.setLang( LOCAL_EN );
150 description.setStringValue( MessageFormat.format( CAUSE_MESSAGE, new Object[] {
151 getCause().getClass().getName(), getCause().getMessage() } ) );
152 }
153
154 return baseFault;
155 }
156
157
158
159
160
161
162 @Override
163 public int getErrorCode()
164 {
165 return NEGOTIATION_ERROR;
166 }
167 }