Building JavaXML Web Applications with Enhydra Open Source

Building Java/XML Web Applications with Enhydra Open Source Java/XML Application Server @ David H. Young david. young@lutris. com Lutris Technologies & Enhydra. org 30 March 2000 Session: Open Source Java Servers

My Assumptions • You know Java • You know the value of an application server strategy for building Web applications • You know the value of Open Source strategies • You want to see something that solves a problem with building Web applications – e. g. , JSP not the best for a real product life cycle

Enhydra: #1 Open Source Java Application Server • Lutris is sponsor of Enhydra. org, an Open Source Java/XML Application Server • www. enhydra. org • Enhydra is a true Open Source Java/XML Application Server • Over 1000 known developers worldwide • J 2 EE Enhydra available today.

Open Source Enhydra Technology • Enhydra Multiserver – Servlet runner – Web Server & Web Server Connection Manager – Management console • Enhydra Debugger – Graphical Servlet Monitor • Enhydra XMLC – XML/DOM Presentations • Enhydra Director – Failover/Cluster Support • Enhydra Application Framework – “Superservlet Strategy” • Enhydra Application Wizard (“Newapp”) – Instant application to jumpstart development • Enhydra DODS – Graphical Object-to-SQL mapping application

Enhydra Architecture

www. enhydra. org for the Enhydra Community • Mail lists & Working Groups – enhydra@enhydra. org • Mail Archive/Search • Case studies, News • On-line Demos – Shopping Cart, Chat Room, Poker • 3 rd party Services and Products Working Groups: EJB Container Web Container I 18 N Wireless Architecture JMX Rocks/XMLC DODS

www. wnet. org/newyork/game/index 2. html Deployed Enhydra www. earthlink. com (The Mall)

The Internet Wizshop/Earthlink/Mindspring Cisco Local Director • Sun E 250/2 CPU • 500 M Memory • 400 Mhz • Enhydra • Apache/Jserv • Sun E 450 • Oracle DB

A Best Practice Leveraging Enhydra XMLC Java Server Pages

Embedded Page Languages: Bad Idea! • HTML is developed by graphic artists – Authoring programs can break the code – Pages with mocked data is not final mockup – Most graphic artists cannot program • Code is developed by programmers – They use source code editors – Code added to HTML is difficult to maintain – Most programmers cannot draw

Embedded Page Languages: Bad Idea! • Embedded page languages are not legal HTML – Can’t parse the pages with standard parsers – Standards are a good thing. • Flow-of-control is obscured • Little compile-time type checking available • Does not integrate well with debuggers, profilers • Poor support for I 18 N

JSP Example <HTML> <%@ page language==“java” imports==“com. wombat. JSP. *” %> <H 1>Welcome</H 1> <P>Today is </P> <jsp: use. Bean id==“clock” class==“calendar. jsp. Calendar” /> <UL> <LI>Day: <%==clock. get. Day. Of. Month() %> <LI>Year: <%==clock. get. Year() %> </UL> <% if (Calendar. get. Instance(). get(Calendar. AM_PM) == Calendar. AM) { %> Good Morning <% } else { %> Good Afternoon <% } %> <%@ include file==“copyright. html” %> </HTML>

An HTML Example <TABLE> <TBODY> <TR> <TH>Name</TH> <TH>City</TH> </TR> <TD>John Doe</TD> <TD>Atlanta</TD> </TR> </TBODY> </TABLE>

DOM Representation ID=cust. Name ID=city

Adding ID Attributes <TABLE> <TBODY> <TR> <TH>Name</TH> <TH>City</TH> </TR> <TD ID=“cust. Name”>John Doe</TD> <TD ID=“city”>Atlanta</TD> </TR> </TBODY> </TABLE>

What is the DOM? • Document Object Model • A W 3 C specification (www. w 3 c. org/DOM) • A standard API to represent a structured document as a tree with branches, nodes, and leaves • Each markup element in the document is a node with nested markup elements as child nodes • Allows documents to be traversed as a tree where nodes are visited, added, removed, replaced, or cloned

Java DOM Package • Node: Base class of all DOM tree objects – Contains children and parent links – Provides methods for manipulating the tree • Document: Root of tree – Provides factory methods for other DOM classes • Element: Interface for XML tag classes – Implements Node – Specific XML applications may define classes that extend element • Text: Nodes that contain the document text

Java DOM HTML Package • org. w 3 c. dom. html – DOM Interfaces for HTML • HTMLDocument - Root of the HTML hierarchy • HTMLHead. Element - <HEAD> • HTMLBody. Element - <BODY> • HTMLParagraph. Element - <P> • HTMLAnchor. Element - <A> • HTMLTable. Element - <TABLE> • HTMLFont. Element - <FONT> • …more…

Enhydra XMLC

Enhydra XMLC Overview • Compiles HTML and XML documents into Java classes • An instance of of the XMLC-generated class is a DOM that contains the original document • Access methods are generated for elements with ID attributes – Return type of method is DOM class for that element – If the element is deleted from the document, the code will quit compiling – Isolates change in the structure of the document

. . . Enhydra XMLC Overview • Programmer adds dynamic content to the document by adding and manipulating DOM objects • Static page URLs can be replaced with dynamic ones • Prototype table row can be template for other rows.

Simple XMLC Example HTML <H 1><FONT ID=“Head. Font” SIZE=“ 4” COLOR=“red”> Hello World</FONT></H 1> <P>Hello, my name is <SPAN ID=“Cust. Name”>John Doe</SPAN> Generated Class public class public } Hello. HTML extends HTMLObject { HTMLFont. Element get. Element. Head. Font(); HTMLElement get. Element. Name(); void set. Text. Cust. Name(String text); Using the Generated Class Hello. HTML hello = new Hello. HTML(); HTMLFont. Element hfont = hello. get. Element. Head. Font(); hfont. set. Color(“Green”); hello. set. Text. Cust. Name(“Barney Blake”); out. println(hello. to. Document());

Development with Enhydra XMLC welcome. html xmlc -class myapp. Welcome. HTML welcome. html javac myapp. Welcome. HTML

Work Flow using Enhydra XMLC • HTML designer creates a working storyboard/demo page • The designer tags dynamic elements with HTML 4. 0 ID tags, e. g. , <TD ID=“Cust. Name”>…</TD> and hands off the page to the programmer • The programmer compiles the page into a java class which is a DOM tree that can reproduce the document

… Work Flow. . . • XMLC generates “get. Element<IDName>()” methods in the document object, e. g. get. Element. Cust. Name() for each ID-tagged HTML page element • At run-time the programmer instantiates the HTML page as an object and manipulates its properties

…Work Flow • The programmer can use the XMLC-generated methods like get. Element. Cust. Name()to manipulate page elements • The programmer can also traverse the DOM tree to manipulate its other nodes directly if desired • Finally to. Document() is called on the page object to stream the page to the web client as a string

Advantages of XMLC • Object-oriented control of documents • Layout and flow of control are completely separated • Page designers and programmers only intersect on defining the dynamic page elements • Programmers are largely unaware of page layout

. . . Advantages • HTML storyboard can be demo’d and changed in parallel with the server-side code • Business logic and user interface can be developed and tested completely independently of each other • Enhydra XMLC can serve the presentation layer in any multi-tier environment, such as BEA Web. Logic

XMLC for Skins <TABLE ID=users. . . get. Element. Users(). . . Pages/de/user. List. html pages. de. User. List. Impl <TABLE ID=users. . . XMLC get. Element. Users(). . . Pages/en/user. List. html pages. en. User. List. Impl <TABLE ID=users. . . get. Element. Users(). . . Pages/fr/user. List. html pages. fr. User. List. Impl Interface User. List HTMLTable. Element get. Element. Users();

XMLC for XML • XMLC compiles any XML document – Generic DOMs – DTD-specific DOMs • XML intended for display • XML as data interchange format • WML - Wireless Markup Language – HTML-like DTDs for wireless devices – Many companies using Enhydra XMLC for developing WML applications

Enhydra Roadmap

Other Open Source contributions, including on-going Enhydra evolution JOn. AS, Bull. Soft Jonathan, France Telecom Toward J 2 EE Enhydra

The Enhydra Near-Term Future • Enhydra 3. 0 (beta: Today, FCS: TBA) – Servlet 2. 2 (JSP) Support – Enhydra Director for Cluster/Failover – Enhydra Rocks • Enhydra Enterprise (beta: Today, FCS: TBA) – J 2 EE Enhydra – Jonas/EJB Server – Jonathan/CORBA – JMS, JMX, etc.

Open Source Java/XML Application Server
- Slides: 34