/**
 * @author	STF 424_ITS_Test_Platform
 * @version    $URL$
 *             $Id$
 */
package org.etsi.its.codec.adapter;

import org.etsi.its.codec.adapter.ICodecFactory;

/** 
 * This class implement a factory to instantiate a new Test Adapter codec instance
 * 
 * @category Factory
 */
public class CodecsFactory implements ICodecFactory {

	/** 
	 * Unique instance of this class
	 */
	private static CodecsFactory _instance = new CodecsFactory();

	/** 
	 * Constructor
	 */
	private CodecsFactory() {
		//empty
	}

	/** 
	 * Singleton access method
	 * 
	 * @return A unique reference to the class CodecsFactory
	 */
	public static CodecsFactory getInstance() {
		return _instance;
	}

	/**
	 * This method instantiate the requested Test Adapter codec
	 * @param instance The requested codec
	 * @return A new instance of a Test Adapter codec
	 */
	public ICodec InstanciateCodec(final SupportedCodecsEnum instance) {
		ICodec newInstance = null;
		switch (instance) { // TODO: To be enhanced using refactor concept (Class<?>[] ctorParams = {instance.getClass()};, with String instance)
			case LibItsCommon_TypesAndValues:
				newInstance = new UpperTesterCodecImpl();
				break;
			case LibItsGeoNetworking_TypesAndValues:
				newInstance = new AdapterControlCodecImpl();
				break;
			case LibIts_Interface:
				newInstance = new LibItsInterfaceCodecImpl();
				break;
			default:
				throw new ExceptionInInitializerError(String.format("CodecsFactory.InstanciateCodec: codec '%s' not implemented yet", instance.name()));
		}
		return newInstance;
	} // End of method InstanciateCodec

} // End of class CodecsFactory
