content top

Two iDogs rock on stage

Two iDogs rock on stage

We got two new tech pets over the holidays, two iDogs. These cool little toys look very Apple-style but were originally made by SEGA and are now distributed by Hasbro and others. You could use an iDog simply as a speaker for you iPod (or any other MP3-player – in case there are still other players out there) but it is so much more.

Read More

JavaOne SwiXML presentation online

Finally, Sun posted PDF formatted session documentation of all JavaOne 2005 sessions here:
http://developers.sun.com/learning/javaoneonline/2005/

Even if you went to JavaOne, you probably missed Hans Muller’s Defining Swing GUIs Declaratively session and his take on Swixml. The PDF version of his slides is now available here:
http://www.swixml.org/TS-7122.pdf

Read More

How private are private fields after all?

How private are private fields after all?

Last week, I sent the following brain teaser:

public class Foo {
private int secret = 47;
public Foo() {
new Hacker().hack(this);
}
public String tellSecret() {
return String.valueOf(secret);
}
public static void main(String[] args) {
System.out.println(''How secret are private members? ..'');
System.out.println(''Psst: '' + new Foo().tellSecret();
}
}

Can you write a void hack(Object obj) method that would change foo’s private member variable, so that the output looked like this?

Psst: 74

A sharp developer came up with this solution:

class Hacker {
public void hack (Object o) {
try {
Field f = o.getClass().getDeclaredField( ''secret'' );
f.setAccessible( true );
f.setInt( o, 74 );
} catch ( Exception e ) {
e.printStackTrace();
}
}
}

Now there you have it. Just because a member is declared private doesn’t mean it cannot be changed from outside.

Not only to emphasize this but also because it was more convenient, up to now, Swixml was only able to map public members.

FYI:
Swixml is a small GUI generating engine for Java applications and applets. Graphical User Interfaces are described in XML documents that are parsed at runtime and rendered into javax.swing objects.

While parsing an XML layout descriptor, the SwingEngine instantiates all the Components and assembles the GUI tree. In case a tag was given an idattribute, the SwingEngine will also put a reference to the instantiated object into an idmap. After all this is done, the SwingEngine introspect the class of a provided client object, 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 Swixml 1.5 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++) {
Object widget = idmap.get( flds[i].getName() );
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() );
}
}
Read More

Why in the world would you think your cell phone would work in your house?

Why in the world would you think your cell phone would work in your house?

This obviously rhetorical question was asked by Ivan Seidenberg, Verizon‘s CEO.

During a short trip to San Francisco last week, I stayed at the stunning Hyatt Regency San Francisco (thanks to a great deal I got on HotWire). The biz section of the morning newspaper, the San Francisco Chronicle had an interview with Verizon’s CEO that I found rather interesting.

Seidenberg seriously complained about his customers’ unrealistic expectations about having the wireless service working everywhere. “Why in the world would you think your (cell) phone would work in your house?” he said. It would not be Verizon’s responsibility to correct the misconception by giving out statistics on how often Verizon’s service works inside homes or by distributing more detailed coverage maps, showing all the possible dead zones.

Can you hear me now? :-)
Read the whole story for yourself, it was published in the San Franciso Chronicle on Saturday, April 16, 2005 and is available online here:http://sfgate.com/cgi-bin/article.cgi?file=/c/a/2005/04/16/BUGJ1C9R091.DTL

Read More

Wetsuit for the Gs

Current weather conditions here in Southern California made me buy a wetsuit for the PowerBook.
We had more than enough of rain during the last couple of weeks and carrying an unprotected PowerBook outside, even for just the short distance between the office building and the car, was sometimes not an option.
Finding a suitable bag for the huge 17″ model is not that easy but once I saw the Tucano Second Skin folder; there was no way back. I got a black one for the PowerBook and a red one for the iBook.
Both laptop sleeves fit perfectly and look terrific. The bags are made in Taiwan but were designed by Tucano in Milano Italy and that really shows.
Looks like these cool sleeves are really hard to find – I got one at the UCSD Bookstore and the other one at Amazon – just search for Tucano.

17″PB • Tucano 2nd Skin Folder

12″iB • Tucano 2nd Skin Folder


Two Apples, gone surfin’ • the PB took the long board ..


Read More
content top