/*
#=======================================================================================================
#
#                   Copyright (c) 2007 Origin Enterprise Solution LTD.
#
#=======================================================================================================
# File description:  GetAllDataSetNames.java
#=======================================================================================================
#	 Date	       time   	   Name	 Action	   Description of Change
#	2011-1-18      下午04:59:11    tyl  	Ini	            初始化文件
#=======================================================================================================
*/
package cn.com.customization.imports.importfiles;

import java.util.ArrayList;
import java.util.List;

import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;

public class GetAllDataSetNames {

	/**
	 * Creates a new instance of GetAllDataSet.
	 */
	public GetAllDataSetNames() {}

	/**
	 * getDatasetInfo:得到版本下已经存在的数据集的名称
	 * @param @return 设定文件
	 * @return String 对象类型
	 * @throws
	 * @since CodingExample　Ver 1.1
	 */
	public List<String> getDatasetNames(TCComponent component,String strRelName) {
		List<String> datasetNames = new ArrayList<String>();
		try {
			if (component instanceof TCComponentItemRevision) {
				TCComponentItemRevision itemRevision = (TCComponentItemRevision) component;
				
				TCComponent[] datasets = null;
				if(strRelName.length() > 0){
					datasets = (TCComponent[]) itemRevision.getRelatedComponents(strRelName);
				}else{
					datasets = (TCComponent[]) itemRevision.getRelatedComponents("IMAN_specification");
				}
//				TCComponent[] datasets = (TCComponent[]) itemRevision.getRelatedComponents("IMAN_specification");
				for (int j = 0; j < datasets.length; j++) {
					if (datasets[j] instanceof TCComponentDataset) {
						String name = datasets[j].getProperty("object_name");
						datasetNames.add(name);
					}
				}
			} else if (component instanceof TCComponentFolder) {
				TCComponentFolder folder = (TCComponentFolder) component;
				TCComponent[] datasets = (TCComponent[]) folder.getRelatedComponents("contents");
				for (int j = 0; j < datasets.length; j++) {
					if (datasets[j] instanceof TCComponentDataset) {
						String name = datasets[j].getProperty("object_name");
						datasetNames.add(name);
					}
				}
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return datasetNames;
	}
}
