/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.module;

import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.util.xml.*;
import com.silverwrist.dynamo.except.*;

class ConfigData implements ModuleConfigurationData
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private Hashtable m_store = new Hashtable();

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  ConfigData(Element elt) throws ConfigException
  {
    XMLLoader loader = XMLLoader.get();
    try
    { // get a list of all <item/> sub-elements
      List l = loader.getMatchingSubElements(elt,"item");
      Iterator it = l.iterator();
      while (it.hasNext())
      { // get each <item/> and decode it
	Element n = (Element)(it.next());
	String tmp = loader.getAttribute(n,"ns");
	Hashtable tab = (Hashtable)(m_store.get(tmp));
	if (tab==null)
	{ // create a Hashtable for this namespace
	  tab = new Hashtable();
	  m_store.put(tmp,tab);

	} // end if

	tmp = loader.getAttribute(n,"name");
	tab.put(tmp,loader.getText(n));

      } // end while

    } // end try
    catch (XMLLoadException e)
    { // translate XML loader exception
      throw new ConfigException(e);

    } // end catch

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Implementations from interface ModuleConfigurationData
   *--------------------------------------------------------------------------------
   */

  public String getValue(String namespace, String name)
  {
    Hashtable tab = (Hashtable)(m_store.get(namespace));
    if (tab==null)
      return null;
    return (String)(tab.get(name));

  } // end getValue

} // end class ConfigData
