01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
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: */
16: package de.odysseus.calyxo.control.base;
17:
18: import javax.servlet.ServletContext;
19: import javax.servlet.ServletException;
20: import javax.servlet.http.HttpServletRequest;
21:
22: import de.odysseus.calyxo.base.ModuleGroup;
23: import de.odysseus.calyxo.base.ModuleContext;
24: import de.odysseus.calyxo.base.ModuleSelector;
25: import de.odysseus.calyxo.base.ModuleSupport;
26:
27: /**
28: * Module group to collect instances of {@link de.odysseus.calyxo.control.base.ControlModuleContext}.
29: *
30: * @author Christoph Beck
31: */
32: public final class ControlModuleGroup extends ModuleGroup {
33: private static final String MODULE_CONTAINER_KEY = "de.odysseus.calyxo.control.module.container";
34: private static final String MODULE_CONTEXT_KEY = "de.odysseus.calyxo.control.module.context";
35:
36: /**
37: * Loookup module container instance
38: */
39: public static final ControlModuleGroup getInstance(
40: ServletContext context) {
41: ControlModuleGroup result = (ControlModuleGroup) context
42: .getAttribute(MODULE_CONTAINER_KEY);
43: if (result == null) {
44: result = new ControlModuleGroup(ModuleSupport
45: .getInstance(context));
46: context.setAttribute(MODULE_CONTAINER_KEY, result);
47: }
48: return result;
49: }
50:
51: private ControlModuleGroup(ModuleSupport support) {
52: super (support);
53: }
54:
55: protected ModuleSelector extend(final ModuleSelector delegate) {
56: return new ModuleSelector() {
57: public ModuleContext getModuleContext(
58: HttpServletRequest request) {
59: ModuleContext result = delegate
60: .getModuleContext(request);
61: if (result == null) {
62: result = (ModuleContext) request
63: .getAttribute(MODULE_CONTEXT_KEY);
64: }
65: return result;
66: }
67: };
68: }
69:
70: public void setControlModuleContext(HttpServletRequest request,
71: ControlModuleContext module) {
72: request.setAttribute(MODULE_CONTEXT_KEY, module);
73: }
74:
75: public ControlModuleContext getControlModuleContext(String name) {
76: return (ControlModuleContext) getModuleContext(name);
77: }
78:
79: public void add(ControlModuleContext context)
80: throws ServletException {
81: super .add(context);
82: }
83:
84: public void remove(ControlModuleContext context) {
85: super.remove(context);
86: }
87: }
|