commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitry Beransky" <>
Subject [digester] converting resource uri to an object
Date Tue, 05 Dec 2006 17:07:48 GMT

Could you guys tell me if I'm doing this right?..

for the following fragment:

      <action class="csaswing.action.MoveToFirstRowAction">

I need to end up with roughly this sequence:

1. JMenu menu = new JMenu();
2. JMenuItem item = new JMenuItem();
3. Action action = new MoveToFirstRowAction();
4. Icon icon = new ImageIcon(getClass().getResource("/resources/pics/top.png"));
5. action.putValue(Action.SMALL_ICON, icon);
6. item.setAction(action);
7. menu.add(item);

and here's how I've implemented it:

   digester.addObjectCreate("*/menu/item", "javax.swing.JMenuItem", "class");
   digester.addObjectCreate("*/menu/item/action", null, "class");

   digester.addCallMethod("*/menu/item/action/title", "putValue", 2,
new Class[] {String.class, Object.class});
   digester.addObjectParam("*/menu/item/action/title", 0, Action.NAME);
   digester.addCallParam("*/menu/item/action/title", 1);
   digester.addRule("*/menu/item/action/icon", new IconRule());

   digester.addSetNext("*/menu/item/action", "setAction");

where IconRule is:

class IconRule extends Rule {
     Icon icon;

     public void body(String ns, String name, String text) throws Exception {
         icon = new ImageIcon(MenuBuilder.class.getResource(text));

     public void end(String string, String string1) throws Exception {
         ((Action)getDigester().peek()).putValue(Action.SMALL_ICON, icon);

My custom icon rule bugs me a little bit, but I'm not sure why.  Is
there a better, cleaner way of implementing this whole thing?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message