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

import java.io.IOException;

import cdac.medinfo.sdk.dcm30_04.commoninterface.IDicomStream;
import cdac.medinfo.sdk.dcm30_04.enums.EnumItemType;




/**
 * This Class represents the TransferSyntaxItem.
 */
public class TransferSyntaxItem extends AssociationItem 
{


	/** The string value of transfer syntax name. */
	String strTSName;

	/**
	 * Instantiates a new transfer syntax item.
	 */
	public TransferSyntaxItem() 
	{
		super(EnumItemType.TRANSFER_SYNTAX_ITEM.getValue());
	}

	/**
	 * Gets the Transfer syntax name.
	 * @return String - the Transfer Syntax name
	 */
	public String getTSName() 
	{
		return strTSName;
	}

	/**
	 * Sets the Transfer Syntax name.
	 * @param strTSName String value of Transfer Syntax.
	 */
	public void setTSName(String strTSName)
	{
		this.strTSName = strTSName;
	}

	/**
	 * This method returns the short value of Transfer Syntax Item.
	 * @return short Short value of Transfer Syntax Item.
	 */
	public short getItemLength() 
	{
		if(strTSName != null)
			return (short)strTSName.length();
		return 0;
	}

	/**
	 * This method parses the Dicom Stream containing Transfer syntax item.
	 * @param objIDicomStream the dicom stream containing Dicom Data.
	 * @throws IOException  Signals that an I/O exception has occurred.
	 */
	public void parse(IDicomStream objIDicomStream)throws IOException
	{
		super.parse(objIDicomStream);
		short shItemLength = objIDicomStream.readShort();
		strTSName = objIDicomStream.readString(shItemLength);
	}

	/**
	 * This method writes the Data Value to the given Stream.
	 * @param objIDicomStream object of the stream onto which the Transfer Syntax Item is to be  written.
	 * @throws IOException Signals IOException if IO Operation fails.
	 */
	public void serialize(IDicomStream objIDicomStream) throws IOException
	{
		super.serialize(objIDicomStream);
		objIDicomStream.writeShort(getItemLength());
		objIDicomStream.writeString(strTSName);
	}

	/**
	 * This method Populate Transfer Syntax Item.
	 * @param strTSname String value of transfer syntax name.
	 */
	public void populate(String strTSname)
	{
		this.strTSName = strTSname;
	}
}
