/*
 * Filename: Lookup.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
 *
 * Created on May 8, 2002, 11:44 AM
 */

package edu.columbia.print.ninja.core.service;

import java.util.*;
import javax.print.DocFlavor;
import javax.print.attribute.AttributeSet;
import net.jini.print.service.PrintService;

/**
 *
 * @author  joe
 */
public class Lookup {

	Vector lookups;
	/** Creates a new instance of Lookup */
	public Lookup() {
		lookups = new Vector();
	}
	
	public RemotePrintService getDefaultPrintService() {
		for(Iterator i=lookups.iterator(); i.hasNext();) {
			Lookup lookup = (Lookup )i.next();
			RemotePrintService ps = lookup.getDefaultPrintService();
			if(ps!=null) return ps;
		}
		return null;
	}
	
	public net.jini.print.service.MultiDocPrintService[] getMultiDocPrintServices(DocFlavor[] docFlavor, AttributeSet attributeSet) {
		return null;
	}
	
	public RemotePrintService[] getPrintServices() {
		//get the sizes
		int total = 0;
		for(Iterator i=lookups.iterator(); i.hasNext();) {
			Lookup lookup = (Lookup )i.next();
			PrintService[] ps = lookup.getPrintServices();
			if(ps!=null) total += ps.length;
		}
		if(total==0) return null;
		RemotePrintService[] pss = new RemotePrintService[total];
		total = 0;
		for(Iterator i=lookups.iterator(); i.hasNext();) {
			Lookup lookup = (Lookup )i.next();
			PrintService[] ps = lookup.getPrintServices();
			if(ps==null) continue;
			System.arraycopy(ps, 0, pss, total, ps.length);
			total += ps.length;
		}
		return pss;
	}
	
	public RemotePrintService[] getPrintServices(DocFlavor docFlavor, AttributeSet attributeSet) {
		return null;
	}

	public boolean registerServiceProvider(Lookup sp) {
		if(lookups.contains(sp)) return false;
		lookups.add(sp);
		return true;
		}

}
