The best way to to this is to create a custom command and use hookHelper to get the handle to the MapBean from within your command code. The HookHelper will give you the focus map that you can cast to IDynamicMap:

IDynamicMap dynamicMap = (IDynamicMap)hookHelper.getFocusMap();

The following example code comes from the Engine Java SDK sample called Display.CustomLayer.DynamicDisplay. It's the source for a custom command. Please refer to the onClick method. I hope this is helpfull...