Package de.odysseus.calyxo.base.access

Source Code of de.odysseus.calyxo.base.access.AccessSupport

/*
* 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.base.access;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;

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

/**
* Access support class. There is one instance per module,
* which may be retreived via the <code>getInstance()</code>
* methods.
* This class encapsulates an accessor Map, which may be accessed and
* extended during module initialization.
* @author Christoph Beck
*/
public class AccessSupport {

  /**
   * Module scope key where the access support instance is stored.
   */
  public static final String ACCESS_SUPPORT_KEY = "de.calyxo.base.access";

  /**
   * Lookup access support for module determined by specified request
   */
  public static final AccessSupport getInstance(HttpServletRequest request) {
    ModuleContext context =
      ModuleSupport.getInstance(request).getModuleContext(request);
    return (AccessSupport)context.getAttribute(ACCESS_SUPPORT_KEY);
  }

  /**
   * Convenience method.
   * @see #getInstance(HttpServletRequest)
   */
  public static final AccessSupport getInstance(PageContext pageContext) {
    return getInstance((HttpServletRequest)pageContext.getRequest());
  }

  /**
   * Lookup access support for specified module
   */
  public static final AccessSupport getInstance(ModuleContext context) {
    return (AccessSupport)context.getAttribute(ACCESS_SUPPORT_KEY);
  }

  private AccessorMap accessors;

  /**
   * Default constructor.
   * Uses an empty <code>AccessorMap</code>.
   */
  public AccessSupport() {
    this(new AccessorMap());
  }

  /**
   * Constructor.
   * The passed map may already contain some accessors.
   *
   * @param accessors the map of accessors.
   */
  public AccessSupport(AccessorMap accessors) {
    super();
   
    this.accessors = accessors;
  }

  /**
   * Get accessor for specified key
   */
  public Accessor get(String key) {
    return accessors.get(key);
  }

  /**
   * Put accessor for specified key
   */
  public void put(String key, Accessor value) {
    accessors.put(key, value);
  }

  /**
   * Create object (map) from our encapsulated accessor map.
   */
  public Object create(HttpServletRequest request) {
    return accessors.get(request);
  }
}
TOP

Related Classes of de.odysseus.calyxo.base.access.AccessSupport

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.