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.framework.core;
16:
17: import org.araneaframework.Environment;
18: import org.araneaframework.InputData;
19: import org.araneaframework.Message;
20: import org.araneaframework.OutputData;
21: import org.araneaframework.Path;
22: import org.araneaframework.Service;
23: import org.araneaframework.core.Assert;
24: import org.araneaframework.core.BaseService;
25: import org.araneaframework.framework.FilterService;
26:
27: /**
28: * A filter service is a Service which filters requests to its child service. A filter
29: * overrides one of the methods:
30: * <ul>
31: * <li><code>action(Path, InputData, OutputData)</code></li>
32: * </ul>
33: * and does the filtering by allowing the action to be invoked on the child or not. This class is a
34: * skeleton which lets all the requests through, sets the child, handles the initilization and
35: * destroying of the child.
36: * <p>
37: * The child is initilized with <code>getChildServiceEnvironment()</code> which by default returns
38: * this component's Environment. For alternate environments it should be overridden.
39: * </p>
40: *
41: * @author "Toomas Römer" <toomas@webmedia.ee>
42: */
43: public class BaseFilterService extends BaseService implements
44: FilterService {
45: protected Service childService;
46:
47: public BaseFilterService() {
48: }
49:
50: public BaseFilterService(Service childService) {
51: setChildService(childService);
52: }
53:
54: /**
55: * Sets the child service.
56: * @param childService
57: */
58: public void setChildService(Service childService) {
59: this .childService = childService;
60: }
61:
62: protected void init() throws Exception {
63: Assert.notNull(this , childService,
64: "Filter cannot have a null child!");
65:
66: childService._getComponent().init(getScope(),
67: getChildEnvironment());
68: }
69:
70: protected void action(Path path, InputData input, OutputData output)
71: throws Exception {
72: this .childService._getService().action(path, input, output);
73: }
74:
75: protected void propagate(Message message) throws Exception {
76: message.send(null, childService);
77: }
78:
79: protected void destroy() throws Exception {
80: childService._getComponent().destroy();
81: }
82:
83: /**
84: * Returns the Environment of this service by default. The child
85: * is initilized with this method. Meant for overriding.
86: */
87: protected Environment getChildEnvironment() {
88: return getEnvironment();
89: }
90: }
|