SwiXml 1.5 (#144) has been released
[email protected] Sat, 4 Jun 2005 18:07:20 -0700
| Newsgroups | gmane.comp.embedded.carlsbad-cubes |
|---|---|
| Message-ID | <[email protected]> |
June 4, 2005 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
707.202.3937
[email protected]
C a r l s b a d C u b e s
Dedicated to Excellence
CONFIDENTIALITY NOTICE:
This message is intended only for the use of the individual or entity
to which it is addressed, and may contain information that is
privileged, confidential and exempt from disclosure under applicable
law. If you are not the intended recipient, please contact the sender
by reply email and destroy all copies of the original message.