package kr.gmtc.tss.util.vo;

import java.util.HashMap;
import java.util.Map;

public class NodeValue{

	public NodeValue() {
		
	}
	public NodeValue(String nodeFullName,String text) {
		
		this.text=text;
		this.nodeFullName=nodeFullName;
		if(!nodeFullName.isEmpty()&&nodeFullName.contains(":")) {
			String[] nodeNmArr=nodeFullName.split(":");
			if(nodeNmArr.length>1) {
				this.nodeName=nodeNmArr[1];
				this.nodeNs=nodeNmArr[0];
			}
		}else {
			this.nodeName=nodeFullName;
			
		}
		
		
		
	}
	
	String nodeFullName;
	String nodeName;
	String nodeNs="";
	String text;
	Map<String,String> attrMap = new HashMap<>();
	Map<String,Object> childMap = new HashMap<>();
	
	Map<String, String> nsMap = new HashMap<>();
	Map<String, String> xsiMap = new HashMap<>();
	
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public Map<String, String> getAttrMap() {
		return attrMap;
	}
	
	public String getAttrMapValue(String key) {
		return attrMap.get(key);
	}
	
	
	public void setAttrMap(Map<String, String> attrMap) {
		this.attrMap = attrMap;
	}
	
	public void putAttr(String key,String data) {
		
		if(key.contains("xmlns:")) {
			String [] keyVal = key.split(":");
			try {
				nsMap.put(keyVal[1], data);
			} catch (NullPointerException e) {
				nsMap.put(key, data);
			}
			
		}else if(key.contains("xsi:")) {
			String [] keyVal = key.split(":");
			try {
				xsiMap.put(keyVal[1], data);
			} catch (NullPointerException e) {
				xsiMap.put(key, data);
			}
		}else {
			attrMap.put(key, data);	
		}
		
		
	}
	
	public Map<String, Object> getChildMap() {
		return childMap;
	}
	public void setChildMap(Map<String, Object> childMap) {
		this.childMap = childMap;
	}

	public void putChildMap(String key,Object data) {
		childMap.put(key, data);
	}
	
	
	public String getNsMapValue(String key) {
		return nsMap.get(key);
	}
	public Map<String, String> getNsMap() {
		return nsMap;
	}
	public void setNsMap(Map<String, String> nsMap) {
		this.nsMap = nsMap;
	}
	

	public String getXsiMapValue(String key) {
		return xsiMap.get(key);
	}
	public Map<String, String> getXsiMap() {
		return xsiMap;
	}
	public void setXsiMap(Map<String, String> xsiMap) {
		this.xsiMap = xsiMap;
	}
	public String getNodeName() {
		return nodeName;
	}
	public void setNodeName(String nodeName) {
		this.nodeName = nodeName;
	}
	public String getNodeNs() {
		return nodeNs;
	}
	public void setNodeNs(String nodeNs) {
		this.nodeNs = nodeNs;
	}
	

 	
	
	public String getNodeFullName() {
		return nodeFullName;
	}
	public void setNodeFullName(String nodeFullName) {
		this.nodeFullName = nodeFullName;
	}
	@Override
	public String toString() {
		return "NodeValue [nodeName=" + nodeName + ", nodeNs=" + nodeNs + ", text=" + text + ", attrMap=" + attrMap
				+ ", childMap=" + childMap + "]";
	}

	
	
}
