commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "RODRIGUEZ Eric" <eric.rodrig...@cetelem.be>
Subject Betwixt and collections
Date Mon, 20 Mar 2006 09:04:11 GMT
Hi all,

I'm sorry if this may seem to you a classic (dummy) question but I get some difficulties to
get working betwixt with collections.
Basically, my problem is with List  I got a userlist with "boys" and "girls" list, and I want
to be populated in the right way.
I get lost in the documentation to find a example on how to handle correctly the "addDefaults"
or "updater" settings.
What should I use to ensure that boys entries are added to boys List (and girls to girls List).

Sorry if this may seem too simple but I tried several betwixt-config files and .betwixt but
I can't get this working properly.

Thanks for any help or comments or links.

Eric Rodriguez


Here are my test classes:
Betwixt Write:
        UserList userList = Factory.getData();
        FileWriter outputWriter = new FileWriter(new File("users.xml"));
        outputWriter.write("<?xml version='1.0' ?>");

        BeanWriter beanWriter = new BeanWriter(outputWriter);
        beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        beanWriter.getBindingConfiguration().setMapIDs(false);
        beanWriter.enablePrettyPrint();

        beanWriter.write("users", userList);

        outputWriter.close();

Betwixt XML out:
<?xml version='1.0' ?>  <users>
    <boys>
      <User>
        <name>Boy 1</name>
      </User>
      <User>
        <name>Boy 2</name>
      </User>
    </boys>
    <girls>
      <User>
        <name>Girl 1</name>
      </User>
      <User>
        <name>Girl 2</name>
      </User>
    </girls>
    <userListName>User List</userListName>
  </users>


Betwixt Read:
        FileReader xmlReader = new FileReader(new File("users.xml"));
        BeanReader beanReader = new BeanReader();

        beanReader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
        beanReader.getBindingConfiguration().setMapIDs(false);
        
        beanReader.registerBeanClass("users", UserList.class);
        UserList userList = (UserList) beanReader.parse(xmlReader);



UserList
public class UserList {

    private String userListName;

    private ArrayList girls;

    private ArrayList boys;

    public UserList() {
        this.girls = new ArrayList();
        this.boys = new ArrayList();
    }

    public ArrayList getBoys() {
        return boys;
    }

    public void setBoys(ArrayList boys) {
        this.boys = boys;
    }

    public ArrayList getGirls() {
        return girls;
    }

    public void setGirls(ArrayList girls) {
        this.girls = girls;
    }

    public String getUserArrayListName() {
        return userListName;
    }

    public void setUserArrayListName(String userListName) {
        this.userListName = userListName;
    }
    
    public void addBoy(User user) {
        this.boys.add(user);
    }
    public void addGirl(User user) {
        this.girls.add(user);
    }

}

User
public class User {

    private String name;

    public User() {
        super();
    }

    public User(String userName) {
        this.name = userName;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}


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