| By Christian Landbo Frederiksen | Article Rating: |
|
| November 27, 2007 11:45 AM EST | Reads: |
10,770 |
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.
Published November 27, 2007 Reads 10,770
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By 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.
![]() |
Christian Schuhegger 05/25/08 03:25:53 PM EDT | |||
is the source code for this article available? |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?









































