/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * 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 cdac.medinfo.sdk.dcm30_04.services.print.testcases.customizedscp;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataElement;
import cdac.medinfo.sdk.dcm30_04.commoninterface.IDataSet;
import cdac.medinfo.sdk.dcm30_04.services.dicomnetcommons.IPrinterHadler;
import cdac.medinfo.sdk.dcm30_04.utils.ICollectionIterator;
import cdac.medinfo.sdk.dcm30_04.utils.ISingleCollection;

/**
 * IPrintHandler is used for getting the created Stored Print IOD and Hard Copy Grayscale or Color IOD (which are abstraction for
 * Printer). The implementor of this class gets the Stored Print IOD and the HardCopy Grayscale or Color IOD
 * which then can be used to print the image information.
 * When N-Action request for Print Management Service arrives at SCP , it then creates the Stored Print IOD and
 * the HardCopy grayscale Image IOD and then receiveDataSetForPrint() Function of Print Handler Class is called.
 * To receive the Stored Print and HardCopy Grayscale or Color Image information , IPrintHandler should be 
 * added to PrintDataSourceImpl for receiving the datasets.
 * This class implements IPrinterHadler to receive Stored Print IOD and Hard Copy GrayScale Image IOD.
 */
public class PrintHandler implements IPrinterHadler
{
	/**
	 * This function receives the Stored Print IOD and Hard Copy Grayscale or Color IOD (which are abstraction for
	 * Printer). The implementor of this class gets the Stored Print IOD and the HardCopy Grayscale or Color IOD
	 * which then can be used to print the image information.
	 * When N-Action request for Print Management Service arrives at SCP , it then creates the Stored Print IOD and
	 * the HardCopy grayscale Image IOD and then receiveDataSetForPrint Function of Print handler Class is called.
	 * To receive the Stored Print and HardCopy Grayscale or Color Image information , IPrintHandler should be 
	 * added to PrintDataSourceImpl for receiving the datasets.
	 * This will print the data sets received.
	 * @param objIDataSetCollection DataSet collection containg Stored Print IO and HardCopy Grayscale IOD.
	 */
	public void receiveDataSetForPrint(ISingleCollection<IDataSet> objDataSetCollection)
	{
		for(IDataSet objIDataSet : objDataSetCollection)
		{
			display(objIDataSet.iterator());
		}
	}

	/*
	 * Displays the DataElements of given Collection Iterator.
	 */
	private void display(ICollectionIterator<IDataElement> objIterator)
	{
		int iGroupNumber = 0;
		int iElementNumber = 0;
		System.out.println("Group Number"+"\t\t"+"Element Number");
		while(objIterator.hasNext())
		{
			IDataElement objIDataElement = objIterator.next();
			iGroupNumber = objIDataElement.getTag().getGroupNumber();
			iElementNumber = objIDataElement.getTag().getElementNumber();
			System.out.println( Integer.toHexString(iGroupNumber) +"\t\t"+ Integer.toHexString(iElementNumber) );
		}
	}
}
