001: /**
002: *
003: */package nl.hippo.cms.wizard.components;
004:
005: import java.util.Iterator;
006: import java.util.LinkedHashMap;
007: import java.util.Map;
008:
009: import nl.hippo.cms.wizard.WizardResult;
010:
011: import org.springframework.web.context.WebApplicationContext;
012:
013: /**
014: * @author a.bogaart@hippo.nl
015: *
016: */
017: public abstract class AbstractComponentContainer extends
018: AbstractComponent implements ComponentContainer {
019:
020: protected Map components;
021: protected String currentComponent = "";
022:
023: /**
024: * @param id
025: */
026: public AbstractComponentContainer() {
027: super ();
028: components = new LinkedHashMap();
029: }
030:
031: /* (non-Javadoc)
032: * @see nl.hippo.cms.wizard.ComponentContainer#addComponent(nl.hippo.cms.wizard.Component)
033: */
034: public void addComponent(Component component) {
035: components.put(component.getId(), component);
036: }
037:
038: /* (non-Javadoc)
039: * @see nl.hippo.cms.wizard.ComponentContainer#getComponents()
040: */
041: public Map getComponents() {
042: return components;
043: }
044:
045: /* (non-Javadoc)
046: * @see nl.hippo.cms.wizard.ComponentContainer#getCurrentComponent()
047: */
048: public Component getCurrentComponent() {
049: return (Component) components.get(getCurrent());
050: }
051:
052: /* (non-Javadoc)
053: * @see nl.hippo.cms.wizard.components.ComponentContainer#getCurrent()
054: */
055: public String getCurrent() {
056: return currentComponent;
057: }
058:
059: /* (non-Javadoc)
060: * @see nl.hippo.cms.wizard.components.ComponentContainer#setCurrent(java.lang.String)
061: */
062: public void setCurrent(String id) {
063: currentComponent = id;
064: }
065:
066: //@Override
067: public void reset() {
068: setCurrent("");
069: Iterator it = components.values().iterator();
070: while (it.hasNext()) {
071: Component comp = (Component) it.next();
072: comp.reset();
073: }
074: }
075:
076: //@Override
077: public void fillResult(WizardResult result,
078: WebApplicationContext context) throws Exception {
079: super .fillResult(result, context);
080:
081: Component component = getCurrentComponent();
082: if (component != null
083: && component instanceof ComponentContainer) {
084: component.fillResult(result, context);
085: } else {
086: Iterator it = components.values().iterator();
087: while (it.hasNext()) {
088: Component comp = (Component) it.next();
089: comp.fillResult(result, context);
090: }
091: }
092: }
093:
094: public Component getComponentById(String id) {
095: return (Component) getComponents().get(id);
096: }
097:
098: public Component findComponentById(String id) {
099: if (getComponentById(id) != null) {
100: return getComponentById(id);
101: } else {
102: Iterator it = components.values().iterator();
103: while (it.hasNext()) {
104: Component component = (Component) it.next();
105: if (component instanceof ComponentContainer) {
106: Component componentFound = ((ComponentContainer) component)
107: .findComponentById(id);
108: if (componentFound != null) {
109: return componentFound;
110: }
111: }
112: }
113: }
114: return null;
115: }
116:
117: }
|