Hi Raman, What you wrote is not 100% right, since Context *extends Map<String, Object>*, so a correct assignment would be:
Context context = new MyContextImpl(); Context is able to store object identified by a key; let's assume you store there your DataSource: DataSource dataSource = ... ; ... context.put("datasource", dataSource); That needs to be retrieved in a Command during the chain execution; the difference is by invoking `get` Object obj = context.get("datasource"); DataSource dataSource = (DataSource) obj; And `retrieve` DataSource dataSource = context.retrieve("datasource"); That is able to 'auto-cast' the retrieved object while Map#get() not. HTH, have a nice day! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Sun, Sep 4, 2011 at 9:31 PM, Raman Gupta <rocketra...@fastmail.fm> wrote: > On 09/04/2011 05:22 AM, Simone Tripodi wrote: >> Hi all guys, >> I think that generics could help us on improving the Context class; >> I'm not particularly happy having it extending Map - it is needed >> anyway for backward compatibility - but it is clear that Context is a >> place where storing/retrieving objects identified by a key. >> I propose adding two helper methods >> >> /** @since 2.0 */ >> <T> T retrieve( String key ); >> >> /** @since 2.0 */ >> <T> void store( String key, T object ); >> >> that would help users avoid the redundant code of type cast/checking >> when assignments are already known (it throws a ClassCastException if >> types are not assignable). >> At the same time, old pattern is supported, users can choose their >> preferred way to go, depending on their needs. >> WDYT? > > Just curious -- what is the advantage of these two new methods over using: > > Context<String,Object> context = ... > > context.get(k); > context.put(k, v); > > Cheers, > Raman > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > For additional commands, e-mail: dev-h...@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org