package com.alexrnl.commons.database;

import java.io.Closeable;
import java.io.IOException;
import java.util.logging.Logger;

import com.alexrnl.commons.error.ExceptionUtils;

/**
 * The abstract factory for the {@link DAO}s.<br />
 * It manages the creation of the factory through the {@link #createFactory(String)} method.<br />
 * The user of this class should extend id and add the required {@link DAO} methods needed for its
 * needs.
 * @author Alex
 */
public abstract class AbstractDAOFactory implements Closeable {
	/** Logger */
	private static Logger				lg	= Logger.getLogger(AbstractDAOFactory.class.getName());
	
	/** Implementation of the factory to be used */
	private static AbstractDAOFactory	implementation;
	
	/**
	 * Return the implementation of the factory to be used.
	 * @return the concrete implementation
	 */
	public static AbstractDAOFactory getImplementation () {
		return implementation;
	}
	
	/**
	 * Retrieve and create the appropriate factory.
	 * @param factoryClass
	 *        the type of DAO required.
	 */
	public static synchronized void createFactory (final String factoryClass) {
		try {
			if (implementation != null) {
				try {
					implementation.close();
				} catch (final IOException e) {
					lg.warning("Could not close previous implementation (" + e.getMessage() + ")");
				}
			}
			implementation = Class.forName(factoryClass).asSubclass(AbstractDAOFactory.class).newInstance();
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ClassCastException e) {
			lg.severe("Cannot instantiate DAO factory class (" + factoryClass + "). " + ExceptionUtils.display(e));
			throw new DAOInstantiationError(factoryClass, e);
		}
	}
	
}

@@ -366,17 +366,17 @@
 extend i
-d
+t
  and add
@@ -929,51 +929,51 @@
 %09 * 
-Retrieve and create the appropriate factory
+Create the factory from the class specified
 .%0A%09 
@@ -1090,22 +1090,51 @@
  (final 
-String
+Class%3C? extends AbstractDAOFactory%3E
  factory
@@ -1378,149 +1378,566 @@
 n = 
-Class.forName(factoryClass).asSubclass(AbstractDAOF
+factoryClass.newInstance();%0A%09%09%7D catch (InstantiationException %7C IllegalAccessException e) %7B%0A%09%09%09lg.severe(%22Cannot instantiate DAO f
 actory
-.class).newInstance();%0A%09%09%7D catch (InstantiationException %7C IllegalAccessException %7C 
+ class (%22 + factoryClass + %22). %22 + ExceptionUtils.display(e));%0A%09%09%09throw new DAOInstantiationError(factoryClass.getName(), e);%0A%09%09%7D%0A%09%7D%0A%09%0A%09/**%0A%09 * Retrieve and create the appropriate factory.%0A%09 * @param factoryClass%0A%09 *        the type of DAO required.%0A%09 */%0A%09public static void createFactory (final String factoryClass) %7B%0A%09%09try %7B%0A%09%09%09createFactory(Class.forName(factoryClass).asSubclass(AbstractDAOFactory.class));%0A%09%09%7D catch (
 Clas

Split class loading and instantiation in two methods