/*
 * $Id: DynaForm.java,v 1.11 2007/08/08 12:14:47 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: DynaForm.java,v $
 * Revision 1.11  2007/08/08 12:14:47  marbobo
 * + License-Funktionalität komplett umgeschrieben
 * + Bugfix bzgl. Beschreibungsfelder von Entitäten
 * + Bugfix mailing
 *
 * Revision 1.10  2004/08/20 12:59:56  koppy
 * +getDynaValueMap()
 *
 * Revision 1.9  2004/07/20 08:53:51  jonyp
 * added copyright info + cvs log
 *
 *
 */
package vkc.view.form;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;

/**
 * Implementierung einer map-backed ActionForm für die Behandlung dynamischer
 * Eingaben
 * 
 * @author koppy
 */
public class DynaForm extends BasicActionForm {

    /**
     * Map for the dynamic properties
     */
    private final Map dynaValueMap = new HashMap();

    /**
     * Sets the value of a property
     * 
     * @param name
     *            the name of the property
     * @param value
     *            the value that property shall be set to
     */
    public final void setDynaValue(String name, Object value) {
        dynaValueMap.put(name, value);
    }

    /**
     * Returns the value of a dynamic property
     * 
     * @param name
     *            the name of the property
     * @return value of a dynamic property
     */
    public final Object getDynaValue(String name) {
        return dynaValueMap.get(name);
    }

    /**
     * Returns the value of a dynamic property
     * 
     * @param name
     *            the name of the property
     * @return true if the dynamic property is in map false else
     */
    public final boolean isContainsKey(String key) {
        return dynaValueMap.containsKey(key);
    }

    public final Map getDynaValueMap() {
        return this.dynaValueMap;
    }

    /**
     * Removes a dynamic value
     * 
     * @param name
     *            name of the key of the value to be removed
     * @return the removed value
     */
    public final Object removeDynaValue(String name) {
        return dynaValueMap.remove(name);
    }

    /**
     * Returns an iterator of the dynakeys
     * 
     * @return iterator of the dynakeys
     */
    public final Iterator getDynaKeys() {
        return dynaValueMap.keySet().iterator();
    }

    /**
     * Clears all dynamic properties
     */
    public final void clearDynaValues() {
        dynaValueMap.clear();
    }

    /**
     * Reset all properties to their default values.
     * 
     * @param mapping
     *            The mapping used to select this instance
     * @param request
     *            The servlet request we are processing
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        super.reset(mapping, request);
    }
}