Search in sources :

Example 6 with FileHandlerInterface

use of com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface in project sldeditor by robward-scisys.

the class DatabaseConnectionFactory method getConnection.

/**
 * Gets the database connection.
 *
 * @param filename the filename
 * @return the new connection
 */
public static DatabaseConnection getConnection(String filename) {
    List<FileHandlerInterface> list = getFileHandlers();
    if (filename != null) {
        for (FileHandlerInterface handler : list) {
            for (String fileExtension : handler.getFileExtensionList()) {
                if (filename.endsWith(fileExtension)) {
                    String dbConnectionType = fileHandlerMap.get(handler);
                    DatabaseConnection dbConnection = createDefault(dbConnectionType);
                    Map<String, String> connectionDataMap = new HashMap<String, String>();
                    connectionDataMap.put(JDBCDataStoreFactory.DATABASE.key, filename);
                    dbConnection.setConnectionDataMap(connectionDataMap);
                    return dbConnection;
                }
            }
        }
    }
    return null;
}
Also used : FileHandlerInterface(com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface) HashMap(java.util.HashMap) DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)

Aggregations

FileHandlerInterface (com.sldeditor.datasource.extension.filesystem.node.file.FileHandlerInterface)6 File (java.io.File)5 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)3 SLDDataInterface (com.sldeditor.common.SLDDataInterface)2 NodeInterface (com.sldeditor.common.NodeInterface)1 DatabaseConnection (com.sldeditor.common.data.DatabaseConnection)1 SelectedFiles (com.sldeditor.common.filesystem.SelectedFiles)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1