/* Copyright (C) 2009  CSE,IIT Bombay  http://www.cse.iitb.ac.in

This file is part of the ConStore open source storage facility for concept-nets.

ConStore is free software and distributed under the 
Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License;
you can copy, distribute and transmit the work
with the work attribution in the manner specified by the author or licensor.
You may not use this work for commercial purposes and may not alter, 
transform, or build upon this work.

Please refer the legal code of the license, available at
http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode

ConStore is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  */

package iitb.con.net;

import iitb.con.util.FileUtil;

import java.io.FileNotFoundException;
import java.io.IOException;


/**
 * ConStore provides the high level system operations 
 * such as create, open, and deletion of ConceptNet.
 * 
 * @author Prathab K
 * 
 * @see ConceptNet
 *
 */
public class ConStore {
    
    /**
     * Creates new concept-net and opens in the specified mode.<br>
     * The opening mode can read (r) or read-write (rw).
     * @param name concept-net name
     * @throws IOException if the file operations fails.
     */
    public static ConceptNet create (String name)
    throws IOException  {
        return ConceptNet.create(name, "rw");
    }
    
    /**
     * Opens the existing concept-net in the specified mode.<br>
     * The opening mode can read (r) or read-write (rw).<br>
     * If Concept-Net does not exists then it throws exception.
     * @param name concept-net name
     * @param mode opening mode
     * @throws FileNotFoundException if the specified concept-net file is not found
     * @throws IOException if file operation fails
     *  
     */
    public static ConceptNet open (String name, String mode)
    throws FileNotFoundException, IOException {
         return ConceptNet.open(name, mode);
     }
    
    /**
     * Deletes the existing concept-net.
     * @param conceptNetDir Concept-Net Directory
     * @return <code>true</code> on success
     */
    public static boolean delete(String conceptNetDir) {
        return FileUtil.deleteDir(conceptNetDir);
    }
    
    /**
     * Returns <tt>true</tt> if concept-net of specified name exists
     * @param name concept-net name
     * @return <tt>true</tt> if concept-net exists
     */
    public static boolean isExists(String name) {
        return FileUtil.isFileExists(name);
    }

}