commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hanson, Anthony (ITD)" <>
Subject Re: trouble mapping XML to HashMap
Date Thu, 20 Jan 2005 15:20:24 GMT
I am writing a component that takes an XML stream from the database then
uses betwixt to build a bean. The bean has two read only properties which
are mapping fine. The problem is mapping the HashMap. The problem is the
add/set method. Stepping through the code, I can see the registerBeanClass
doesn't invoke either method.
<displayName>Hanson, Anthony MD</displayName>
<entry className="java.util.HashMap">
<entry className="java.util.HashMap">
I created the class and created this xml file using the beanwriter (except
for the className attribute). This was exactly the file I was starting with
except for the element names so I modified my file to match what the
beanwriter was creating.
import java.util.*;
public class User {
    private String displayName;
    private String userID;
    private HashMap security;
    public User() {}
    public User(String userID,String displayName,HashMap security) {
       // setSecurity(security);
    public java.lang.String getDisplayName() {
        return displayName;
    public void setDisplayName(java.lang.String displayName) {
        this.displayName = displayName;
    public java.lang.String getUserID() {
        return userID;
    public void setUserID(java.lang.String userID) {
        this.userID = userID;
    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append("User[name='" + displayName + "',userid='" + userID +
        if (security == null){
            return sb.toString();
        Set mappings = security.entrySet();
        for (Iterator i = mappings.iterator(); i.hasNext();) {
            Map.Entry me = (Map.Entry);
        return sb.toString();
    public boolean isAuthorized(String module,int secLevel) {
        Integer secModule = (Integer)security.get(module);
        if((secModule.intValue() & secLevel) == secLevel){
            return true;
            return false;
    public java.util.HashMap getSecurity() {
        return security;
//    public void setSecurity(java.util.HashMap security) {
// = security;
//    }
        public void addSecurity(java.util.HashMap security) {;
The latest thing I tried was setting the className attribute and using it
for the add method. Here is the code I call the write the bean. Please tell
me what I'm doing wrong.
            //sb is a string buffer containing the xml returned from the
            String result = sb.toString();
            StringReader xmlReader = new StringReader(result);
            // Now convert this to a bean using betwixt
            // Create BeanReader
            BeanReader beanReader  = new BeanReader();
            beanReader.registerBeanClass("User",   User.class);
            User user = (User) beanReader.parse(xmlReader);
            System.out.println(user); //only prints the displayname and

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