/*
 * 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) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.security;

import java.security.acl.AclNotFoundException;
import java.util.*;
import com.silverwrist.dynamo.db.OpsBase;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.util.PropertyKey;

abstract class SRMOperations extends OpsBase
{
  /*--------------------------------------------------------------------------------
   * Static data members
   *--------------------------------------------------------------------------------
   */

  public static final String HMKEY_ACLID = "aclid";
  public static final String HMKEY_ACLNAME = "aclname";
  public static final String HMKEY_ACEID = "aceid";
  public static final String HMKEY_PRINCIPAL = "principal";
  public static final String HMKEY_NEGATIVE = "negative";

  public static final int NDX_ADMIN_UID = 0;
  public static final int NDX_ADMIN_GID = 1;
  public static final int NDX_GLOBAL_ACLID = 2;
  public static final int NDX_ALL_GID = 3;
  public static final int NDX_VERIFIED_GID = 4;

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  protected SRMOperations(DBConnectionPool pool)
  {
    super(pool);

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Overrides from class OpsBase
   *--------------------------------------------------------------------------------
   */

  public void dispose()
  {
    super.dispose();

  } // end dispose

  /*--------------------------------------------------------------------------------
   * Abstract operations
   *--------------------------------------------------------------------------------
   */

  abstract AclOperations getAclOperations();

  abstract AceOperations getAceOperations();

  abstract Map getAclData(int aclid) throws DatabaseException, AclNotFoundException;

  abstract Map createAcl(String name, int owner_id, boolean owner_group) throws DatabaseException;

  abstract Map getAceData(int aceid) throws DatabaseException;

  abstract int createAce() throws DatabaseException;

  abstract int[] getGlobalSecurityData() throws DatabaseException;

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

  boolean testUserPermission(int aclid, int uid, PropertyKey perm) throws DatabaseException
  {
    return getAclOperations().testUserPermission(aclid,uid,perm);

  } // end testUserPermission

  boolean testAclOwner(int aclid, PrincipalID owner) throws DatabaseException
  {
    return getAclOperations().testOwner(aclid,owner);

  } // end testAclOwner

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

  static SRMOperations get(DBConnectionPool pool) throws ConfigException
  {
    return (SRMOperations)get(pool,SRMOperations.class.getClassLoader(),
			      SRMOperations.class.getName() + "_","SRMOperations");

  } // end get

} // end class SRMOperations
