/*
 * Copyright 2004-2006 the original author or authors.
 * 
 * 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 org.compass.core.lucene.engine.store;

public class LuceneSearchEngineStoreFactory {

    public static final String MEM_PREFIX = "ram://";

    public static final String FILE_PREFIX = "file://";

    public static final String MMAP_PREFIX = "mmap://";

    public static final String JDBC_PREFIX = "jdbc://";

    public static LuceneSearchEngineStore createStore(String connection, String subContext) {
        if (connection.startsWith(MEM_PREFIX)) {
            return new RAMLuceneSearchEngineStore(connection.substring(MEM_PREFIX.length(), connection.length()), subContext);
        }
        if (connection.startsWith(MMAP_PREFIX)) {
            return new MMapLuceneSearchEngineStore(connection.substring(MMAP_PREFIX.length(), connection.length()), subContext);
        }
        if (connection.startsWith(FILE_PREFIX)) {
            return new FSLuceneSearchEngineStore(connection.substring(FILE_PREFIX.length(), connection.length()), subContext);
        }
        if (connection.startsWith(JDBC_PREFIX)) {
            return new JdbcLuceneSearchEngineStore(connection.substring(JDBC_PREFIX.length(), connection.length()), subContext);
        }
        return new FSLuceneSearchEngineStore(connection, subContext);
    }
}

@@ -665,16 +665,236 @@
 store;%0A%0A
+import java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.lang.reflect.Constructor;%0Aimport java.util.Properties;%0A%0Aimport org.compass.core.engine.SearchEngineException;%0Aimport org.compass.core.util.ClassUtils;%0A%0A
 public c
@@ -1995,32 +1995,1248 @@
 ext);%0A        %7D%0A
+        int index = connection.indexOf(%22://%22);%0A        if (index != -1) %7B%0A            String pluggableStore = connection.substring(0, index);%0A            InputStream is = LuceneSearchEngineStore.class.getResourceAsStream(%22/compass-store-%22 + pluggableStore + %22.properties%22);%0A            Properties props;%0A            try %7B%0A                props = new Properties();%0A                props.load(is);%0A            %7D catch (Exception e) %7B%0A                try %7B%0A                    is.close();%0A                %7D catch (IOException e1) %7B%0A                    // ignore%0A                %7D%0A                throw new SearchEngineException(%22Failed to create store %5B%22 + connection + %22%5D%22, e);%0A            %7D%0A            String className = props.getProperty(%22type%22);%0A            try %7B%0A                Class storeClass = ClassUtils.forName(className);%0A                Constructor storeConst = storeClass.getConstructor(new Class%5B%5D%7BString.class, String.class%7D);%0A                return (LuceneSearchEngineStore) storeConst.newInstance(new Object%5B%5D%7Bconnection, subContext%7D);%0A            %7D catch (Exception e) %7B%0A                throw new SearchEngineException(%22Failed to create connection %5B%22 + connection + %22%5D%22, e);%0A            %7D%0A        %7D%0A
         return n

support custom store