Saturday, June 23, 2007

Modeling Generics With XML Schema

Are you feeling curious today? I'll bet you are!



With the introduction of generics to Ecore itself we needed to think about keeping our round trip stories complete so there was a little bit of last minute scrambling to complete the support to make Ecore -> XML Schema -> Ecore and Ecore -> Java -> Ecore both continue to be round trips for all the new constructs we've added.

This schema shows that it's now possible to define your complex types as normal, and to specify their type arguments as well, kind of like having your cake and eating it too:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:tree="http:/www.example.org/tree"
ecore:nsPrefix="tree"
ecore:package="org.example.tree"
targetNamespace="http:/www.example.org/tree">
<xsd:element name="Node" type="tree:Node"/>
<xsd:complexType name="Node">
<xsd:annotation>
<xsd:appinfo
ecore:key="typeParameters"
source="http://www.eclipse.org/emf/2002/Ecore">
<typeParameter name="T"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element
ecore:keys="label"
ecore:opposite="parent"
ecore:type="tree:Node{T}"
maxOccurs="unbounded"
minOccurs="0"
name="children"
type="tree:Node"/>
</xsd:sequence>
<xsd:attribute
ecore:reference="T"
name="data"
type="xsd:anyURI"/>
<xsd:attribute
name="label"
type="xsd:string"/>
<xsd:attribute
ecore:opposite="children"
ecore:reference="tree:Node{T}"
name="parent"
type="xsd:anyURI"/>
</xsd:complexType>
</xsd:schema>

Notice that we use {} as synonyms for <>, since the later requires the use of entities in the XML representation, which tends to make the results quite unreadable. By hey, is XML actually designed to be human readable, or does it favor the machine? Given that a < within quotes could be handled unescaped by a machine without much challenge and yet must be escape to make it even easier for the machine, I'd argue that XML is sadly twisted in favor of the machine.

Converting this XML Schema to Ecore produces this model, which records as EAnnotations just enough information about the schema so that instances can be serialized to conform to it:



Generating the Java for this Ecore model produces the following, which records as @model annotations just enough information to be able to recover the original Ecore model

package org.example.tree;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;

/**
* @model extendedMetaData="name='Node' kind='elementOnly'"
*/
public interface Node<T> extends EObject
{
/**
* @model opposite="parent" containment="true" keys="label"
* extendedMetaData="kind='element' name='children'"
*/
EList<Node<T>> getChildren();

/**
* @model kind="reference"
* extendedMetaData="kind='attribute' name='data'"
*/
T getData();
void setData(T value);

/**
* @model dataType="org.eclipse.emf.ecore.xml.type.String"
* extendedMetaData="kind='attribute' name='label'"
*/
String getLabel();
void setLabel(String value);

/**
* @model opposite="children" transient="false"
* extendedMetaData="kind='attribute' name='parent'"
*/
Node<T> getParent();
void setParent(Node<T> value);
}


Given the above Java, we can reproduce the originating Ecore and from that we can export the original schema. So in this case, even XML Schema -> Ecore -> Java -> Ecore -> XML Schema is a round trip. The value of this lies in the fact that any of these different forms of the same model can be your starting point and any of the others can be produced from it. Ecore is like the hub in a hub-and-spoke transportation system; every time another two-way spoke is added to the hub, everyone benefits. The UML project provides Ecore importers and exporters to support its own spoke and so the network grows...

It's clear that Ecore, XML Schema, UML, and Java are very different things, but the really useful insight is to see their similarities and then to use those similarities to build tools and runtimes that capitalize on them...

Monday, June 11, 2007

Stop and Smell the Flowers

When the garden is this lovely:


It's time to stop and smell the flowers:


Often it seems there isn't nearly enough time for the important things in life.

Saturday, June 2, 2007

Sneaky Behavior?

This year we started feeding the foxes that regularly visit our back yard, hoping they'll be so well fed, they won't be tempted to eat our dogs. It's very hard to get a picture of these sneaky little guys in action, so we bought a motion triggered camera. The picture quality isn't great, but look who we caught red pawed at the trough:


It turns out there are actually two of these little guys!


And a big one too.


We think the little ones are the babies from last year and are hoping to see new babies from this year out and about soon.

Speaking of apparent sneaky behavior. When the JDJ polls for best Java component closed the other day, I was rather pleased to see that EJB3 was at 583, JSuite at 593, and EMF at 623. Imagine my surprise when the next day the standing was quite different. Despite the polls being closed, JSuite had jumped to 746. That's a surge of 153 votes all in one day. That's quite the voter turnout, especially after the polls were closed! If I'd had my little camera set up at the ballot box, we'd get some really interesting pictures. I'm hopeful that the JDJ auditing process will take note of such irregularities..

Thursday, May 31, 2007

Manipulating Polls?

Well, I haven't blogged much recently because the EMF team has been as busy as the eager little bees in my garden:


Note that like features, this bee sucks, but clearly it's all for a good purpose. The EMF team has spent quite a bit of time splitting our small number of big features into a large number of small features. But enough of the feature bashing, I digress.

Of course I've also been busy making life hell for well-intentioned folks like Janet and Bjorn. You won't think a guy could get so riled up about updating a date in an about.html, but hey, people who know me know that a surprisingly little thing can induce a dramatically big reaction from me. Yep, I'm a volatile person and no effort to be perfect seems to work. I suppose that's a good thing. Imagine how annoying I'd be if I were any closer to perfection than I am now!

My real aim at blogging today is to complain a little. I've been told I'm awfully good at complaining. Just ask anyone. I'm watching the poll for best Java component with great personal interest, for obvious reasons, and am dismayed to see EJB3 garner more votes in the last three days than it did in total for the preceding three weeks. One generally expects a Poisson distribution for the arrival of votes, so spikes are definitely odd. Even the closest competition generally had spikes of votes arrive, whereas EMF has garnered its votes with the expected type of arrival rate. Since today is the last day for voting, maybe things will work out well for EMF, which I consider to be more of a vote for the Modeling project as a whole than a vote purely just for EMF. Hopefully the final audit won't result in big drop...

So am I manipulating the poll with my blog? I think so. I feel dirty now. Time to do something useful to get ride of this unclean feeling. A shower perhaps...

Friday, March 23, 2007

It pays to talk to people at EclipseCon!

This is an update on my previous post: JDK Bugs: To fix or not to fix?

But first a completely gratuitous photo from my collection. Here's one bug you don't want to find in your code!


As I mentioned previously, Joe Darcy from Sun brought up some helpful advice during the talk Marcelo and I did about our experience with Java 5.0 and generics. He approached us afterwards to continue the discussion and since then we have exchanged notes about the String.offsetByCodePoints bug. He pointed out that the code I showed is not the most efficient way to iterate over code points and that his blog shows a better way. It certainly does and I just love to learn better ways!

Another cool development is that he helped to convince the folks at Sun in charge of maintaining the JDKs to fix the String.offsetByCodePoints bug in the 5.0 JDK. What a nice guy! My faith that the right things always get done in the end is restored! So the moral is, it pays to go to EclipseCon and most importantly it pays to talk to anyone and everyone while you are there. The nice helpful people are everywhere in our community.

Tuesday, March 20, 2007

Spring is in the air?

Is that spring I see glinting off the melting ice? I think it is!


Apparently the moss is always greener when it's been protected by three feet of snow all winter; I'm sure the dandelion seed will be lovely when it sprouts later in the season.


Clearly I digress, but consider that these two pictures are worth well over 2,000 words, so I've saved you a lot of reading!

Having read all the blogs, I think pretty much everyone agrees that this year's EclipseCon was the best one ever and that they've been getting better every year. Doug Gaff has a new higher bar to clear for next year thanks to Rich Gronback's bar setting performance this year. (My short side trip to Vancouver after EclipseCon to visit family was very nice, though it rained for three days straight. I forgot about that part of Vancouver.)

As most people already know, I love newsgroups, they really get you close to the pulse of what's going on in the community, so I'm obviously very happy that the new committer rep newsgroup has been created and is open for business:
news://news.eclipse.org/eclipse.board.committer.reps
Be the first to post a question or raise an issue! Demonstrate that committer apathy is a myth and that it reflects only the lack of a vehicle for expressing our views. We committer reps can't help you if you don't let us know what issues are near and dear to your heart. We have a new committer rep blog as well, just waiting for an introductory post from our official ambassador:
http://eclipse-committer-reps.blogspot.com/

I also wanted to draw people's attention to 175200. Let's replace that hideous space alien that's required to appear on the web page for every incubating project with something tasteful in keeping with all the other wonderful Eclipse graphics. After installing a most awesome screen background ModelingBackground contributed by Gen Nishimura, I am spoiled and expect all Eclipse graphics to be awesome. Gen is helping, i.e., doing all the work, to create a new logo for the EMF project. This is our favorite so far!


Who says open source software has no value because it's free? We all know that the best things in life don't have a price tag!

Friday, March 9, 2007

Last Day of EclipseCon

Today was the last day for EclipseCon. It took a few ibuprofens to eliminate the effects of last night's awesome party. We found out during Mike's closing remarks at the end of the day that we'd spent roughly $2867.32 at the bar. Slightly short of our $3,000 spending limit. I hope this sets a precedent for future years that awards winners will have an open party for the community rather than an exclusive party for their buddies.

Marcelo and I missed the keynote, which apparently was the best one of the three from what I heard. We were preparing for our 10:00 talk about our experience porting to Java 5.0. Darn!

Marcelo has the pictures that Dave took at our talk but he, Dave, and Nick had to go home before I would fetch them from his camera. Our talk went okay, but I babbled far too much doing the intro slides, which cut into Marcelo's more interesting air time. I'll bet next time he'll not be so keen to let me talk! Afterwards Joseph Darcy from Sun introduced himself and gave us some very helpful advice. I was really impressed that he was so helpful. He might even help find out about fixing that bug in String.offsetByCodepoints in the Sun 5.0 JDK. Too cool!

I found out that it pays to blog, because the TOPCASED guys told me they read my blog about chatting with Boris about EMF data binding support. Apparently they have a prototype they are willing to contribute, so that's just too cool. They're a great bunch of guys and I'm really looking forward to working more with them.

I went to Ian's Europa marketing meeting to find out how we can help. It would be really cool to have quantitative measurements to back up the assertion that Europa will be the biggest coordinated simultaneous software release ever. We had to leave early to attend Martin's talk.


The audience was waiting in anticipation.


He did an excellent job presenting the material. It's very impressive what he has done and I heard a number of people expression that sentiment. He, Shaun, and Stefan are planning to pool their effort and Martin wants to add Stefan as a committer to Teneo so I will try to help make that happen.

I was on the closing PMC panel discussion which was a lot of fun. This EclipseCon was the best one yet. I suppose each year will always just get better and better. There was just so much interest in modeling this year. It's great to see more and more familiar faces as the community continues to multiply rapidly. I'm already looking forward to Eclipse Summit Europe...

Given that we have to head back to where it's -25 degrees Celsius we decided to sit out on the patio. Something we won't do back home for quite a few months.

Steve Northover, SWT god, came out and I got a big f*** you from him. This guy really has such an eloquent way to express his terms of endearment. He's a brilliant guy too. He's figured out how to make money directly from open source: pan handling at the conference...


I asked Stefan and Shaun to pose in front of the fountain, and he said, oh my goodness, this is the second time you are photographing us together. People might think we're an item. Hehehe!


Bernd invited us to the Eclipse Summit Europe dinner. The food was excellent.


Ralph stopped by to chat, and he paid for the drinks. Thanks Ralph! I'll bet you'll help organize an awesome event in Germany again this year.


Everyone really enjoyed the dinner.


After this, I said goodbye to most of the people and had a nice swim down in the pool. What a great time I've had. Tomorrow I present the same talk I did on Tuesday at IBM's Almaden research lab; it's open to the public, so it will be cool to see who shows up. After that I head up to Vancouver to visit my family before heading home to Vancouver on Tuesday.

I hope folks have enjoyed the blogs.