Comments
litl_phil wrote: While it's nice that Google and Acer share the vision of cloud-based computing, it's also worth noting that we at litl already have a webbook on the market (available at litl.com) that runs our own cloud-based OS. Unlike Chrome, litlOS is focused on creating a new and better web experience for the home, so we don't have the usual browser interface, we have our own innovative UI. In conjunction with easel mode (litl's inverted-V position) and our growing cohort of litl channels (special apps t...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Using Apache Tuscany SDO and JSF To Build Dynamic Web Forms
Assembling a very generic system

JSF
JSF was chosen as the Web framework since it has an extensive component model, where each HTML element needed is represented by a Java object. It comes with built-in conversion and validation and suits the project well.

Per XML element we want displayed we need a UIOutput object for the label and an UIInput object for the data.

Data Structure
We needed a data structure that would wrap the SDO objects along with the needed JSF objects and found the Composite design pattern useful (http://en.wikipedia.org/wiki/Composite_pattern). Using this pattern we could store our own objects in a structure that matches the SDO data graph. SDO containment properties (complex types) went into the composites and SDO non-containment properties (simple types) went into the leafs as illustrated in Figure 1.

Filling the Data Structure from XSD and XML
From the root data object obtained earlier we're going to construct the JSF components and fill the data structure.

Each property is extracted from the data object and handled recursively. The JSF components are generated, as we recursively traverse the structure, ending in the leafs (see Listing 2).

Now the data structure is filled with the SDO and JSF components - ready to be plugged into a GUI such as added to the child list of a panel:

private void setupXmlElement(XmlElement xmlElement) {

   CompositeXmlElement comp = xmlElement.getCompositeXmlElement();
   if (comp != null) {
     for (XmlElement child : comp.getChildren()) {
       setupXmlElement(child);
     }
   } else {

     LeafXmlElement leaf = (LeafXmlElement) xmlElement;
     if (leaf.getUiInput() != null && leaf.getUiInput().isRendered()) {

       this.getPanel().getChildren().add(leaf.getLabel());
       this.getPanel().getChildren().add(leaf.getUiInput());
     }
   }
}

This very simple example renders to this page (see Figure 2).

Because of the flexibility of JSF validation messages, such things as styles can be easily be added to each relevant component.

Submitting Data Back into the SDO Data Model
Submitting the form is easy. You just call submit on the XmlElement and the composite pattern handles the rest by setting each value from the UIInput in the leaf's submit method:

Object inputValue = this.uiInput.getValue();
String stringValue = inputValue.toString();
Object value = SDOUtil.createFromString(this.property.getType(), stringValue);
this.dataObject.set(property, value);

Conclusion
These were some of the basic operations that made it possible for us to assemble a very generic system. Apache Tuscany SDO turned out to be very flexible. Through its simple APIs it was easy to work with schemas and data and easy to plug this into a presentation framework. The final application contained a lot more than exemplified here, since most schema constructs were supported, but that's beyond the scope of this article. Supplying the application with a Web Service interface was also easy since the SDOs could be used to both import and generate XML directly as shown above.

Apache Tuscany also covers SCA and DAS but that's a whole different article.

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?
Enterprise Open Source Magazine Latest Stories . . .
Oracle seems to have divided the open source ranks over the MySQL delay it’s having closing its acquisition of Sun. Eben Moglin, the GPL’s most ardent defender and delineator, the lawyer who has worked hand in glove for years with the Free Software Foundation’s founder Richard Stallman...
Cloud computing is a game changer. The cloud is disrupting traditional software and hardware business models by disrupting how IT service gets delivered. Entrepreneurial opportunities abound as this classic disruptive technology begins to proliferate, so it is no surprise that SYS-CON'...
The irony is that Oracle has advanced MySQL, lost money in the process, and helped its competitors - all at the same time. When Oracle buys Sun and controls MySQL the gift (other than to Microsoft SQL Server) keeps on giving as the existential threat to RDBs is managed by Redwood Shore...
WSO2, the open source SOA company, today announced the launch of the WSO2 Cloud Platform. Available today, the new WSO2 Cloud Platform features a family of WSO2 Cloud Virtual Machines; WSO2 Cloud Connectors for enabling fast, secure cloud services; and the multi-tenant WSO2 Governance-...
Now, the open source Mozilla Thunderbird client software can be used with Open-Xchange collaboration software. The "Community OXtender for Thunderbird" software connector gives users full access to appointments and contacts stored in the Open-Xchange Server and enables them to use Thun...
Morph Labs, a leading provider of enterprise cloud computing technology, today announced an introductory trial of the Morph CloudServer, an open, standards-based server IT organizations can use to rapidly model and evaluate their cloud implementations. A miniature "Cloud Environment in...
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