/*
 * Filename: Requester.java
 *
 * Author: Joe Wang
 *
 * Copyright (c) 2003-2005 
 * The Trustees of Columbia University in the City of New York
 * Columbia University Information Technology
 *
 * This file is part of NINJa.
 *
 * NINJa is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * NINJa is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with NINJa; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

package edu.columbia.print.ninja.prix.requester;

import com.millipad.util.*;
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

/**
 * A Requester will generate print requests from an arbitrary source.
 * The generated requests will be printed to one or more PrintServices.<p>
 * This interface is not well designed.  Some requesters, like the LprRequester,
 * are like filters which pull out attributes.  Other requesters, like SpoolIntercept,
 * contain multiple jobs to be passed down to other Requesters.
 * @author Joe Wang <jw168@columbia.edu>
 * @since 1.0
 */
public abstract class Requester {

	public static int REQUEST_DISPATCHED = 0;
	public static int REQUEST_FAILED = 1;

	/**
	 * Produce requests from a given file.
	 * @param in the file
	 * @param attr The current set of attributes associated with the file
	 * @param required The classes which are required to indicate that
	 *        this request is complete
	 * @return REQUEST_DISPATCHED if request was sent to print service
	 * REQUEST_FAILED if request was not sent to print service
	 */
	public abstract int produceRequest(File in, PrintRequestAttributeSet attr, Class[] required, BlockingStack result)
	throws IOException;

	/**
	 * @param service the print service that is accepting requests
	 */
	public abstract void addPrintService(net.jini.print.service.PrintService service);

	public abstract void setInputDevice(String printer);

        /**
	 * Helper function to determine if a set is missing required attributes
	 * @param set the attributeSet to check
	 * @param required the attributes that are required to be in the set
	 * @return true if the set is missing attributes, false otherwise
	 */
	boolean missing(PrintRequestAttributeSet set, Class[] required, Requester src) {
		for(int i=required.length-1; i>=0; i--) {
			if(!set.containsKey((Class )required[i])) return true;
			}
		return false;
		}
	}
