/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   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 org.bodington.server.realm;

import org.bodington.server.*;
import org.bodington.sqldatabase.*;
import org.bodington.database.*;
import java.util.Enumeration;


/**
 * This class represents a zone of user administration.  Certain users will be allowed to
 * create users and aliases but only within their own zone.  The code for this user management
 * isn't written so zones seem a little redundant at present.
 * 
 * @author Jon Maber
 * @version 1.0
 */
public class Zone extends org.bodington.sqldatabase.SqlPersistentObject
	{

	/**
	 * The primary key of the zone.
	 */
	private PrimaryKey zone_id;

	/**
	 * A prefix suggested for naming objects associated with this zone.
	 * (E.g. user names)
	 */
	private String prefix;

	/**
	 * The full name of the zone.
	 */
	private String name;
	
	public static Zone findZone( PrimaryKey key )
	    throws BuildingServerException
	    {
	    return (Zone)findPersistentObject( key, "org.bodington.server.realm.Zone" );
	    }
	
	public static Zone findZone( String where )
	    throws BuildingServerException
	    {
	    return (Zone)findPersistentObject( where, "org.bodington.server.realm.Zone" );
	    }
    
    public static Zone findZoneByPrefix( String prefix )
        throws BuildingServerException
        {
        return (Zone) findPersistentObject("prefix = "
            + SqlDatabase.quotedSQL(prefix), "org.bodington.server.realm.Zone");
        }
	
	public static Enumeration findZones( String where )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, "org.bodington.server.realm.Zone" );
	    }
	

    public void setPrimaryKey(PrimaryKey key)
    	{
        setZoneId( key );
    	}

    public PrimaryKey getPrimaryKey()
    	{
        return getZoneId();
	    }


    public void setZoneId(PrimaryKey key)
    	{
        zone_id=key;
    	setUnsaved();
    	}

    public PrimaryKey getZoneId()
    	{
        return zone_id;
	    }

	
    public void setPrefix( String p )
    	{
        prefix = p;
    	setUnsaved();
    	}

    public String getPrefix()
    	{
        return prefix;
	    }
	
    public void setName( String n )
    	{
        name =n;
    	setUnsaved();
    	}

    public String getName()
    	{
        return name;
	    }
	
	}
