	package interactivefeaturelocator.model;
	
	import java.io.File;
	import java.io.IOException;
	import java.util.ArrayList;
	
	import javax.xml.parsers.DocumentBuilder;
	import javax.xml.parsers.DocumentBuilderFactory;
	import javax.xml.parsers.ParserConfigurationException;
	
	import org.ntlab.trace.Trace;
	import org.w3c.dom.Document;
	import org.w3c.dom.Element;
	import org.w3c.dom.Node;
	import org.w3c.dom.NodeList;
	import org.w3c.dom.views.DocumentView;
	import org.xml.sax.SAXException;
	
	public class Feature {
		
		private ArrayList<Pattern> patterns = new ArrayList<>();
		private File featureXml;
		private String description;
		
		public Feature(String featurePath) throws ParserConfigurationException, SAXException, IOException {
			File featureFolder = new File(featurePath);
			File[] files = featureFolder.listFiles();
			
			// Featureクラスのインスタンスにpatternsとfeature.xmlを格納
			for (File f : files) {
				if (f.isDirectory()) {
					if (f.getName().startsWith("Pattern")) {
						patterns.add(new Pattern(f.getPath()));
					}				
				}
				if (f.isFile()) {
					if (f.getName().endsWith("xml")) {
						featureXml = f;
					}				
				}
			}
			
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder documentBuilder = factory.newDocumentBuilder();
			Document document = documentBuilder.parse(featureXml);
			
			Element root = document.getDocumentElement();
			//ルート要素のノード名を取得する
					System.out.println("ノード名：" +root.getNodeName());
	
					//ルート要素の属性を取得する
					System.out.println("ルート要素の属性 name:" + root.getAttribute("name") + ", description: " + root.getAttribute("description"));
					description = root.getAttribute("description");
					System.out.println("------------------");
			
		}
	
		public File getFeatureXml() {
			return featureXml;
		}
	
		public ArrayList<Pattern> getPatterns() {
			return patterns;
		}
	
		public String getDescription() {
			return description;
		}
	}
