1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var Args = require('@themost/common/utils').Args;
|
11 | var LangUtils = require('@themost/common/utils').LangUtils;
|
12 | var SequentialEventEmitter = require('@themost/common/emitter').SequentialEventEmitter;
|
13 | var AbstractMethodError = require('@themost/common/errors').AbstractMethodError;
|
14 | var AbstractClassError = require('@themost/common/errors').AbstractClassError;
|
15 | var Symbol = require('symbol');
|
16 | var applicationProperty = Symbol('application');
|
17 | var IApplicationService = require('@themost/common/app').IApplicationService;
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function HttpApplicationService(app) {
|
27 | if (this.constructor === HttpApplicationService.prototype.constructor) {
|
28 | throw new AbstractClassError();
|
29 | }
|
30 | Args.notNull(app, 'HTTP Application');
|
31 | this[applicationProperty] = app;
|
32 | }
|
33 | LangUtils.inherits(HttpApplicationService,IApplicationService);
|
34 |
|
35 |
|
36 |
|
37 | HttpApplicationService.prototype.getApplication = function() {
|
38 | return this[applicationProperty];
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | function HttpViewEngine(context) {
|
49 | if (this.constructor === HttpViewEngine.prototype.constructor) {
|
50 | throw new AbstractClassError();
|
51 | }
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 | |
58 |
|
59 |
|
60 | var ctx = context;
|
61 | Object.defineProperty(this,'context', {
|
62 | get: function() {
|
63 | return ctx;
|
64 | },
|
65 | set: function(value) {
|
66 | ctx = value;
|
67 | },
|
68 | configurable:false,
|
69 | enumerable:false
|
70 | });
|
71 | }
|
72 | LangUtils.inherits(HttpViewEngine, SequentialEventEmitter);
|
73 |
|
74 |
|
75 |
|
76 | HttpViewEngine.prototype.getContext = function() {
|
77 | return this.context;
|
78 | };
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | HttpViewEngine.prototype.render = function(file, data, callback) {
|
89 | throw new AbstractMethodError();
|
90 | };
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | function BeginRequestHandler() {
|
98 | if (this.constructor === BeginRequestHandler.prototype.constructor) {
|
99 | throw new AbstractClassError();
|
100 | }
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | BeginRequestHandler.prototype.beginRequest = function (context, callback) {
|
108 | callback = callback || function () { };
|
109 | return callback();
|
110 | };
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | function ValidateRequestHandler() {
|
118 | if (this.constructor === ValidateRequestHandler.prototype.constructor) {
|
119 | throw new AbstractClassError();
|
120 | }
|
121 | }
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | ValidateRequestHandler.prototype.validateRequest = function (context, callback) {
|
128 | callback = callback || function () { };
|
129 | return callback();
|
130 | };
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | function AuthenticateRequestHandler() {
|
138 | if (this.constructor === AuthenticateRequestHandler.prototype.constructor) {
|
139 | throw new AbstractClassError();
|
140 | }
|
141 | }
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | AuthenticateRequestHandler.prototype.authenticateRequest = function (context, callback) {
|
148 | callback = callback || function () { };
|
149 | return callback();
|
150 | };
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | function AuthorizeRequestHandler() {
|
158 | if (this.constructor === AuthorizeRequestHandler.prototype.constructor) {
|
159 | throw new AbstractClassError();
|
160 | }
|
161 | }
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | AuthorizeRequestHandler.prototype.authorizeRequest = function (context, callback) {
|
168 | callback = callback || function () { };
|
169 | return callback();
|
170 | };
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 | function MapRequestHandler() {
|
177 | if (this.constructor === MapRequestHandler.prototype.constructor) {
|
178 | throw new AbstractClassError();
|
179 | }
|
180 | }
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 | MapRequestHandler.prototype.mapRequest = function (context, callback) {
|
187 | callback = callback || function () { };
|
188 | return callback();
|
189 | };
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | function PostMapRequestHandler() {
|
196 | if (this.constructor === PostMapRequestHandler.prototype.constructor) {
|
197 | throw new AbstractClassError();
|
198 | }
|
199 | }
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | PostMapRequestHandler.prototype.postMapRequest = function(context, callback) {
|
207 | callback = callback || function () { };
|
208 | return callback();
|
209 | };
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | function ProcessRequestHandler() {
|
217 | if (this.constructor === ProcessRequestHandler.prototype.constructor) {
|
218 | throw new AbstractClassError();
|
219 | }
|
220 | }
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 | ProcessRequestHandler.prototype.processRequest = function (context, callback) {
|
227 | callback = callback || function () { };
|
228 | return callback();
|
229 | };
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 | function PreExecuteResultHandler() {
|
237 | if (this.constructor === PreExecuteResultHandler.prototype.constructor) {
|
238 | throw new AbstractClassError();
|
239 | }
|
240 | }
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 | PreExecuteResultHandler.prototype.preExecuteResult = function (context, callback) {
|
247 | callback = callback || function () { };
|
248 | return callback();
|
249 | };
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | function PostExecuteResultHandler() {
|
256 | if (this.constructor === PreExecuteResultHandler.prototype.constructor) {
|
257 | throw new AbstractClassError();
|
258 | }
|
259 | }
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | PostExecuteResultHandler.prototype.postExecuteResult = function (context, callback) {
|
266 | callback = callback || function () { };
|
267 | return callback();
|
268 | };
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 | function EndRequestHandler() {
|
277 | if (this.constructor === EndRequestHandler.prototype.constructor) {
|
278 | throw new AbstractClassError();
|
279 | }
|
280 | }
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 | EndRequestHandler.prototype.beginRequest = function (context, callback) {
|
287 | callback = callback || function () { };
|
288 | return callback();
|
289 | };
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | function HttpHandler() {
|
298 | if (this.constructor === HttpHandler.prototype.constructor) {
|
299 | throw new AbstractClassError();
|
300 | }
|
301 | }
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 | HttpHandler.Events = [
|
308 | 'beginRequest',
|
309 | 'validateRequest',
|
310 | 'authenticateRequest',
|
311 | 'authorizeRequest',
|
312 | 'mapRequest',
|
313 | 'postMapRequest',
|
314 | 'preExecuteResult',
|
315 | 'postExecuteResult',
|
316 | 'endRequest'
|
317 | ];
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | HttpHandler.prototype.beginRequest = function (context, callback) {
|
325 | callback = callback || function () { };
|
326 | return callback();
|
327 | };
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | HttpHandler.prototype.validateRequest = function (context, callback) {
|
335 | callback = callback || function () { };
|
336 | return callback();
|
337 | };
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 | HttpHandler.prototype.authenticateRequest = function (context, callback) {
|
345 | callback = callback || function () { };
|
346 | return callback();
|
347 | };
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 | HttpHandler.prototype.authorizeRequest = function (context, callback) {
|
366 | callback = callback || function () { };
|
367 | return callback();
|
368 | };
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 | HttpHandler.prototype.mapRequest = function (context, callback) {
|
376 | callback = callback || function () { };
|
377 | return callback();
|
378 | };
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 | HttpHandler.prototype.postMapRequest = function(context, callback) {
|
386 | callback = callback || function () { };
|
387 | return callback();
|
388 | };
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 | HttpHandler.prototype.processRequest = function (context, callback) {
|
406 | callback = callback || function () { };
|
407 | return callback();
|
408 | };
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 | HttpHandler.prototype.preExecuteResult = function (context, callback) {
|
416 | callback = callback || function () { };
|
417 | return callback();
|
418 | };
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 | HttpHandler.prototype.postExecuteResult = function (context, callback) {
|
426 | callback = callback || function () { };
|
427 | return callback();
|
428 | };
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 | HttpHandler.prototype.endRequest = function (context, callback) {
|
446 | callback = callback || function () { };
|
447 | return callback();
|
448 | };
|
449 |
|
450 |
|
451 | if (typeof exports !== 'undefined')
|
452 | {
|
453 | module.exports.HttpApplicationService = HttpApplicationService;
|
454 | module.exports.HttpViewEngine = HttpViewEngine;
|
455 | module.exports.BeginRequestHandler = BeginRequestHandler;
|
456 | module.exports.AuthenticateRequestHandler = AuthenticateRequestHandler;
|
457 | module.exports.AuthorizeRequestHandler = AuthorizeRequestHandler;
|
458 | module.exports.MapRequestHandler = MapRequestHandler;
|
459 | module.exports.PostMapRequestHandler = PostMapRequestHandler;
|
460 | module.exports.ProcessRequestHandler = ProcessRequestHandler;
|
461 | module.exports.PreExecuteResultHandler = PreExecuteResultHandler;
|
462 | module.exports.PostExecuteResultHandler = PostExecuteResultHandler;
|
463 | module.exports.EndRequestHandler = EndRequestHandler;
|
464 | module.exports.HttpHandler = HttpHandler;
|
465 | }
|
466 |
|