1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts;
20
21 import java.util.Collections;
22 import java.util.Map;
23
24 import javax.servlet.http.HttpServletResponse;
25
26 import org.springframework.extensions.surf.exception.PlatformRuntimeException;
27
28
29
30
31
32
33 public class WebScriptException extends PlatformRuntimeException implements StatusTemplateFactory
34 {
35 private static final long serialVersionUID = -7338963365877285084L;
36
37 private int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
38 private StatusTemplateFactory statusTemplateFactory;
39
40
41 public WebScriptException(String msgId)
42 {
43 super(msgId);
44 }
45
46 public WebScriptException(int status, String msgId)
47 {
48 this(msgId);
49 this.status = status;
50 }
51
52 public WebScriptException(String msgId, Throwable cause)
53 {
54 super(msgId, cause);
55 }
56
57 public WebScriptException(int status, String msgId, Throwable cause)
58 {
59 super(msgId, cause);
60 this.status = status;
61 }
62
63 public WebScriptException(String msgId, Object ... args)
64 {
65 super(msgId, args);
66 }
67
68 public WebScriptException(int status, String msgId, Object ... args)
69 {
70 super(msgId, args);
71 this.status = status;
72 }
73
74 public WebScriptException(String msgId, Throwable cause, Object ... args)
75 {
76 super(msgId, args, cause);
77 }
78
79 public WebScriptException(int status, String msgId, Throwable cause, Object ... args)
80 {
81 super(msgId, args, cause);
82 this.status = status;
83 }
84
85
86
87
88
89
90
91
92 public void setStatusTemplate(final StatusTemplate statusTemplate, final Map<String, Object> statusModel)
93 {
94 setStatusTemplateFactory(new StatusTemplateFactory()
95 {
96
97 public Map<String, Object> getStatusModel()
98 {
99 return statusModel;
100 }
101
102 public StatusTemplate getStatusTemplate()
103 {
104 return statusTemplate;
105 }
106 });
107 }
108
109
110
111
112
113
114
115
116
117 public void setStatusTemplateFactory(StatusTemplateFactory statusTemplateFactory)
118 {
119 this.statusTemplateFactory = statusTemplateFactory;
120 }
121
122
123
124
125
126
127 public int getStatus()
128 {
129 return status;
130 }
131
132
133
134
135
136
137 public StatusTemplate getStatusTemplate()
138 {
139 return this.statusTemplateFactory == null ? null : this.statusTemplateFactory.getStatusTemplate();
140 }
141
142
143
144
145
146
147 public Map<String, Object> getStatusModel()
148 {
149 Map <String,Object> statusModel = null;
150 if (this.statusTemplateFactory != null)
151 {
152 statusModel = this.statusTemplateFactory.getStatusModel();
153 }
154 return statusModel == null ? Collections.<String, Object> emptyMap() : statusModel;
155 }
156
157 }