/*
 * Created on May 11, 2007
 * 
 * (C) Copyright TANDBERG Television Ltd.
 */

package com.tandbergtv.workflow.comm.routing;

import java.util.ResourceBundle;

/**
 * Factory to instantate the RoutingService
 * 
 * @author Vijay Silva
 */
public final class RoutingServiceFactory
{
	/* The routing service bundle */
	private static final String ROUTING_SERVICE_BUNDLE = "com.tandbergtv.workflow.comm.routing.RoutingService";

	/* The Key for the class name */
	private static final String ROUTING_SERVICE_CLASS_NAME = "RoutingServiceImpl";

	private String className = null;

	/**
	 * Creates an instance of the Routing Service factory
	 * 
	 * @return The RoutingServiceFactory object
	 */
	public static RoutingServiceFactory newInstance()
	{
		return new RoutingServiceFactory();
	}

	/*
	 * Cannot instantiate directly
	 */
	private RoutingServiceFactory()
	{
		ResourceBundle bundle = ResourceBundle.getBundle(ROUTING_SERVICE_BUNDLE);
		this.className = bundle.getString(ROUTING_SERVICE_CLASS_NAME);
	}

	/**
	 * Instantiates a new instance of the RoutingService as specified in the routing service
	 * properties file.
	 * 
	 * @return The RoutingService Implementation
	 */
	public IRoutingService createRoutingService()
	{
		Class clazz;
		try
		{
			clazz = Class.forName(this.className);
			return (IRoutingService) clazz.newInstance();
		}
		catch (Exception ex)
		{
			String errMsg = "Failed to instantiate the IRoutingService Implementation: "
					+ this.className;
			throw new RuntimeException(errMsg, ex);
		}
	}
}
