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