Search code examples
javastringswingcorba

How to store CORBA objects in DefaultMutableTreeNode (Java Swing)?


I know some time ago I asked almost the same question, but I have a new problem that is very similar - but the solution you people gave me then doesnt work now :(

I have an IDL interface:

interface User {
    string toString();
    //..
};

interface Group {
    typedef sequence<User> Users;
    Users getUsers();

};

When I translated it to C++ I got something like this:

// ...
Group::Users* GroupImpl::getUsers()
{
    // ..return sequence of 'User'-objects
}

On client side (written in Java) I want to show my users. I do something like this:

public void showAllUsers() {
    User[] users = interface_obj.getUsers();
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Main Node");
    for(int i=0; i<users.length;i++) {
        User u = users[i];
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(
            ((UserView)u).getUser());
        root.add(node);
    }

    treeForumReview.setModel(new DefaultTreeModel(root));
}

Of coure, I have a class:

public class UserView {

        private final User f;

        private UserView(User f) {
            this.f = f;
        }

        public Forum getUser() {
            return this.f;
        }

        @Override
        public String toString() {
            String ret = null;
            ret = this.f.getName();
            return ret;
        }
    }

But when running all this I get a message:

Error message

When I do this like I wrote, I see only IORs of my Users-object:

IOR :0123405948239481293812312903891208320131293812381023
IOR: 0092930912617819919191818173666288810010199181919919

and so on ...

How to make it that way, to see their toString() representation in DefaultMutableTreeNode? I dont want to do this:

model.addElement(users[i].toString());

thats not the point. When I use RMI instead of CORBA, model.addElement(users[i]); is exactly what I need cause I see users string representation. But I need to use CORBA and store in DefaultMutableTreeNode corba-user-objects, not strings. Please, help.


Solution

  • solved it:

                if (users != null) {
                    for (User f : users) {
                        UserView fv = new UserView(f);
                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(fv);
                        root.add(node);
                    }
                }