/*
 * $Id: WorkflowServiceFactory.java,v 1.3 2004/11/10 15:02:53 koppy Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * Created on 06.07.2004
 *
 * $Log: WorkflowServiceFactory.java,v $
 * Revision 1.3  2004/11/10 15:02:53  koppy
 * Projektweite Überarbeitung von Error-Logs, Stacktraces,..
 *
 * Revision 1.2  2004/09/20 10:26:11  koppy
 * +javadoc Dokumentation
 *
 * Revision 1.1  2004/08/30 14:48:57  koppy
 * Initiale Version der Workflow-Komponente
 *
 */
package vkc.workflow;

import vkc.misc.VKCLogManager;
import vkc.view.WebShare;
import vkc.workflow.service.VKCWorkflowService;


/**
 * This class represents a factory
 * for creating a workflow service.
 * <p>
 * The configuration is done <code>WEB-INF/vkc.properties</code>
 * as follows:<br />
 * <code>WorkflowServiceClass=vkc.workflow.service.CORBAWorkflowService</code>
 * <p>
 * The expected class must implement the <code>@link{vkc.workflow.service.VKCWorkflowService}</code>
 * interface.
 * 
 * @author Andreas Koop
 */
public class WorkflowServiceFactory {

    /**
     * Instance of a workflow service
     */
    private static VKCWorkflowService instance = null;
    
    /**
     * Returns the WorkflowService instance configured
     * in the <code>vkc.properties</code>
     * @return the VKCWorkflowService
     */
    public static synchronized VKCWorkflowService getWorkflowService(){
        
        if(instance == null){
        
            ClassLoader cl = WorkflowServiceFactory.class.getClassLoader();
            try {
                instance = (VKCWorkflowService)cl.loadClass(
                        		WebShare.getProperties().getProperty( "WorkflowServiceClass" ))
                        		.newInstance();
            } catch (Exception e) {
                VKCLogManager.errorLog(VKCWorkflowService.class, "", e.getMessage(),e);
                throw new Error( "Workflow Service could not be instantiated!");
            }    
        }   
        
        return instance;
    }

}
