Package de.odysseus.calyxo.control.base

Source Code of de.odysseus.calyxo.control.base.ControlModuleGroup

/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.control.base;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import de.odysseus.calyxo.base.ModuleGroup;
import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.ModuleSelector;
import de.odysseus.calyxo.base.ModuleSupport;

/**
* Module group to collect instances of {@link de.odysseus.calyxo.control.base.ControlModuleContext}.
*
* @author Christoph Beck
*/
public final class ControlModuleGroup extends ModuleGroup {
  private static final String MODULE_CONTAINER_KEY = "de.odysseus.calyxo.control.module.container";
  private static final String MODULE_CONTEXT_KEY = "de.odysseus.calyxo.control.module.context";

  /**
   * Loookup module container instance
   */
  public static final ControlModuleGroup getInstance(ServletContext context) {
    ControlModuleGroup result = (ControlModuleGroup)context.getAttribute(MODULE_CONTAINER_KEY);
    if (result == null) {
      result = new ControlModuleGroup(ModuleSupport.getInstance(context));
      context.setAttribute(MODULE_CONTAINER_KEY, result);
    }
    return result;
  }

  private ControlModuleGroup(ModuleSupport support) {
    super(support);
  }
 
  protected ModuleSelector extend(final ModuleSelector delegate) {
    return new ModuleSelector() {
      public ModuleContext getModuleContext(HttpServletRequest request) {
        ModuleContext result = delegate.getModuleContext(request);
        if (result == null) {
          result = (ModuleContext)request.getAttribute(MODULE_CONTEXT_KEY);
        }
        return result;
      }
    };
  }

  public void setControlModuleContext(HttpServletRequest request, ControlModuleContext module) {
    request.setAttribute(MODULE_CONTEXT_KEY, module);
  }

  public ControlModuleContext getControlModuleContext(String name) {
    return (ControlModuleContext)getModuleContext(name);
  }

  public void add(ControlModuleContext context) throws ServletException {
    super.add(context);
  }

  public void remove(ControlModuleContext context) {
    super.remove(context);
  }
}
TOP

Related Classes of de.odysseus.calyxo.control.base.ControlModuleGroup

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.