/* ======================================================================
   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.assessment;

import java.sql.Timestamp;
import java.util.Enumeration;
import java.util.Vector;
import java.math.BigDecimal;

import org.bodington.database.*;
import org.bodington.server.*;
import org.bodington.server.resources.*;
import org.bodington.text.BigString;

public class TextQPaper extends org.bodington.server.resources.Resource
	{
	
    public static final int UNSET = -1;
    
	private PrimaryKey textq_paper_id;
	private PrimaryKey general_notes_big_string_id;
	private int general_available = UNSET;
	private BigDecimal general_weight;
	private int maximum_mark = UNSET;
	private Timestamp date_open;
	private Timestamp date_deadline;
	private Timestamp date_penalty;
	
	private Vector questionsinorder;
	
	
    public Class sessionClass()
    	{
        // This method is derived from class org.bodington.server.resources.Resource
        // to do: code goes here
        return org.bodington.assessment.TextQSessionImpl.class;
    	}
    	

   	public static TextQPaper findTextQPaper( PrimaryKey key )
		throws BuildingServerException
		{
		return (TextQPaper)findPersistentObject( key, "org.bodington.assessment.TextQPaper" );
		}
	public static Enumeration findTextQPapers( String where )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, "org.bodington.assessment.TextQPaper" );
	    }
	public static Enumeration findTextQPapers( String where, String order )
	    throws BuildingServerException
	    {
	    return findPersistentObjects( where, order, "org.bodington.assessment.TextQPaper" );
	    }
	    
	    
	    


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

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

    public PrimaryKey getTextQPaperId()
		{
        return textq_paper_id;
        }

    public void setTextQPaperId(PrimaryKey key)
    	{
    	textq_paper_id = key;
    	setResourceId( key );
    	setUnsaved();
    	}
    	
    	
	public PrimaryKey getGeneralNotesBigStringId()
		{
		return general_notes_big_string_id;
		}

	public void setGeneralNotesBigStringId( PrimaryKey id )
		{
		general_notes_big_string_id = id;
		setUnsaved();
		}
		
	public String getGeneralNotes()
		throws BuildingServerException
		{
		if ( general_notes_big_string_id == null )
			return null;
		BigString bstr = BigString.findBigString( general_notes_big_string_id );
		if ( bstr == null )
			return null;
		return bstr.getString();
		}
		
	public void setGeneralNotes( String s )
		throws BuildingServerException
		{
		BigString bstr=null;
		if ( general_notes_big_string_id != null )
			bstr = BigString.findBigString( general_notes_big_string_id );
		if ( bstr == null )
			{
			bstr = new BigString();
			bstr.setString( s );
			bstr.save();
			general_notes_big_string_id = bstr.getBigStringId();
			setUnsaved();
			return;
			}

		bstr.setString( s );
		bstr.save();
		}
	
		



	public int getGeneralAvailable()
		{
		return general_available;
		}
    	
    	
    public void setGeneralAvailable( int n )
    	{
    	general_available = n;
		setUnsaved();
    	}
    	
	public BigDecimal getGeneralWeight()
		{
		return general_weight;
		}
		
	public void setGeneralWeight( BigDecimal w )
		{
		if ( general_weight==null && w == null )
			return;
		if ( general_weight!=null && w!=null && general_weight.equals(w) )
			return;
		general_weight = w;
		setUnsaved();
		}
		
		
	public int getMaximumMark()
		{
		return maximum_mark;
		}
    	
    	
    public void setMaximumMark( int n )
    	{
    	maximum_mark = n;
		setUnsaved();
    	}
    	
    	

	public Timestamp getDateOpen()
		{
		return date_open;
		}
		
	public void setDateOpen( Timestamp t )
		{
		if ( date_open==null && t==null )
			return;
		if ( date_open!=null && t != null )
			if ( date_open.equals( t ) )
				return;
		date_open= t;
		setUnsaved();
		}

	public Timestamp getDateDeadline()
		{
		return date_deadline;
		}
		
	public void setDateDeadline( Timestamp t )
		{
		if ( date_deadline==null && t==null )
			return;
		if ( date_deadline!=null && t != null )
			if ( date_deadline.equals( t ) )
				return;
		date_deadline = t;
		setUnsaved();
		}
		

	public Timestamp getDatePenalty()
		{
		return date_penalty;
		}
		
	public void setDatePenalty( Timestamp t )
		{
		if ( date_penalty==null && t==null )
			return;
		if ( date_penalty!=null && t != null )
			if ( date_penalty.equals( t ) )
				return;
		date_penalty = t;
		setUnsaved();
		}
		
		
		
		
	public Enumeration getQuestions()
		{
		return null;
		}

	public TextQuestion getQuestionAt( int n )
		{
		return null;
		}
		
	public TextQuestion createQuestion()
		{
		return null;
		}

	public void removeQuestion( TextQuestion q )
		{
		}


    public int getResourceType()
    	{
    	return RESOURCE_TEXTQ;
    	}
	}
