package com.eactive.eai.transformer.layout;

import com.eactive.eai.transformer.util.ConstantUtil;

public class ItemFactory {
	private ItemFactory() {
		
	}
	public static Item createItem(int nodeTypeId) {
		switch (nodeTypeId) {
		case Item.NODE_ATTR:
			return new Attribute();
		case Item.NODE_FIELD:
			return new Field();
		case Item.NODE_GROUP:
			return new Group();
		default:
			throw new RuntimeException("cannot create item - node type id : " + nodeTypeId);
		}
	}
	
	public static Item createItem(String nodeTypeName) {
		if (nodeTypeName == null) {
			throw new RuntimeException("cannot create item - note type is null");
		}
		
		int nodeTypeId = ConstantUtil.getNodeTypeId(nodeTypeName.trim());
		try {
			return createItem(nodeTypeId);
		} catch(Exception e) {
			throw new RuntimeException("cannot create item - node type name : " + nodeTypeName, e);
		}
	}
}
