commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Caddel <jcad...@cox.net>
Subject [Chain] ContextToRequestCommand
Date Thu, 06 Nov 2003 04:30:35 GMT
Any feedback on this Command implementation?

The idea is that as a chain of commands is executing objects get 
aggregated into a map.  The context holds a reference to the map.  At 
the tail end of the execution chain, this command places the objects 
from the map into the request as request attributes so that front end 
components (Tiles, JSP's etc) can display them.


Is this:
A) A terrible idea violating abstractions of the Chain of Responsibility 
pattern? 
B) A good idea demonstrating good use of the pattern?
C) Something else?


public class ContextToRequestCommand implements Command {
    String key = "contextToRequest";

    public boolean execute(Context context) throws Exception {
        HttpServletRequest request = 
(HttpServletRequest)context.get("request");
        Map map = (Map)context.get(key);
        if (map == null) {
            return false;
        }

        Iterator pairs = map.entrySet().iterator();
        while (pairs.hasNext()) {
            Map.Entry pair = (Map.Entry)pairs.next();
            request.setAttribute((String)pair.getKey(), pair.getValue());
        }

        return false;
    }
}


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


Mime
View raw message