You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by st...@jakarta.apache.org on 2004/04/09 06:58:23 UTC

[Apache Struts Wiki] New: StrutsCatalogInstrumentableForms

   Date: 2004-04-08T21:58:17
   Editor: 131.191.40.91 <>
   Wiki: Apache Struts Wiki
   Page: StrutsCatalogInstrumentableForms
   URL: http://wiki.apache.org/struts/StrutsCatalogInstrumentableForms

   no comment

New Page:

StrutsCatalog: '''Provide a multipurpose form that can be instrumented.'''

This class allows you to instrument your !ActionForms and use them as dynamic property setters and getters as well.  (The size 89 is chosen because the series created by x = 2x + 1 stays prime for a considerable time.  This is far preferrable to the default !HashMap behavior.)  You don't have to use this as a form, of course.  You can use it just for the dynamic property setters and getters and instrument these as you like.  

{{{   
public class BeanMapForm extends ActionForm implements Map {
  private Map map;

  public BeanMapForm() {
    int size = 89;
    this.map = Collections.synchronizedMap(new HashMap(size));
  }

  public void setMap(Map map) {
    this.map = map;
  }

  public void setProperty(Object key, Object value) {
    map.put(key,value);
  }

  public Object getProperty(Object key) {
    return map.get(key);
  }

  public void       clear()                       { map.clear(); }
  public boolean    containsKey(Object key)       { return map.containsKey(key);}
  public boolean    containsValue(Object value)   { return map.containsValue(value); }
  public Set        entrySet()                    { return map.entrySet(); }
  public boolean    equals(Object object)         { return map.equals(object); }
  public Object     get(Object key)               { return map.get(key); }
  public int        hashCode()                    { return map.hashCode(); }
  public boolean    isEmpty()                     { return map.isEmpty(); }
  public Set        keySet()                      { return map.keySet(); }
  public Object     put(Object key, Object value) { return map.put(key,value); }
  public void       putAll(Map map)               { map.putAll(map); }
  public Object     remove(Object key)            { return map.remove(key); }
  public int        size()                        { return map.size(); }
  public Collection values()                      { return map.values(); }
  public String     toString()                    { return map.toString(); }
} ///;-)
}}}
-- Michael !McGrady

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org