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.base;
17:
18: import java.util.Collections;
19: import java.util.HashMap;
20: import java.util.Set;
21:
22: import javax.servlet.ServletException;
23:
24: /**
25: * Module grouü base class.
26: * A single instance of this class is used to collect modules of a specific kind,
27: * e.g. "Calyxo Control" or "Calyxo Struts" modules. The modules are automatically
28: * added to the global {@link de.odysseus.calyxo.base.ModuleSupport} instance whose
29: * {@link de.odysseus.calyxo.base.ModuleSelector} is extended to be able to identify
30: * modules from this module group, too.
31: *
32: * @see de.odysseus.calyxo.base.ModuleContext
33: * @see de.odysseus.calyxo.base.ModuleSupport
34: *
35: * @author Christoph Beck
36: */
37: public abstract class ModuleGroup {
38: private HashMap modules = new HashMap();
39: private ModuleSupport support;
40:
41: protected ModuleGroup(ModuleSupport support) {
42: this .support = support;
43:
44: support.setModuleSelector(extend(support.getModuleSelector()));
45: }
46:
47: /**
48: * Lookup a module context by name.
49: */
50: protected final ModuleContext getModuleContext(String name) {
51: return (ModuleContext) modules.get(name);
52: }
53:
54: /**
55: * Answer <code>true</code> iff there are no modules
56: */
57: public final boolean isEmpty() {
58: return modules.isEmpty();
59: }
60:
61: /**
62: * Answer an unmodifiable set containing the module names
63: */
64: public final Set getModuleNames() {
65: return Collections.unmodifiableSet(modules.keySet());
66: }
67:
68: /**
69: * Add a module context
70: */
71: protected void add(ModuleContext context) throws ServletException {
72: support.add(context);
73: modules.put(context.getName(), context);
74: }
75:
76: /**
77: * Remove a module context
78: */
79: protected void remove(ModuleContext context) {
80: support.remove(context);
81: modules.remove(context.getName());
82: }
83:
84: /**
85: * Answer module selector "extending" the specified selector and being capable of
86: * selecing modules from this container.
87: */
88: protected abstract ModuleSelector extend(ModuleSelector delegate);
89: }
|