Final Comparative Discussion
Short of the use of simple id attributes and span tags for substring manipulation, XMLC is a presentation technology that is completely transparent to anybody viewing a markup page about to be processed in the XMLC environment. It achieves this by turning the page into a DOM structure, then manipulating the structure. It is, however, more than direct DOM manipulation. As a compiler, XMLC offers significant capabilities and conveniences that greatly simplify the tasks of the designer, the Java developer, and the application architect. A couple of features have been reviewed in our previous two chapters, with many more to be discussed in Chapter 6, "XMLC Basics."
Clearly, standard servlet programming, JavaServer Pages programming, XSLT programming, and Cocoon/XSP programming have something for just about everybody. We now have sufficient context with respect to these technologies to makes some observations about XMLC. In this section we're going to use the context of this chapter to make some assertions about XMLC programming, and bring to light advantages of XMLC that are made more clear when described relative to JSP and XSLT.
XMLC Views Markup Pages as Template Object Representations
By accessing markup through the DOM API, XMLC views all markup as object-oriented resources that can be manipulated with a minimum of markup idiosyncrasies. The DOM library insulates the Java logic from the need to understand markup language conversion issues, such as how to replace ampersand characters with the appropriate entity references. Letting the DOM represent the page, there's no JSP or XSP embedded logic that looks like
if (( request!= null && (e.hasMoreElements()))...
Finally, DOM development guarantees that well-formed XML documents are generated from the object representation.
XMLC Sticks with One Programming Language: Java
Cocoon and XSLT incorporate yet another language (or two) for project and product managers, and sometimes their customers, to consider. Debugging becomes complex and integration issues more difficult. With XMLC, you are operating with only one language, Java. Yes, there are the inevitable JavaScript issues for supporting client-side browser programming, but that's the case for all the presentation technologies discussed in this chapter. With XMLC, there is no new category of "page programmer," an intermediate between Java developer and the page designer.
Figure 3.4 attempts to show by relative position on a triangulation of Java, DOM, and XSL programming where the presentation technologies we've discussed might lie. Clearly, JSP is the most Java-centric. But, without DOM support, JSP programming has had to engineer an alternative, non-standard strategy for generating HTML/XML content.
Figure 3.4 Relative use of Java and Scripting/XSLT templating.
XMLC Enables Type-Safe DOM Programming
Markup language-specific DOM sub-interfaces are incorporated with the XMLC environment. These include HTML, WML, VoiceXML, and cHTML. Unlike JSP, which relies entirely on the developer to construct the resultant markup page, markup language-specific libraries increase type-safe programming. XMLC has an escape hatch for those who aren't interested in leveraging markup-specific libraries. You always have the option to do standard DOM programming and still take advantage of the use of id attributes. This means that you can use XMLC for any type of markup language as long as it is based in XML.
XMLC Is a True Template Presentation Technology
With thoughtful designs on how to detect client types or preferred languages, XMLC supports the capability for Java servlets to load the appropriate DOM representation of a markup page. This template encapsulates the markup page, reducing the amount of Java logic required to generate the presentation page. Unlike JSPs, these templates never contain Java code.
As a template resource and lacking any embedded logic, the page has no impact on the flow of logic. It also eliminates the need for special tag elements representing the namespace for Java or XSLT code.
XMLC Greatly Simplifies DOM Programming
The use of developer/designer-chosen id attributes greatly simplifies the manipulation of DOM elements. XMLC uses the id values to auto-generate Java methods that the developer has the option of using. These methods bypass much of the DOM intrigue of traversing, removing, appending, and updating tree nodes and text elements.
XMLC Is Designer-Friendly
With JSP, a designer must maintain two documents: One with scriptlets embedded that will, eventually, populate a table with dynamically-gathered row data; and another that is the mock-up page, which shows what the page might look like when the application is operational.
With XMLC, the document used by the application and as the mocked-up page are one in the same. The XMLC compiler incorporates options that make it easy to remove mocked-up data during compilation.
And, of course, the designer never sees a lick of code. Other than accidentally changing an id attribute value, there's no chance to accidentally break the application. Even in the case of missing id attributes or renamed id values, the XMLC compiler includes options for validating ids.
XMLC Eliminates the Need to Introduce New Tags (Elements)
Again, XMLC keys off of id attributes. There is no need for taglibs. There is no need for scriptlets. The implication is that XMLC will work with any standard HTML or XML browser without having any required update to the list of supported elements.
XMLC Is a True Loosely Coupled, Object-Oriented Presentation Strategy
XMLC was designed to keep Web applications truly object-oriented. This was in reaction to the observation that JSP really let HTML do the steering, as it were. The absence of Java logic embedded in a markup page makes XMLC as loosely coupled as you can get when gluing two very differently purposed languages together: markup and Java. XMLC's avoidance of embedding logic in the markup makes XMLC programming more polymorphic. Any action can connect any page. There is no pre-knowledge of page and action, which is typically the case with JSP pages. Instead of the page calling code, the code calls the pages into memory.
With XMLC, you can string actions together to form a business process. Because XMLC doesn't depend on a series of visual clues, you can string them together differently on, for example, a per-user basis. An example might be the behavior defined for an average user as opposed to an administrator. Recognizing an administrator, the logic determines that another page requiring another type of login is to be loaded and displayed.
The XMLC Mechanism Is the Same for Everybody
Unlike JSP taglibs and XSP taglibs, XMLC introduces a standard relationship between the markup page and how it references Java logic "underneath." Attributes, not elements/tags, are defined by the programmer. There is no option for inserting Java logic directly in the markup page. Until there is a unified standard JSP or XSP custom tag library, the approaches taken by different parties to define custom tag interfaces will vary from organization to organization and product to product.
XMLC Detects Errors Early
XMLC identifies page creation errors during compile-time. Unlike JSP, XMLC detects malformed markup pages during the development phase. It is impossible to generate a malformed markup page when leveraging the DOM standard. XMLC development is much less error prone than JSP development. There is less opportunity for making errors as compared to JSP development, where the developer performs a specialized form of Java developmentconnecting JSP declarations, scriptlets, and expressions. And there is a much higher likelihood of understanding the error, because it is expressed in the context of standard Java, not JSP scriptlet-isms.
XMLC Is Built Heavily on Standards
Finally, although it is not a defined technology under J2EE, in many ways XMLC is actually more "standard" than JSP. XMLC leverages the XML and DOM standards, both defined by the World Wide Web Consortium. XMLC is also an open source technology, which for many, offsets its definition outside the J2EE specification.
Taglibs Do Not Make JSP Like XMLC
The most common response an XMLC developer hears in a discussion about JSP versus XMLC is "JSP can do that with taglibs." The reality lies somewhere between an answer of "Somewhat yes, and mostly no." For example, a designer-friendly JSP developer could create a custom tag that enables mocked-up data to be included in the body of the element, like XMLC does natively. But even this feature will be non-standard, as different implementers of different tag libraries do it differently.
The leveraging of HTML/XML elements to identify and install a new custom tag again forces a tight coupling between markup and logic. Not even XSLT defines new elements. Its elements are standard, thus guaranteeing a common language from implementation to implementation.
My observation is simply this: If you want extreme flexibility of strategies that you use to link markup presentation and logic, JSP is absolutely your choice. If you want to standardize on one strategy for achieving separation of presentation and logic, and you want it to be the same approach used by anybody else using that same technology, then XMLC is the route to take.