commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc DEXET <Marc.De...@dsi.cnrs.fr>
Subject [betwixt] Collection and elements
Date Thu, 03 Mar 2005 14:41:49 GMT
Hi guys.
I belevied I was mastering betwixt : I was wrong.
Look at this :
I get a class NameBunch :
- - - - - - - - - - - - - - - - 
public class NameBunch  {
    
    private String name;
    private ArrayList sqlNames;
    
    public NameBunch(){
        sqlNames = new ArrayList();
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public ArrayList getSqlNames() {
        return sqlNames;
    }
    
    public void addSqlName(String sqlName) {
        getSqlNames().add(sqlName);
    }
}
- - - - - - - - - - - - - - - - 
An input file like this :

<?xml version="1.0" encoding="UTF-8" ?>
  <bunch name="bunch_name">
    <sql>sql_name0</sql>
    <sql>sql_name1</sql>
    <sql>sql_name2</sql>
  </bunch>

I have tried many betwixt file, but I can't make betwixt add sql content.
What do you think it' wrong with 

<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="element">
    <element name="bunch">
        <attribute name="name" property="name"/>
        <element name="sql" property="sqlNames" updater="addSqlName"/>
    </element>
</info>

-- 
UnitTest method :


    public void testReadBetwixt() throws IntrospectionException,
IOException, SAXException {
        String xml = 
            "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"+
            "<bunch name=\"bunch_name\">"+
            "<sql>sql_name0</sql>"+
            "<sql>sql_name1</sql>"+
            "<sql>sql_name2</sql>"+
            "</bunch>";
        
        BeanReader reader = new BeanReader();
        reader.registerBeanClass(NameBunch.class);
        Object obj = reader.parse( new StringReader(xml) );
        assertTrue( obj instanceof NameBunch );
        NameBunch nb = (NameBunch) obj;
        assertEquals("bunch_name",nb.getName());
        assertFalse("is empty",nb.getSqlNames().isEmpty());
        assertTrue("sql_name0",nb.getSqlNames().contains("sql_name0"));
        assertTrue(nb.getSqlNames().contains("sql_name1"));
        assertTrue(nb.getSqlNames().contains("sql_name2"));


-- 
Marc DeXeT
CNRS/DSI/BEST
<http://www.dsi.cnrs.fr>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message