commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dmitry Beransky" <d...@dembel.org>
Subject [digester] setting parent properties after the child's
Date Fri, 01 Dec 2006 22:58:08 GMT
Hi,

I can't figure out how to properly set up rules so that this test does not fail:

    public void testTitle() throws IOException, SAXException {
        String xml = "<menu>\n" +
                "   <item title=\"Copy\">\n" +
                "      <action
class=\"javax.swing.text.DefaultEditorKit$CopyAction\"/>\n" +
                "   </item>\n" +
                "</menu>";

        Digester digester = new Digester();
        digester.addObjectCreate("*/menu", "javax.swing.JMenu", "class");
        digester.addObjectCreate("*/menu/item",
"javax.swing.JMenuItem", "class");
        digester.addObjectCreate("*/menu/item/action", null, "class");
        digester.addSetNext("*/menu/item/action", "setAction");
        digester.addSetProperties("*/menu/item", "title", "text");
        digester.addSetNext("*/menu/item", "add");

        JMenu menu = (JMenu) digester.parse(new StringReader(xml));

        assertEquals("Copy", ((JMenuItem)menu.getMenuComponent(0)).getText());
    }

Result:
   junit.framework.ComparisonFailure:
   Expected :Copy
   Actual  :copy-to-clipboard

The problem is that the rules above result in roughly the following
sequence of calls:

   JMenu menu = new JMenu()
   JMenuItem item = new JMenuItem();
   item.setTitle("Copy");
   Action action = new DefaultEditorKit.CopyAction();
   item.setAction(action);

and setting action on a menu item will override previously set text.
What I need to do is to set the item's text AFTER setting the action:

   JMenu menu = new JMenu()
   JMenuItem item = new JMenuItem();
   Action action = new DefaultEditorKit.CopyAction();
   item.setAction(action);
   item.setTitle("Copy");

any recommendations on how to change digester rules to accomplish that?


Thanks
Dmitry

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


Mime
View raw message