/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (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.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2001-02 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.core.internals;

import com.silverwrist.venice.except.AccessError;
import com.silverwrist.venice.security.Role;
import com.silverwrist.venice.security.SecurityMonitor;

public class EnvConference extends EnvCommunity
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private ConferenceBackend conf;
  private SecurityMonitor sm;

  /*--------------------------------------------------------------------------------
   * Constructors
   *--------------------------------------------------------------------------------
   */

  public EnvConference(EnvCommunity parent, ConferenceBackend conf)
  {
    super(parent);
    this.conf = conf;
    this.sm = (SecurityMonitor)(getGlobalSite().queryService(SecurityMonitor.class,"Conference"));

  } // end constructor

  protected EnvConference(EnvConference other)
  {
    super(other);
    this.conf = other.conf;
    this.sm = other.sm;

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Overrides from class EnvEngine
   *--------------------------------------------------------------------------------
   */

  protected SecurityMonitor getStaticMonitor()
  {
    return sm;

  } // end getStaticMonitor

  /*--------------------------------------------------------------------------------
   * Overrides from class EnvCommunity
   *--------------------------------------------------------------------------------
   */

  public boolean testPermission(String symbol, String errormsg) throws AccessError
  {
    SecurityMonitor sm = getStaticMonitor();
    // TODO: test dynamic permissions
    if (sm.testPermission(symbol,conf.env_getConfLevel(),errormsg))
      return true;
    return super.testPermission(symbol,errormsg);

  } // end testPermission

  public boolean testPermission(String symbol)
  {
    SecurityMonitor sm = getStaticMonitor();
    // TODO: test dynamic permissions
    if (sm.testPermission(symbol,conf.env_getConfLevel()))
      return true;
    return super.testPermission(symbol);

  } // end testPermission

  public boolean satisfy(Role role)
  {
    return role.isSatisfiedBy(conf.env_getConfLevel());

  } // end satisfy

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  public final ConferenceBackend getConference()
  {
    return conf;

  } // end getConference

  public final int getConfID()
  {
    return conf.realConfID();

  } // end getConfID

  public final String getConferenceAlias()
  {
    return conf.realConfAlias();

  } // end getConfAlias

  public final String getConferenceName()
  {
    return conf.env_getConfName();

  } // end getConfName

} // end class EnvConference

