Wolf Paulus

Journal

Navigation Menu

By Developers For Developers

Posted by on Jan 21, 2009 in Software

It’s Code Camp time again in Southern California and lots of Coders, Programers, Engineers, Geeks, and Hackers will meet at the California State University Fullerton this coming Saturday and Sunday, January 24 and 25.
Code Camp is a community driven event for developers of all platforms, programming languages and disciplines – well that’s the idea at least. Looking at the session table, one cannot shake the feeling that .netasp.netAzure and Silverlight seem a little over represented – but there are also a couple platform independent, embedded, and Java specific talks scheduled as well.
My sessions: Turning a WiFi Router into a general-purpose Network Device and Java UI Generation at Runtime with SwiXML have been scheduled to take place on Saturday, before dinner. I hope to see you Saturday afternoon at the CSFU Campus in H-123 … when you Twitter about the event, please use #SoCalCodeCamp in your tweet so we can track.

Turning a WiFi Router into a general-purpose Network Device

CSFU Campus, H 123, Sat. 01/24/2009, 3:45 – 5:00 PM

Embedded systems are increasingly present in our life and quite a few of them can be repurposed (a.k.a. hacked), to make them even more useful.
The purpose of this session is to have fun and give you some inside of what’s involved in turning a $30 wireless router into a general purpose embedded network device, running the LINUX OS and a full featured Java Runtime environment.
We will take a closer look at some popular Router OS distributions, like OpenWrt, DD-WRT, FreeWRT, Tomato, or X-Wrt and show how to flash the Fonera (FON) WiFi router with a vanilla OpenWrt distribution. The FON is a very small, relatively simple, and inexpensive router, built on the AR531x/231x Atheros WiSoC (Wireless System-on-a-Chip) with an integrated 32-bit MIPS R4000-class processor running at 183.5 MHz, comes with 8 Mbytes Flash Memory and 16 MByte RAM. In short, it has all the attributes required to be added our digital playground.

Embedded OS Development / Kernel Architecture, Implementation and port for Embedded Systems
OpenWrt is a Linux distribution optimized especially for embedded devices and surprisingly, the OpenWrt kernel configuration is done with the help of a character based UI. OpenWrt also comes with a lightweight package management system (IPKG or more recently OPKG), meaning that features that have not already been built into the kernel, can be added later, at runtime. As an example, we will take a look at how a JavaVM could be built, packaged, and deployed, or built directly into the kernel.

Java UI Generation at Runtime with SwiXML

CSFU Campus, H 123, Sat. 01/24/2009, 2:30 – 3:45 AM

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. Theoretically, you can look at SwiXML as an XML based domain-specific language, allowing to declare Java Swing GUIs. The SwiXML engine will then later at runtime, take a GUI declaration and create that User-Interface on the fly, just like a Web Browser would do with an HTML document.
SwiXML doesn’t introduce any new layout managers or component classes. Instead, it operates directly on the Swing component classes using introspection.

Read More

XML Schema for Swixml

Posted by on Mar 3, 2007 in Java

Writing a Swixml declaration file is not that hard, if you know your javax.swing components. However, getting a little support from your XML-Editor or IDE certainly doesn’t hurt.
Getting IntelliSense help sometimes doesn’t require much more than pointing your editor to a DTD or XML Schema to pop-up element and attribute names as needed; or simply adding an xsi:schemaLocation attribute to the root element might do the trick.
Anyway, I’ve generated the XML-Schema for all built-in Swixml elements and attributes and made it available here: http://www.swixml.org/2007/swixml.xsd
It is complete, concerning elements and their attributes, and while the schema already has more than 2700 lines (which tells a story about the complexity of Swing), it does not include containment-rules, e.g. that you shouldn’t add a button into a label, nor does it validate the attribute values other than booleans.

<?xml version=”1.0″ encoding=”UTF-8″?>

<frame xmlns=”http://www.swixml.org/2007/SwixmlTags” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://www.swixml.org/2007/SwixmlTags http://www.swixml.org/2007/swixml.xsd”>

….

</frame>

After that’s done, some tool may make writing the descriptors somewhat easier. Oxygen XML Editor for instance has code competitions for elements and attributes:

With IntelliJ-IDEA on the other hand, even after registering the URI in System/Settings/Resources, I could only get completion for elements but not for the attributes to work:

Give it a try and let me know what you think and how we should improve the xsd. Again, the schema can be downloaded here: http://www.swixml.org/2007/swixml.xsd
The XML-Schema for Swixml is obviously generated using Java Reflection and the code will be made available in the upcoming Swixml 1.6. The cool thing about this is that you can generate your own XSD after you have registered all your own and 3rd party components. That way your Schema will allow you to use IntelliSense on your own elements just like it works on the built-in ones.

Read More

By Developers For Developers No Fluff only Code

Posted by on Jan 23, 2007 in Software

It’s Code Camp time again in Southern California and lots of Coders, Programers, Engineers, etc will meet at the Cal State Fullerton Campus this coming Saturday and Sunday, January 27 and 28.
Code Camp is a community driven event for developers of all platforms, programming languages and disciplines – well that’s the idea at least. Looking atsession table, one cannot shake the feeling that .net seems a little over represented but there are also a couple platform independent, embedded, and Java specific talks scheduled as well.
My sessions: Arduino Fever – PHYSICAL COMPUTING and Declarative Programming, emphasizing UI Generation at Runtime have been scheduled to take place on Saturday, right after Code Camp Welcome.
See you Saturday morning at the CSFU Campus in UH248 …

Arduino Fever – PHYSICAL COMPUTING

CSFU Campus, UH248, Sat. 01/27/2007, 9:00 – 10:15 AM

The Arduino project was created to provide access to the essence of digital technologies and has contributed a remarkable set of open-source tools, ideal to conduct courses in electronics prototyping. Today, more than 20 universities are using Arduino in their programs and engineering classes, several open source communities have welcomed Arduino as their platform for interfacing the physical world, and the Arduino project has expanded into secondary education in schools allover Europe. This session provides a hands-on introduction to Arduino platform. We will focus on sensors and actuators and take a look at how a computer converts inputs (in the form of sound, light, motion, and other forms) into changing electronic signals that it can interpret. No previous knowledge in electronics is required. However, participants should bring an open mind for a challenging time with a hand full of bytes.

Declarative Programming, emphasizing UI Generation at Runtime

CSFU Campus, UH248, Sat. 01/27/2007, 10:30 – 11:45 AM

Graphical User Interfaces are described in XML documents that are parsed at runtime and rendered into UI-Widgets. While open-source projects likeThinlet and Swixml focus mainly on the GUI, they are also good examples for how declarative programming can be done in Java. Find out more at http://www.swixml.org Read what your peer are saying about declarative programming and swixml at http://www.swixml.org/opinion.html

Read More

How private are private fields after all?

Posted by on Jun 14, 2005 in Java

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