org.barracudamvc.contrib.sam.models
Class MapDecorator

java.lang.Object
  extended by org.barracudamvc.contrib.sam.models.TemplateModelDecorator
      extended by org.barracudamvc.contrib.sam.models.MapDecorator
All Implemented Interfaces:
Contextual, IterativeModel, Model, TemplateModel

public class MapDecorator
extends TemplateModelDecorator

MapDecorator is a Decorator class using the well known decorator pattern.
It modifies the return values of the getItem(TemplateDirective) method of the decorated model using a Map.

Version:
$Id: MapDecorator.java 114 2005-12-09 15:51:51Z christianc $
Author:
Stefan Armbruster

Nested Class Summary
static class MapDecorator.Link
           
static class MapDecorator.StringBoolCompound
           
static interface MapDecorator.UserMapping
          Interface for handling user defined mappings
 
Field Summary
protected static org.apache.log4j.Logger logger
           
protected  Map mapping
           
 
Fields inherited from class org.barracudamvc.contrib.sam.models.TemplateModelDecorator
_templateModel
 
Constructor Summary
MapDecorator(TemplateModel tm)
           
MapDecorator(TemplateModel tm, Map mapping)
          Creates a new instance of MapDecorator
 
Method Summary
 Object getItem(TemplateDirective td)
          getItem first checks, if the is a matching entry in mapping.
 void setMapping(Map mapping)
           
 
Methods inherited from class org.barracudamvc.contrib.sam.models.TemplateModelDecorator
addModelListener, getName, getViewContext, hasNext, loadNext, postIterate, preIterate, processDirective, removeModelListener, setViewContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger

mapping

protected Map mapping
Constructor Detail

MapDecorator

public MapDecorator(TemplateModel tm)

MapDecorator

public MapDecorator(TemplateModel tm,
                    Map mapping)
Creates a new instance of MapDecorator

Parameters:
tm - decorated model
mapping - Table containing the mappings, the keys represent the the keys in the getItem(TemplateDirective) method
Method Detail

setMapping

public void setMapping(Map mapping)

getItem

public Object getItem(TemplateDirective td)
getItem first checks, if the is a matching entry in mapping. If so, the value of the decorated model is modified depending on the type of the mapper entry. The following modifications are possible:
Lookup map, implements Map If the Map contains the value of the underlying model, it is replaced by the value the the lookup map. formatting to a specific numeric format, implements NumberFormat formatting to a specific date format, implements DateFormat formatting to a user defined class, must implement UserMapping returning a BAction, implements ControlEvent If the value of the mapping table is a ControlEvent, a BAction with the ControlEvent as href is returned.

Specified by:
getItem in interface TemplateModel
Overrides:
getItem in class TemplateModelDecorator
Parameters:
td - the template directive
Returns:
modified return value of underlying model


Copyright © 2006 BarracudaMVC.org All Rights Reserved.