org.apache.cocoon.forms.util
Class ContainerWidgetAsMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by org.apache.cocoon.forms.util.ContainerWidgetAsMap
All Implemented Interfaces:
Map

public class ContainerWidgetAsMap
extends AbstractMap

A Map view of a container widget, keys being children names and values either maps (for container children), objects (for terminal children) or lists (for repeaters).

The returned map is non-modifiable, except using the put() method, which much refer to an existing child widget, and putAll(Map) that will silently ignore keys that don't refer to existing child widgets.

Also, this map accepts getting and setting values for keys that correspond to value-less widgets such as Action. The result in that case is always null. This is to allow global retrieving or filling of the map values.

Since:
2.1.8
Version:
$Id: ContainerWidgetAsMap.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  AbstractContainerWidget container
           
 
Constructor Summary
ContainerWidgetAsMap(AbstractContainerWidget container)
          Same as ContainerWidgetAsMap(container, false)
ContainerWidgetAsMap(AbstractContainerWidget container, boolean keysToLowerCase)
          Wraps a container widget in a Map.
 
Method Summary
 Set entrySet()
           
 Object get(Object key)
           
 ContainerWidget getWidget()
          Get the container widget that is wrapped by this Map.
 Widget getWidget(String path)
          Get a widget relative to the container wrapped by this Map
 Object put(Object key, Object value)
          Put a value in a child widget.
 void putAll(Map map)
           
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

container

protected AbstractContainerWidget container
Constructor Detail

ContainerWidgetAsMap

public ContainerWidgetAsMap(AbstractContainerWidget container,
                            boolean keysToLowerCase)
Wraps a container widget in a Map.

The keysToLowerCase argument specifies if input keys given in get(), put() and putAll() should be converted to lower case before searching for the corresponding widget. This feature allows to directly feed widgets with Maps coming from JDBC resultset rows where keys are uppercase (see JDBI).

Parameters:
container - the container to wrap
keysToLowerCase - should we convert keys to lower case?

ContainerWidgetAsMap

public ContainerWidgetAsMap(AbstractContainerWidget container)
Same as ContainerWidgetAsMap(container, false)

Method Detail

getWidget

public ContainerWidget getWidget()
Get the container widget that is wrapped by this Map.

Returns:
the wrapped ContainerWidget

getWidget

public Widget getWidget(String path)
Get a widget relative to the container wrapped by this Map

Parameters:
path - a widget lookup path
Returns:
the widget pointed to by path or null if it doesn't exist.
See Also:
Widget.lookupWidget(String)

put

public Object put(Object key,
                  Object value)
Put a value in a child widget. The value must be compatible with the datatype expected by the child widget. In the case of repeaters and containers, this datatype is Collection and Map respectively, which will be used to fill the rows and child widgets.

Note also that the contract of put requires the previous value to be returned. In the case of repeaters and containers, the value is a live wrapper around the actual widget, meaning that it's not different from the current value.

Specified by:
put in interface Map
Overrides:
put in class AbstractMap

putAll

public void putAll(Map map)
Specified by:
putAll in interface Map
Overrides:
putAll in class AbstractMap

get

public Object get(Object key)
Specified by:
get in interface Map
Overrides:
get in class AbstractMap

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.