01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.core;
16:
17: import org.araneaframework.InputData;
18: import org.araneaframework.OutputData;
19: import org.araneaframework.Path;
20: import org.araneaframework.Service;
21: import org.araneaframework.core.util.ExceptionUtil;
22:
23: /**
24: * Non-composite service component providing the extra action(Path, InputData, OutputData)
25: * to BaseComponent.
26: *
27: * @author "Toomas Römer" <toomas@webmedia.ee>
28: */
29: public abstract class BaseService extends BaseComponent implements
30: Service {
31:
32: protected InputData currentInputData;
33: protected OutputData currentOutputData;
34:
35: public Service.Interface _getService() {
36: return new ServiceImpl();
37: }
38:
39: protected class ServiceImpl implements Service.Interface {
40: public void action(Path path, InputData input, OutputData output) {
41: Assert.notNullParam(this , input, "input");
42: Assert.notNullParam(this , output, "output");
43:
44: _startCall();
45:
46: currentInputData = input;
47: currentOutputData = output;
48: try {
49: if (isAlive()) {
50: BaseService.this .action(path, input, output);
51: }
52: } catch (Exception e) {
53: try {
54: handleServiceException(e);
55: } catch (Exception e2) {
56: ExceptionUtil.uncheckException(e2);
57: }
58: } finally {
59: currentInputData = null;
60: currentOutputData = null;
61: _endCall();
62: }
63: }
64: }
65:
66: /**
67: * Services provide their services through the action method. An implementation of a non-composite
68: * service like BaseService uses the action method to hook in the middle of the action routing and
69: * provide filtering, logging etc.
70: */
71: protected void action(Path path, InputData input, OutputData output)
72: throws Exception {
73: }
74:
75: protected void handleServiceException(Exception e) throws Exception {
76: handleException(e);
77: }
78:
79: protected InputData getInputData() {
80: return currentInputData;
81: }
82:
83: protected OutputData getOutputData() {
84: return currentOutputData;
85: }
86: }
|