public class MapModel extends StringModel implements TemplateMethodModelEx
A special case of
BeanModel that adds implementation
TemplateMethodModelEx on map objects that is a shortcut for the
Map.get() method. Note that if the passed argument itself is a
reflection-wrapper model, then the map lookup will be performed using the
wrapped object as the key. Note that you can call get() using the
map.key syntax inherited from
BeanModel as well,
however in that case the key is always a string.
The class itself does not implement the
You can, however use map.entrySet(), map.keySet(), or
map.values() to obtain
TemplateCollectionModel instances for
various aspects of the map.
|Constructor and Description|
Creates a new model that wraps the specified map object.
|Modifier and Type||Method and Description|
The first argument is used as a key to call the map's get method.
Overridden to invoke the generic get method by casting to Map instead of through reflection - should yield better performance.
Tells whether the model is empty.
Helper method to support TemplateHashModelEx.
get, getAdaptedObject, getAPI, getWrappedObject, hasPlainGetMethod, keys, toString, unwrap, values, wrap
public MapModel(Map map, BeansWrapper wrapper)
map- the map object to wrap into a model.
BeansWrapperassociated with this model. Every model has to have an associated
BeansWrapperinstance. The model gains many attributes from its wrapper, including the caching behavior, method exposure level, method-over-item shadowing policy etc.
public Object exec(List arguments) throws TemplateModelException
TemplateModel-s, containing the arguments passed to the method. If the implementation absolutely wants to operate on POJOs, it can use the static utility methods in the
DeepUnwrapclass to easily obtain them. However, unwrapping is not always possible (or not perfectly), and isn't always efficient, so it's recommended to use the original
TemplateModelvalue as much as possible.
null. If the returned value does not implement
TemplateModel, it will be automatically wrapped using the
environment's object wrapper.
protected TemplateModel invokeGenericGet(Map keyMap, Class clazz, String key) throws TemplateModelException
public boolean isEmpty()
public int size()
protected Set keySet()