Comments
Patrick Collands wrote: collands (AT) gmail com I'd be very grateful for an invitation. Thank you.
Cloud Expo on Google News

SYS-CON.TV

2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Click For 2008 West
Event Webcasts
Using Apache Tuscany SDO and JSF To Build Dynamic Web Forms
Assembling a very generic system

This was the challenge: Build a generic system that lets users compare data suppliers in different categories. The data to be compared is defined by XML Schemas, where new schemas will be frequently uploaded and existing schemas may be changed. Moreover, the schemas aren't specifically designed for this system, so system specific metadata can't be added as attributes.

Based on the schemas the data suppliers must be presented with standard HTML forms to enter in their own specific data. Alternatively the suppliers must be able to use a Web Service interface.

Overall the sum of the requirements demanded extreme flexibility and robustness of the system.

So basically we wanted something that could go from XSD/XML to HTML forms and back. We stumbled upon a few COTS products, but these weren't suitable. I know many of you will probably think XForms. XForms was what turned up most when searching for known ways to do such a thing. Not knowing XForms beforehand I just superficially skimmed the technology and concluded that it wasn't right for us for several different reasons - one of them being the flexibility the requirements demanded. This may be because we didn't examine it thoroughly enough.

Anyway, looking further we came upon EMF (Eclipse Modelling Framework) and started building a small prototype. EMF seemed rather complex and during a discussion in a newsgroup somebody recommended SDO and the Apache Tuscany SDO implementation, which is based on EMF.

It immediately caught our attention since it seemed to supply just what we needed through a much simpler API. Any issues we had were quickly resolved by the extremely friendly people behind Apache Tuscany via the user mailing list. And our proposals for new functionality were quickly implemented.

Now, let's get into some technical details. This article doesn't introduce SDO as such - for that I recommend the articles by Kelvin Goodson and Geoffrey Winn in earlier issues of JDJ (Volume 11, Issue 12).

SDO
With Apache Tuscany SDO you operate within certain helper contexts. You do your SDO work in a context and you can choose to use this one context for all your work and let it live throughout your application lifetime, or you can use as many contexts as you like. This can be useful when XML Schemas aren't static - even in the same namespace. Once an XML Schema has been defined the types are cached for easy access in your context. If an XML Schema changes (and still keeps the same namespace) you can just scratch the original context and create a new one. Of course it's never recommended to work with XML Schemas that way since it opens up millions of issues regarding schema instances (XML) and the version of the schema. It's recommended that you do your versioning using the namespace. Still it shows some of the flexibility of the Apache Tuscany SDO implementation.

Let's look at some examples of how to define an XML Schema as SDOs and how to load and save XML from them (see Listing 1). For simplicity's sake the examples are without enumerations or many-valued properties. All use Apache Tuscany SDO 1.0 Incubating (beta 1, but the final has just been released).

Okay, so following listing 1, we have got a hold of the SDO data object representing the type of the schema we're interested in. Before we continue let's just see how you can get to this point if you already have existing XML that you want loaded into the data object.

String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    + "<test:TestElementX xmlns:test=\"http://mytestnamespace\">"
    + " <test:SubElement1>1.0</test:SubElement1>"
    + " <test:SubElement2>Hello</test:SubElement2>"
    + "</test:TestElementX>";
XMLDocument xmlDoc = context.getXMLHelper().load(xml);
rootDataObject = xmlDoc.getRootObject();

At this point you can choose to extract XML from the data object. This will be more relevant once we've altered the data object, but this is how it can be done:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
xmlDoc.setEncoding("UTF-8");
try {
    context.getXMLHelper().save(xmlDoc, baos, null);
} catch (IOException e) {
    e.printStackTrace();
    System.exit(-1);
}
System.out.println(baos.toString());

If you haven't already got hold of the XMLDocument, it can be created like this:

XMLDocument xmlDoc = context.getXMLHelper().createDocument(dataObject, namespace, "TestElementX");

Before we continue to work with the root data object, let's take a brief look at how we can make any of this useful in a browser.


About Christian Landbo Frederiksen
Christian Landbo Frederiksen is a senior consultant in Ementor Denmark and has worked with Java and J2EE since 2000. He holds an M.Sc. in IT from the IT University of Copenhagen and a B.Sc. in computer science from the University of Copenhagen. He is a SCJP, SCJD and SCWCD.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

is the source code for this article available?


Your Feedback
Christian Schuhegger wrote: is the source code for this article available?
Latest Cloud Developer Stories
CloudBench Applications, Inc. announced its financial results for the three months and nine months ending September 30, 2009. All amounts are stated in Canadian dollars unless otherwise noted. Revenues from BasicGov, the Company's cloud computing solution for local government, gr...
The new contract is an industry first, with CSC being the first Microsoft partner to lead and win a cloud computing services agreement of this scale. Under terms of the contract, CSC will provide Royal Mail Group's 30,000 employees with access to new IT services using Microsoft's...
Operates in over 170 countries and is one of the world’s leading providers of communications solutions and services. Richard Tarboton talks for MeettheBoss.TV on his role as Head of Energy & Carbon for BT and what they are doing towards reducing carbon emissions.
CA is going to put its Agile Planner software on salesforce.com’s Force.com platform in the first half to accelerate development time and give users visibility over their development initiatives to reduce time-to-market. Customers are supposed to be able to accelerate the deploym...
Despite its uncertain fate Sun soldiers on. Monday it trotted out a cloud-based multiplatform desktop as a service for K-12 and community colleges that can run Windows, the Mac OS, Linux and Solaris applications to nearly any client device, including its own Sun Ray thin clients....
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News
CloudBench Applications, Inc. announced its financial results for the three months and nine months e...