Feb 25

E4X: Is ECMAScript the glue language we have wanted? It powers the browser VM.

Java, JavaScript, Tech 9 Comments »

JavaScript has a bit of a tough label. Many developers think of it as a hackers web scripting language which is good for alert("foo") and document.*.

The language is really growing up now though, and we have good implementations on the Java side such as Rhino.

Rhino even implements the latest and greatest of ECMAScript: ECMAScript for XML (E4X).

Now, XML is a first class citizen in the language which allows you to do some of the following:

Create a DOM from XML

var order = <order>
<customer>
<firstname>John</firstname>
<lastname>Doe</lastname>
</customer>
<item>
<description>Big Screen Television</description>
<price>1299.99</price>
<quantity>1</quantity>
</item>
</order>

Walk the XML tree a la XPath etc

// Construct the full customer name
var name = order.customer.firstname + " " + order.customer.lastname;

// Calculate the total price
var total = order.item.price * order.item.quantity;

Construct a new XML object using expando and super-expando properties

var order = <order/>;
order.customer.name = "Fred Jones";
order.customer.address.street = "123 Long Lang";
order.customer.address.city = "Underwood";
order.customer.address.state = "CA";
order.item[0] = "";
order.item[0].description = "Small Rodents";
order.item[0].quantity = 10;
order.item[0].price = 6.95;

Playing with SOAP

var message = <soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Body>
<m:GetLastTradePrice xmlns:m="http://mycompany.com/stocks">
<symbol>DIS</symbol>
</m:GetLastTradePrice>
</soap:Body>
</soap:Envelope>

// declare the SOAP and stocks namespaces
var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
var stock = new Namespace ("http://mycompany.com/stocks");

// extract the soap encoding style and body from the soap message
var encodingStyle = message.@soap::encodingStyle;

print("The encoding style of the soap message is specified by:\n" + encodingStyle);

// change the stock symbol
message.soap::Body.stock::GetLastTradePrice.symbol = "MYCO";

var body = message.soap::Body;

Conclusion

It is interesting to see ECMAScript leading the way in some areas. It is an interesting idea to have XML as such as first class citizen. I don’t remember having “tab delimited data” at the same level, and it is a little worrying to think about XML abuse that could occur because of it.

However, maybe it is time to take ECMAScript more seriously. It is installed in all browser VMs so to speak, and with implementations like Rhino, allows you to script Java in a simple way :)

Feb 24

“Those who coded, also coded”

IDE, Java, Tech 8 Comments »

I had a strange dream last night. I won’t go into the details of my warped conciousness, but will talk about one small piece that flashed by.

At one point I was coding using IntelliJ IDEA Eclipse 12.5. As I started to write some code, a panel changed to say “Those who coded with API FOO, went on to do X, Y, Z”. The dream-like, better looking, Dion, then clicked on Y and a bunch of skeleton code was done for me.

Although this is a little out there, I do always come back to the fact that it feels like there are thousands of developers doing their own thing. As a profession, each project is making its own mistakes, and I don’t think we have avenues and ways to learn from eachother. Sure, there are design patterns, and practices which we sometimes share, but isn’t there more?

If there was a way to capture our experiences, it would be great. E.g., in some small ways…. say I started to tie together Tapestry and Spring. My IDE could see that I was doing this, and knows that someone in my social network has also done this, and shows/does this for me. Roll on the AI IDE! ;)

Feb 21

Struts Flow: Continations come to Struts

Java, Tech, Web Frameworks 6 Comments »

Wow, Struts is a huge project:

Today, Struts is comprised of nine subprojects: Core, Taglib, Tiles, El, Faces, Scripting, Applications, Shale, and (now) Flow.

The Struts team just announced Struts Flow which brings a continuations based approach to web flows.

This is interesting stuff, and we have seen continuations popup in other communities such as Ruby, Perl, and Smalltalk.

Seaside was the first web framework that I saw with continuations, and it intrigued me from the beginning. It really does make sense to have the users ’session’ to be the core. In fact, on our projects, we put a lot of functionality there (even if it just ties into the business layers etc).

It will be interesting to see how Struts Flow gets adopted.

Take a look at an example of putting the logic in one workflow, even though web pages are being sent around to get input from the user:

function main() {

var random =  Math.round( Math.random() * 9 ) + 1;
var hint = "No hint for you!"
var guesses = 0;

while (true) {

// send guess page to user and wait for response
forwardAndWait("failure",
{ "random"  : random,
"hint"    : hint,
"guesses" : guesses} );

// process user's guess
var guess = parseInt( getRequestParams().guess );
guesses++;
if (guess) {
if (guess > random) {
hint = "Nope, lower!"
}
else if (guess < random) {
hint = "Nope, higher!"
}
else {
// correct guess
break;
}
}
}

// send success page to user
forwardAndWait("success",
{"random"  : random,
"guess"   : guess,
"guesses" : guesses} );
}

View the Announcement

The Apache Struts team is pleased to announce the adoption of its latest subproject, Struts Flow, a continuations-based approach to complex web workflows. Struts Flow originated at the struts.sf.net project and has been formally adopted now as a Struts subproject. Struts Flow is a port of Apache Cocoon's Control Flow to Struts to allow complex workflow, like multi-form wizards, to be easily implemented using continuations-capable Javascript and eventually Java.

Today, Struts is comprised of nine subprojects: Core, Taglib, Tiles, El, Faces, Scripting, Applications, Shale, and (now) Flow. Struts Flow is different from Struts Scripting/BSF as where Scripting brings any BSF-supported scripting language to Struts Actions, Struts Flow works on redefining the traditional Model 2 state-driven workflow into simplified scripts whose execution spans multiple requests. Currently, the Rhino engine, a Javascript implementation, is used to provide continuations support, but with the maturation of Jakarta Commons Javaflow - http://jakarta.apache.org/commons/sandbox/javaflow - a Java-based continuations implementation, Java will soon be supported as well.

For more information, visit the Struts Flow website at:
- http://struts.apache.org/flow
Feb 21

CharSequence: one of those quiet gems

Java, Tech No Comments »

When is a String not a String?. Simon Harris has brought up the nice CharSequence interface that both Strings and StringBuffers implement.

This means that we can pass around the interface and let us give the implementation later.

Maybe it would be nice to have had ‘String’ be an interface itself, and when you coded: String foo = “bar” it would create an ImmutableString which implements String. Then we could come up with crazy implementations of String :)

However, we would run into a lot of security concerns, as people could sneak in BackdoorStringWhichEmailsMeYourPassword.

Anyway, CharSequence has been a very useful interface for me too, for those cases where I really do want to encapsulate multiple impls.

Feb 21

CharSequence: one of those quiet gems

Java, Tech No Comments »

When is a String not a String?. Simon Harris has brought up the nice CharSequence interface that both Strings and StringBuffers implement.

This means that we can pass around the interface and let us give the implementation later.

Maybe it would be nice to have had ‘String’ be an interface itself, and when you coded: String foo = “bar” it would create an ImmutableString which implements String. Then we could come up with crazy implementations of String :)

However, we would run into a lot of security concerns, as people could sneak in BackdoorStringWhichEmailsMeYourPassword.

Anyway, CharSequence has been a very useful interface for me too, for those cases where I really do want to encapsulate multiple impls.

Feb 17

AspectJ2ME: Using AOP for running J2ME on any phone

AOP, Java, Mobile, Tech 1 Comment »

Michael Yuam explains how Tira Wireless does WORA with Aspect Oriented Programming.

Tira Wireless is a very successful J2ME game porting house with big name customers like Disney and Warner Brothers. It takes J2ME games from developers and port them to more than a thousand handset/wireless operator/language combinations for global distribution. As one would expect, they have intimate knowledge and hands-on experience with many JVM implementations to know how exactly “write once, run everywhere” does not work in J2ME. :) Today, Tira Wireless sent two engineers from Toronto down to Austin on a Sunday to sit down with me and explain to me exactly how their approaches work. To my pleasant surprise, their approach is “aspect oriented programming” using a customized version of Javassist (the same underlying library for JBoss AOP)!

The concept is really pretty simple. In regular AOP, the aspects are cross cutting several different classes. In Tira Wireless’s Jump transformation engine, an aspect is a specific class-level bytecode modification that has to be done (i.e., cross cutting) across several handsets. Better yet, Tira wireless’s has profiled more than 200 handsets and distilled a set of commonly used transformations for you! Those prepackaged aspects/transformations include swapping soft button labels, using multiple images to replace faulty image flip calls, catching certain exceptions, changing thread behaviors, and changing app start/pause behaviors. For each application port, Tira Wireless’s Jump developer tool lists a set of recommended aspects/transformations for those two devices and other possible transformations for you to choose. The following shows the aspects available for the Nokia 3650 to Motorola V300 port and the Nokia 7210 to Nokia 3650 port.

AspectJ2ME ?

Feb 17

AspectJ2ME: Using AOP for running J2ME on any phone

AOP, Java, Mobile, Tech No Comments »

Michael Yuam explains how Tira Wireless does WORA with Aspect Oriented Programming.

Tira Wireless is a very successful J2ME game porting house with big name customers like Disney and Warner Brothers. It takes J2ME games from developers and port them to more than a thousand handset/wireless operator/language combinations for global distribution. As one would expect, they have intimate knowledge and hands-on experience with many JVM implementations to know how exactly “write once, run everywhere” does not work in J2ME. :) Today, Tira Wireless sent two engineers from Toronto down to Austin on a Sunday to sit down with me and explain to me exactly how their approaches work. To my pleasant surprise, their approach is “aspect oriented programming” using a customized version of Javassist (the same underlying library for JBoss AOP)!

The concept is really pretty simple. In regular AOP, the aspects are cross cutting several different classes. In Tira Wireless’s Jump transformation engine, an aspect is a specific class-level bytecode modification that has to be done (i.e., cross cutting) across several handsets. Better yet, Tira wireless’s has profiled more than 200 handsets and distilled a set of commonly used transformations for you! Those prepackaged aspects/transformations include swapping soft button labels, using multiple images to replace faulty image flip calls, catching certain exceptions, changing thread behaviors, and changing app start/pause behaviors. For each application port, Tira Wireless’s Jump developer tool lists a set of recommended aspects/transformations for those two devices and other possible transformations for you to choose. The following shows the aspects available for the Nokia 3650 to Motorola V300 port and the Nokia 7210 to Nokia 3650 port.

AspectJ2ME ?

Feb 17

Femtocontainer — The IoC container built into the JDK

Java, Lightweight Containers, Tech 1 Comment »

Sam has wisely seen that Java has a version of IoC via the java.beans.XMLEncoder/XMLDecoder classes.

Take a look at Sam’s XML config:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE javabeans SYSTEM "http://www.javarants.com/schemas/javabeans.dtd">
<java version="1.4.2" class="java.beans.XMLDecoder">
<object id="cityFinder" class="com.sampullara.jbioc.CityScape">
<void property="cityMap">
<object class="java.util.HashMap">
<void method="put">
<string>LDN</string>
<string>London</string>
</void>
<void method="put">
<string>FFT</string>
<string>Frankfurt</string>
</void>
</object>
</void>
</object>
<object id="region" class="com.sampullara.jbioc.RegionInfo">
<void property="cityFinder"><object idref="cityFinder"/></void>
<void property="regions">
<object class="java.util.ArrayList">
<void method="add"><string>Europe</string></void>
<void method="add"><string>America</string></void>
</object>
</void>
</object>
</java>

Now, you may not be a big fan of the Spring XML config, but this is even closer to the bone. It really does shout out “WHY ARE WE USING XML FOR THIS AND NOT JUST CODE!” (especially a dynamic language).

Also, although it does allow some dependency injection, it is basic. It doesn’t support the layers of components/services like HiveMind.

And IoC itself is only part of the picture. The real power of Spring is that it has practical stuff that you can use out of the box! Great find though Sam!

Feb 16

In Minneapolis, chatting about relational theory

Java, Tech 3 Comments »

I had a good time tonite speaking at the Twin Cities Java User Group. Man it is cold here at the moment. As I drove in to Minneapolis, I was just behind a huge jack knifing accident. It was kinda scary to see the truck swipe two cars aside :( Luckily all were ok.

I had a really interesting conversation with someone after the JUG, in which we chatted about the relational mismatch. This kind chap was laughing at the whole heirarchical XML thing that we are in now:

Didn’t we try heirachical and move on to relational?

He really want to have relational operators baked into the languages of today. I think he will enjoy looking at Comega :)

Feb 15

Rails for the poor Struts guys

Java, Ruby, Tech, Web Frameworks 1 Comment »

Brian McCallister has started on a path of comparing Rails in a way that Strut’ters would get.

He is spot on that people have made a connection between:

Rails is easy. Look at the short demo video

and:

Rails is easy, which means it must no be flexible, or scalable, or …

However, I think Rails manages to be all of these things. The hooks are there for you to get your fingers dirty, while staying in the rails world. There are also many apps which are running with high load, and no scalability problems.

I am really looking forward to talking to Mr. Trails at TSSS, to see what his experience has been shoehorning a Ruby view on a Java platform.