package addressbook;

import org.w3c.dom.Node;

public class UserBean {

	private String id = ""; // ID

	private String name = ""; // 名前

	private String password = ""; // パスワード

	/**
	 * コンストラクタ Xprioriからuserノードを渡し、メンバ変数を設定する 
	 * @param usernode
	 */
	public UserBean(Node usernode) {
			if(usernode != null && usernode.getNodeName().equals("user")){
				// IDを取得
				this.setID(usernode.getAttributes().getNamedItem("id").getNodeValue());
				// 名前を取得
				this.setName(AddressbookUtils.getChildNodeByTagName(usernode,"name").getFirstChild().getNodeValue());
				// パスワードを取得
				this.setPassword(AddressbookUtils.getChildNodeByTagName(usernode,"password").getFirstChild().getNodeValue());
			}
	}
	
	/**
	 * デフォルトコンストラクタ
	 */
	public UserBean() {
	}

  /**
   * IDをセット
   * @param id
   */	
	public void setID(String id) {
		this.id = id;
	}

	/**
	 * IDをゲット
	 * @return ID
	 */
	public String getID() {
		return this.id;
	}

	/**
	 * 名前をセット
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 名前をゲット
	 * @return
	 */
	public String getName() {
		return this.name;
	}
	
	/**
	 * パスワードをセット
	 * @param password
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * パスワードをゲット
	 * @return
	 */
	public String getPassword() {
		return this.password;
	}

	/**
	 * ユーザのxmlを取得する
	 * @return userXML
	 */
	public String getUserXML() {
		String userXML = "<user id=\"" + this.getID() + "\">" + "<name>"
				+ this.getName() + "</name>"
				+ "<password>" + this.getPassword() + "</password>"
				+ "</user>";
		return userXML;
	}
}

