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.container;
16:
17: import org.apache.commons.logging.Log;
18: import org.apache.commons.logging.LogFactory;
19: import org.araneaframework.InputData;
20: import org.araneaframework.OutputData;
21: import org.araneaframework.Path;
22: import org.araneaframework.core.StandardPath;
23: import org.araneaframework.framework.core.BaseFilterService;
24:
25: /**
26: * A service that contains a service and routes actions to it. If
27: * <code>hasAction(InputData)</code> returns true, the action is routed to the child, otherwise
28: * not.
29: *
30: * @author "Toomas Römer" <toomas@webmedia.ee>
31: */
32: public class StandardContainerService extends BaseFilterService {
33: //*******************************************************************
34: // CONSTANTS
35: //*******************************************************************
36: private static final Log log = LogFactory
37: .getLog(StandardContainerService.class);
38: /**
39: * The key of the action path parameter in the request.
40: */
41: public static final String ACTION_PATH_INPUT_DATA_PARAMETER = "serviceActionId";
42:
43: /**
44: * Returns the path of action from the InputData. Uses the ACTION_PATH_INPUT_DATA_PARAMETER
45: * to get the path.
46: */
47: protected Path getActionPath(InputData input) {
48: return new StandardPath((String) input.getGlobalData().get(
49: ACTION_PATH_INPUT_DATA_PARAMETER));
50: }
51:
52: /**
53: * Determines if the request contains an action. Checks if the ACTION_PATH_INPUT_DATA_PARAMETER
54: * is set in the request.
55: */
56: protected boolean hasAction(InputData input) {
57: return input.getGlobalData().get(
58: ACTION_PATH_INPUT_DATA_PARAMETER) != null;
59: }
60:
61: protected void action(Path path, InputData input, OutputData output)
62: throws Exception {
63: if (hasAction(input)) {
64: Path actionPath = getActionPath(input);
65: log.debug("Routing action to service '"
66: + actionPath.toString() + "'");
67: super.action(actionPath, input, output);
68: }
69: }
70: }
|