package cn.net.connor.std.processedit.modifymeopno;

import java.util.HashMap;

import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
import com.teamcenter.rac.kernel.TCComponentItemRevision;

import cn.net.connor.std.aifrcp.util.KUtil;
import cn.net.connor.std.aifrcp.util.PropLocation;

public class ModifyMeopNoRow {
	
	private TCComponentBOMLine bomline;
	private boolean isReleased;
	private HashMap<String, TCComponent> markedComponents;

	public ModifyMeopNoRow(TCComponentBOMLine cLine) throws Exception {
		this.bomline = cLine;
		this.bomline.refresh();
		TCComponentItemRevision rev = cLine.getItemRevision();
		if(rev==null) {
			throw new Exception("revision not found: "+cLine);
		}
		rev.refresh();
		markedComponents = new HashMap<String, TCComponent>();
		PropLocation.initLocationMap(markedComponents , getBomline());
		this.isReleased=KUtil.isReleased(rev);
	}
	
	public boolean isReleased() {
		return this.isReleased;
	}

	public Object[] getRowData(String[] tableProps) throws Exception{
		int len = KUtil.getLen(tableProps);
		Object[] data = new Object[len+1];
		data[0] = this;
		for(int i=0; i<len; i++) {
			String[] config = tableProps[i].split("\\.");
			if(KUtil.getLen(config)!=2) {
				data[i+1] = tableProps[i];
				continue;
			}
			String propLoc = config[0].toUpperCase();
			if(markedComponents.containsKey(propLoc)) {
				data[i+1] = markedComponents.get(propLoc).getProperty(config[1]);
			}else {
				data[i+1] = tableProps[i];
			}
		}
		return data;
	}
	
	@Override
	public String toString() {
		return getBomline().toString();
	}

	public TCComponentBOMLine getBomline() {
		return bomline;
	}
}
