/*
 * 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) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.dynamo.servlet;

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

class RemapperElement
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private String m_path;
  private String m_target;
  private String m_target_type;
  private Set m_param_names;
  private Map m_param_defaults;

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

  RemapperElement(Element elt) throws XMLLoadException
  {
    XMLLoader loader = XMLLoader.get();
    m_path = loader.getAttribute(elt,"path");
    Element target_elt = loader.getSubElement(elt,"target");
    m_target = loader.getText(target_elt);
    m_target_type = loader.getAttribute(elt,"type","SERVLET").toUpperCase();

    // Load the parameter names and default values.
    HashSet names = new HashSet();
    HashMap defaults = new HashMap();
    List l = loader.getMatchingSubElements(elt,"param");
    Iterator it = l.iterator();
    while (it.hasNext())
    { // get each <param/> element and store it
      Element x = (Element)(it.next());
      String s = loader.getAttribute(x,"name");
      names.add(s);
      DOMElementHelper h = new DOMElementHelper(x);
      String v = h.getElementText();
      if (v!=null)
	defaults.put(s,v);

    } // end while

    m_param_names = Collections.unmodifiableSet(names);
    m_param_defaults = Collections.unmodifiableMap(defaults);

  } // end constructor

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  String getPath()
  {
    return m_path;

  } // end getPath

  Map getDefaults()
  {
    return m_param_defaults;

  } // end getDefaults

  String getLinkType()
  {
    return m_target_type;

  } // end getLinkType

  String getTemplate()
  {
    return m_target;

  } // end getTemplate

  Set getParamNames()
  {
    return m_param_names;

  } // end getParamNames

} // end class RemapperElement
