//----------------------------BEGIN LICENSE----------------------------
/* 
 * Willow : the Open Source WorkFlow Project
 * Distributable under GNU LGPL license by gun.org
 *
 * Copyright (C) 2004-2010  huihoo.org 
 * Copyright (C) 2004-2010  ZosaTapo <dertyang@hotmail.com> 
 * 
 * ====================================================================
 * Project Homepage : http://www.huihoo.org/willow
 * Source Forge     : http://sourceforge.net/projects/huihoo
 * Mailing list     : willow@lists.sourceforge.net 
 */
//----------------------------END  LICENSE-----------------------------
package org.huihoo.willow.core;

import java.util.Enumeration;
import java.util.Hashtable;

import org.huihoo.willow.util.StringManager;
import org.huihoo.workflow.server.WorkflowConfig;
import org.huihoo.workflow.server.WorkflowContext;


public class ApplicationConfig implements WorkflowConfig
{
	public ApplicationConfig(WorkflowContext context)
	{
		this.context=context;
	}
	
	/**
	 * The WorkflowContext instance with which we are associated.
	 */	
	private WorkflowContext context;
	
	/**
	 * The  initialization parameters for this WorkflowContext.
	 */
	private Hashtable parameters = new Hashtable();
	
	/**
	 * The string manager for this package.
	 */
	private static final StringManager sm = StringManager.getManager(Constants.PACKAGE);
	

	public String getWorkflowName()
	{
		return null;
	}
	
	public WorkflowContext getWorkflowContext()
	{
		return context;
	}

	/**
	 * Return the value for the specified config initialization
	 * parameter name, if any; otherwise return <code>null</code>.
	 *
	 * @param name Name of the parameter to return
	 */
	public String getInitParameter(String name)
	{
		return (String)parameters.get(name);
	}

	/**
	 * Return the names of all defined context initialization parameters
	 * for this config. 
	 */
	public Enumeration getInitParameterNames()
	{
		return parameters.keys();
	}
	
	/**
	 * Add a new context initialization parameter.
	 *
	 * @param name Name of the new parameter
	 * @param value Value of the new  parameter
	 *
	 * @exception IllegalArgumentException if the name or value is missing,
	 *  or if this context initialization parameter has already been
	 *  registered
	 */
	public void addInitParameter(String name, String value)
	{	
		// Validate the proposed context initialization parameter
		if ((name == null) || (value == null))
		{
			throw new IllegalArgumentException(sm.getString("scriptConfig.parameter.required"));
		}
		if (parameters.get(name) != null)
		{
			throw new IllegalArgumentException(sm.getString("scriptConfig.parameter.duplicate", name));
		}

		// Add this parameter to our defined set
		synchronized (parameters)
		{
			parameters.put(name, value);
		}
	}
}
