package org.judal.storage;

/**
 * This file is licensed under the Apache License version 2.0.
 * 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.
 */

import java.util.Hashtable;

public class EngineFactory {
	
	private static Hashtable<String, Class<Engine<? extends DataSource>>> engines = new Hashtable<String, Class<Engine<? extends DataSource>>>();
	
	@SuppressWarnings("unchecked")
	public static void registerEngine(String engineName, String engineClassName) throws ClassNotFoundException {
		engines.put(engineName, (Class<Engine<? extends DataSource>>) Class.forName(engineClassName));
	}
	
	public static Engine<? extends DataSource> getEngine(String engineName) throws InstantiationException, IllegalAccessException {
		return engines.get(engineName).newInstance();
	}

	/*
	 * Some standard names for engines
	 */
	public static final String NAME_JDBC = "JDBC";
	public static final String NAME_BERKELEYDB = "BDB";
	public static final String NAME_AMAZONS3 = "S3";
	public static final String NAME_CASSANDRA = "CASSANDRA";
	public static final String NAME_HBASE = "HBASE";
	public static final String NAME_MONGODB = "MONGODB";
	public static final String NAME_REDIS = "REDIS";
	
}

@@ -547,16 +547,84 @@
 y %7B%0D%0A%09%0D%0A
+%09public static ThreadLocal%3CDataSource%3E DefaultThreadDataSource;%0D%0A%09%0D%0A
 %09private
@@ -800,385 +800,1981 @@
 )%0D%0A%09
-public static void registerEngine(String engineName, String engineClassName) throws ClassNotFoundException %7B%0D%0A%09%09engines.put(engineName, (Class%3CEngine%3C? extends DataSource%3E%3E) Class.forName(engineClassName));%0D%0A%09%7D%0D%0A%09%0D%0A%09public static Engine%3C? extends DataSource%3E getEngine(String engineName) throws InstantiationException, IllegalAccessException %7B%0D%0A%09%09return engines.get(engineName)
+/**%0D%0A%09 * %3Cp%3ERegister an Engine implementation under a given name%3C/p%3E%0D%0A%09 * @param engineName String Engine name.%0D%0A%09 * @param engineClassName String Name of an implementation of org.judal.storage.Engine%0D%0A%09 * @throws ClassNotFoundException%0D%0A%09 * @throws IllegalArgumentException If another Engine implementation is already registered under the same name%0D%0A%09 */%0D%0A%09public static void registerEngine(String engineName, String engineClassName) throws ClassNotFoundException, IllegalArgumentException %7B%0D%0A%09%09Class%3CEngine%3C? extends DataSource%3E%3E engineClass = engines.get(engineName);%0D%0A%09%09if (engineClass==null)%0D%0A%09%09%09engines.put(engineName, (Class%3CEngine%3C? extends DataSource%3E%3E) Class.forName(engineClassName));%0D%0A%09%09else if (engineClass.getName().equals(engineClassName))%0D%0A%09%09%09throw new IllegalArgumentException(%22EngineFactory.registerEngine() Engine %22 + engineName + %22 is already registered for class %22 + engineClassName);%0D%0A%09%7D%0D%0A%09%0D%0A%09/**%0D%0A%09 * %3Cp%3EGet implementation for a given named Engine%3C/p%3E%0D%0A%09 * @param engineName String%0D%0A%09 * @return Engine&lt;? extends DataSource&gt;%0D%0A%09 * @throws InstantiationException%0D%0A%09 * @throws IllegalAccessException%0D%0A%09 * @throws NullPointerException If engineName is %3Cb%3Enull%3C/b%3E or empty String%0D%0A%09 * @throws IllegalArgumentException If no Engine has been previously registered with the given name%0D%0A%09 */%0D%0A%09public static Engine%3C? extends DataSource%3E getEngine(String engineName) throws InstantiationException, IllegalAccessException, NullPointerException, IllegalArgumentException %7B%0D%0A%09%09if (null==engineName)%0D%0A%09%09%09throw new NullPointerException(%22EngineFactory.getEngine() Engine name cannot be null%22);%0D%0A%09%09else if (engineName.length()==0)%0D%0A%09%09%09throw new NullPointerException(%22EngineFactory.getEngine() Engine name is required%22);%0D%0A%09%09Class%3CEngine%3C? extends DataSource%3E%3E engineClass = engines.get(engineName);%0D%0A%09%09if (null==engineClass)%0D%0A%09%09%09throw new IllegalArgumentException(%22EngineFactory.getEngine() Cannot find any Engine with name %22 + engineName);%0D%0A%09%09return engineClass
 .new

Add Javadoc