// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/Loader.java
// public interface Loader {
// 
//     /**
//      * The message key for the error reported when a source file cannot be read.
//      */
//     String CANNOT_READ_SOURCE_FILE = "cannot_read_source_file";
// 
//     /**
//      * The message key for the error reported when a source file cannot be processed.
//      */
//     String ERROR_PROCESSING_SOURCE_FILE = "error_processing_source_file";
// 
//     /**
//      * Determine whether or not the data or script can be loaded or executed.
//      *
//      * @param logger Used to report errors and raise exceptions.
//      * @param source The source file containing the data or script.
//      * @return <ul>
//      *         <li><code>true</code> if the data or script can be loaded or executed.</li>
//      *         <li><code>false</code>if the data or script cannot be loaded or executed.</li>
//      *         </ul>
//      */
//     boolean isSupported(Logger logger, Source source);
// 
//     /**
//      * Load data into or execute a script against the in-memory database.
//      *
//      * @param logger   Used to report errors and raise exceptions.
//      * @param database The in-memory database.
//      * @param source   The source file containing the data or script.
//      */
//     void load(Logger logger, Database database, Source source);
// }
// 
// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/Source.java
// public interface Source {
// 
//     /**
//      * Get the source file that contains the DDL/DML script or DBUnit data set.
//      *
//      * @return The source file.
//      */
//     String getSourceFile();
// 
//     /**
//      * Determine if the table names in the source file are fully qualified.
//      *
//      * @return <ul>
//      *         <li>{@link Boolean#TRUE} if the table names are fully qualified.</li>
//      *         <li>{@link Boolean#FALSE} if the table names are not fully qualified.</li>
//      *         </ul>
//      */
//     Boolean getQualifiedTableNames();
// }


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Locale;
import com.btmatthews.maven.plugins.inmemdb.Loader;
import com.btmatthews.maven.plugins.inmemdb.Source;
import com.btmatthews.utils.monitor.Logger;

/*
 * Copyright 2011-2012 Brian Matthews
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.btmatthews.maven.plugins.inmemdb.ldr;



/**
 * Abstract base class for loaders that implements the {@link
 * Loader#isSupported(com.btmatthews.utils.monitor.Logger, com.btmatthews.maven.plugins.inmemdb.Source)} method.
 *
 * @author <a href="mailto:brian@btmathews.com">Brian Matthews</a>
 * @version 1.0.0
 */
public abstract class AbstractLoader implements Loader {

    /**
     * The prefix used to denote that a resource should be loaded from the classpath
     * rather than the file system.
     */
    protected static final String CLASSPATH_PREFIX = "classpath:";

    /**
     * The length of the classpath: prefix.
     */
    protected static final int CLASSPATH_PREFIX_LENGTH = 10;

    /**
     * The message key for the error reported when an error occurs validating a
     * file.
     */
    protected static final String CANNOT_VALIDATE_FILE = "cannot_validate_file";

    /**
     * Get the extension of the files that the loader will support.
     *
     * @return The file extension.
     */
    protected abstract String getExtension();

    /**
     * Check the contents of the file to see if it is valid for this loader.
     *
     * @param logger Used to report errors and raise exceptions.
     * @param source The source data or script.
     * @return <ul>
     *         <li><code>true</code> if the content is valid.</li>
     *         <li><code>false</code> if the content is invalid.</li>
     *         </ul>
     */

// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/Loader.java
// public interface Loader {
// 
//     /**
//      * The message key for the error reported when a source file cannot be read.
//      */
//     String CANNOT_READ_SOURCE_FILE = "cannot_read_source_file";
// 
//     /**
//      * The message key for the error reported when a source file cannot be processed.
//      */
//     String ERROR_PROCESSING_SOURCE_FILE = "error_processing_source_file";
// 
//     /**
//      * Determine whether or not the data or script can be loaded or executed.
//      *
//      * @param logger Used to report errors and raise exceptions.
//      * @param source The source file containing the data or script.
//      * @return <ul>
//      *         <li><code>true</code> if the data or script can be loaded or executed.</li>
//      *         <li><code>false</code>if the data or script cannot be loaded or executed.</li>
//      *         </ul>
//      */
//     boolean isSupported(Logger logger, Source source);
// 
//     /**
//      * Load data into or execute a script against the in-memory database.
//      *
//      * @param logger   Used to report errors and raise exceptions.
//      * @param database The in-memory database.
//      * @param source   The source file containing the data or script.
//      */
//     void load(Logger logger, Database database, Source source);
// }
// 
// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/Source.java
// public interface Source {
// 
//     /**
//      * Get the source file that contains the DDL/DML script or DBUnit data set.
//      *
//      * @return The source file.
//      */
//     String getSourceFile();
// 
//     /**
//      * Determine if the table names in the source file are fully qualified.
//      *
//      * @return <ul>
//      *         <li>{@link Boolean#TRUE} if the table names are fully qualified.</li>
//      *         <li>{@link Boolean#FALSE} if the table names are not fully qualified.</li>
//      *         </ul>
//      */
//     Boolean getQualifiedTableNames();
// }


// Path: src/main/java/com/btmatthews/maven/plugins/inmemdb/ldr/AbstractLoader.java
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Locale;
import com.btmatthews.maven.plugins.inmemdb.Loader;
import com.btmatthews.maven.plugins.inmemdb.Source;
import com.btmatthews.utils.monitor.Logger;

/*
 * Copyright 2011-2012 Brian Matthews
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.btmatthews.maven.plugins.inmemdb.ldr;



/**
 * Abstract base class for loaders that implements the {@link
 * Loader#isSupported(com.btmatthews.utils.monitor.Logger, com.btmatthews.maven.plugins.inmemdb.Source)} method.
 *
 * @author <a href="mailto:brian@btmathews.com">Brian Matthews</a>
 * @version 1.0.0
 */
public abstract class AbstractLoader implements Loader {

    /**
     * The prefix used to denote that a resource should be loaded from the classpath
     * rather than the file system.
     */
    protected static final String CLASSPATH_PREFIX = "classpath:";

    /**
     * The length of the classpath: prefix.
     */
    protected static final int CLASSPATH_PREFIX_LENGTH = 10;

    /**
     * The message key for the error reported when an error occurs validating a
     * file.
     */
    protected static final String CANNOT_VALIDATE_FILE = "cannot_validate_file";

    /**
     * Get the extension of the files that the loader will support.
     *
     * @return The file extension.
     */
    protected abstract String getExtension();

    /**
     * Check the contents of the file to see if it is valid for this loader.
     *
     * @param logger Used to report errors and raise exceptions.
     * @param source The source data or script.
     * @return <ul>
     *         <li><code>true</code> if the content is valid.</li>
     *         <li><code>false</code> if the content is invalid.</li>
     *         </ul>
     */

    protected boolean hasValidContent(final Logger logger, final Source source) {
