Add XML to your J2EE applications
Integrate an XML presentation layer in the J2EE layered architecture
By Eoin Lane, JavaWorld.com, 02/09/01
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Today's organizations' rapid moves to e-business bring new demands on defining flexible systems architectures. Systems need
to be powerful, scalable, robust, and, most of all, capable of meeting new business demands. With that in mind, although more
and more organizations are adopting a multitier, Java 2 Platform, Enterprise Edition (J2EE)-based application server architecture,
they rely on HTML for the presentation layer. This prevents them from fully benefiting from the flexibility the distributed,
multitier J2EE framework can offer. XML's Web publishing capabilities are key to solving this architectural shortfall.
This article proposes a replacement for the current HTML-based J2EE architecture presentation layer with a dynamic XML content
layer. Through a case study, we'll see an XML-aware, open source application server within a fully operational end-to-end
solution. At the heart of the case study resides Cocoon, a servlet from Apache that provides a pluggable Java presentation
framework used to present XML content in a variety of formats, on demand.
The situation
J2EE defines a standard for developing multitier enterprise applications. J2EE simplifies enterprise applications by basing
them on standardized, modular components, by providing a complete set of services (persistence, security, transactions, and
so on) to those components, and by handling many details of application behavior declaratively, without complex programming.
However, the architecture's presentation layer is primarily HTML-based, thus limiting the target audience largely to Web browsers.
Tomorrow's audience will be much broader, what with a variety of new devices about to revolutionize how we send and receive
information. As such, it's imperative to decouple content from presentation logic and become independent of our intended audience's
devices. XML is the solution.
XML's Web publishing capabilities are possible using XSLT to transform XML documents into other textual documents. These target
documents are often XML-based languages themselves (with HTML serving as a notable exception as it is based on SGML). As a
metalanguage, XML can also produce other Web languages such as:
- XHTML (for Web browsers, WebTV, and soon WAP devices)
- WML (a language for describing two-dimensional graphics in XML)
- SVG
- MathML
- VoxML (for voice)
XSLT can transform an XML document into any one of these target languages. Once we've expressed the solution in terms of XML,
we can leverage it using XML's sister technologies to produce powerful, media-aware Web application that will remain invariant
to target device changes.
Case study
The case study develops a software application to automate a car rental company's various processes -- reserving, renting,
and returning a car. Our objectives: analyze, design, and implement the car rental agency system and build a scalable system
capable of targeting multiple end user devices (Web browsers, WAP -- Wireless Application Protocol -- phones, Web TV, and
so on).
For simplicity's sake, we'll implement just one use case: reserve car. Other use cases such as modify/cancel reservation,
return/rent car, or maintain car could be similarly implemented.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- Download the complete source code to this article by going to
http://www.javaworld.com/javaworld/jw-02-2001/xmlj2ee/jw-0209-xmlj2ee.zip
- The site dedicated to updating the information and code presented in this article can be found at
http://jaba.sourceforge.net
- Andrew Schneider's "JUnit best practices" (JavaWorld, December 21, 2000) eloquently describes techniques for building resilient, relocatable, multithreaded JUnit tests
http://www.javaworld.com/javaworld/jw-12-2000/jw-1221-junit.html
- "XML Document Processing in Java Using XPath and XSLT" by André Tost (JavaWorld, September 2000) explains how XPath and XSLT can significantly reduce the complexity of your Java code when handling XML documents
http://www.javaworld.com/javaworld/jw-09-2000/jw-0908-xpath.html
- You'll find numerous informative XML-related articles in the Java and XMLsection of our Topical Index
http://www.javaworld.com/javaworld/topicalindex/jw-ti-javaxml.html
- Swap tips and techniques for developing with XML in the XML & Javadiscussion
http://www.itworld.com/jump/jw-0209-xmlj2ee/forums.itworld.com/webx?14@@.ee6b78f
- For more JavaWorld articles covering J2EE, visit the Server-Side Javasection of our Topical Index
http://www.javaworld.com/javaworld/topicalindex/jw-ti-ssj.html
- Sign up for the JavaWorld This Week free weekly email newsletter and keep up with what's new at JavaWorld
http://www.idg.net/jw-subscribe
- For answers to your pressing J2EE questions, check out the JavaWorld Server-Side Javadiscussion
http://www.itworld.com/jump/jw-00202-extremescale/forums.itworld.com/webx?14@@.ee6bdcf
- An object-orientated XML replacement for DTDs (W3C XML Schema homepage)
http://www.w3.org/XML/Schema
- A recursive style sheet language, used for transforming XML documents into other textual documents (W3C XSLT homepage)
http://www.w3.org/Style/XSL
- HTML meets XML (W3C XHTML homepage)
http://www.w3.org/MarkUp
- A language for describing two-dimensional graphics in XML (W3C SVG homepage)
http://www.w3.org/Graphics/SVG/Overview.htm8
- A way of representing complex (and simple math) with XML (W3C MathML homepage)
http://www.w3.org/TR/REC-MathML
- The Cocoon Website contains instructions on how to install Apache, Tomcat, and Cocoon
http://xml.apache.org/cocoon/index.html
- Apache's servlet container that is Servlet 2.2 and JSP 1.1 compliant
http://jakarta.apache.org/tomcat/index.html
- Apache homepage http://www.apache.org
- Servlet 2.2 specifications
http://java.sun.com/products/servlets
- White paper on XML and Cocoon technology
http://xml.apache.org/cocoon/technologies.html
- Cocoon 2 focus page
http://xml.apache.org/cocoon/cocoon2.html
- The jBoss homepage
http://www.jboss.org
- jBoss site for downloading the latest version of jBoss with embedded Tomcat
http://www.jboss.org/newsite/business/jboss-tomcat.html
- JDOM homepage -- this is DOM for Java programmers http://www.jdom.org
- XProgramming.com -- a site dedicated to extreme programming practices and ideas
http://www.xprogramming.com
- JUnit -- a framework for developing unit tests
http://www.junit.org
- Ant -- a Java build tool from Apache
http://jakarta.apache.org/ant/index.html