SwiXML 1.5 (Build#144) Now Out - Build Java Swing Apps Using XML

Gerald Bauer <[email protected]> Mon, 06 Jun 2005 12:01:16 -0700
Newsgroups gmane.comp.lang.xul.announce
Message-ID <[email protected]>
Hello,

   Wolf Paulus writes in the posting titled "SwiXml 1.5 (#144) has been 
released":

The new release contains all bug fixes that were available through  the 
CVS version over at java.net (https://swixml.dev.java.net/).  Moreover, 
automatic mapping (Swixml tags to client objects members)  now works 
with *private* member variables as well. For more details,  check the 
change-log and the discussion in the forum. (http:// 
carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com)

More details about the Automatic Mapping:

While parsing your XML layout descriptor, the SwingEngine  instantiates 
all the Components and assembles the GUI tree.
In case a tag was given an id attribute,  the SwingEngine will also  put 
a reference to the instantiated object into a so-called idmap.
After all this is done, the SwingEngine introspect the class of the  
client object you provided when setting-up the SwingEngine. E.g.

    new SwingEngine( this ).render( "xml/helloworld.xml" ).setVisible ( 
true );

Here "this" points to the client object.

If during this introspection member variables in the client's class  are 
found, whose names match those in the idmap, the SwingEngine maps  the 
reference into the
member variable.

This used to work only with public members. Since this release  however, 
the updated mapping considers ALL member variables in the  whole class 
structure.
This means even members in a super class and its super class ... are  
considered.
BUT, to work consistent with serialization, members flagged as  
"transient" are not mapped automatically.


Mapping works recursively on a client object's class tree like this:

 private void mapMembers(Object obj, Class cls) {
    if (obj != null && cls != null && !Object.class.equals(cls)) {
      Field[] flds = cls.getDeclaredFields();

        for (int i = 0; i < flds.length; i++) {  // loops through  
class' declared fields and try to find a matching widget.
         Object widget = idmap.get(flds[i].getName());

          // field and object type need to be compatible and field  must 
not be declared Transient
          if ( widget != null &&  flds[i].getType().isAssignableFrom 
(widget.getClass()) && !Modifier.isTransient(flds[i].getModifiers())) {
            try {
              boolean accessible = flds[i].isAccessible();
              flds[i].setAccessible(true);
              flds[i].set(obj, widget);
              flds[i].setAccessible(accessible);
            } catch  ..

            }
          }
        }

     mapMembers(obj, cls.getSuperclass());  // getDeclaredFields()  only 
works on the class itself, work recursively the class tree.
    }
  }


-- 
Wolf Paulus 

 


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20