/* $Id: RootFolder.java 506 2012-06-01 08:23:43Z ohura $ */
package smart_gs.reasoning_web;


import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import smart_gs.reasoning_web.desktop.logical.DeskTopFolder;
import smart_gs.reasoning_web.desktop.logical.ShortCut;

public class RootFolder extends DeskTopFolder{

	private static RootFolder singleton = new RootFolder();
	
	private RootFolder() {
		super(null,"root");
	}
	
	public static RootFolder getInstance(){
		return singleton;
	}
	@Override
	public Element createXMLElement(Document document) {
		Element element =  super.createXMLElement(document);
		element.setAttribute("isRoot","true");
		
		return element;
	}
	public void restoreAll(Element element){
		String source = element.getAttribute("source");
		DeskTopFolder folder = RootFolder.getInstance();
		folder.initialize();
		folder.setString(source);
		NodeList list = element.getElementsByTagName("desktopFolder");

		for(int i=0;i<list.getLength();i++){
			DeskTopFolder childFolder = DeskTopFolder.restore((Element)list.item(i));
			folder.add(childFolder);
		}
		
		list = element.getElementsByTagName("shortcut");
		for(int i=0;i<list.getLength();i++){
			if(!list.item(i).getParentNode().equals(element)){
				continue;
			}
			ShortCut shortcut = ShortCut.restore((Element)list.item(i));
			folder.add(shortcut);
		}
	}

	public void clear() {
		singleton.initialize();
//		singleton.setString(null);
	}
}
