![Page 1: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/1.jpg)
Open Source Java/XML Application ServerOpen Source Java/XML Application Server
&&
Web Developmentwith Open Source Enhydra Java/XML Application Server
Web Developmentwith Open Source Enhydra Java/XML Application Server
James Murphy
UC Santa CruzJanuary 2001
![Page 2: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/2.jpg)
Agenda
• Introduction, CGI, and Servlets
• Architecture
• Application
• Enhydra XMLC
![Page 3: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/3.jpg)
CGI Common Gateway Interface
• First We Have Static Web Pages
• Served by a Web Server to a Browser
• For Search or Buy on Line - Dynamic Web Page
• Enter CGI - Start Process for each request
• Request on standard input
• HTML page on standard output• URL http://www.ecst.csuchico.edu/~murphy/hellop.cgi
• test.cgi (bin/sh) hello.cgi (c program)
![Page 4: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/4.jpg)
CGI Perl script
• #!/usr/local/bin/perl
• #hello: a simple Perl example
• # TWO carriage returns after the content type.
• # This is important to end the header!
• print "Content-type: text/html\n\n";
• # Output a proper HTML document, with <head> and <body> tags.
• print "<head>\n";
• print "<title>Hello, World</title>\n";
• print "</head>\n";
• print "<body>\n";
• print "<h1>Hello, World</h1>\n";
• print "</body>\n";
• Could be cshell Script or Java or C etc. Program
![Page 5: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/5.jpg)
HTML source Generated
• <head>
• <title>Hello, World</title>
• </head>
• <body>
• <h1>Hello, World</h1>
• </body>
![Page 6: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/6.jpg)
HTML Forms and Java Servlets
• <HTML>
• <HEAD>
• <TITLE>Introductions </TITLE>
• </HEAD>
• <BODY>
• <FORM METHOD=GET ACTION="http://localhost:9004/">
• If you don't mind me asking, what is your name?
• <INPUT TYPE=TEXT NAME="name"><P>
• <INPUT TYPE=SUBMIT>
• </FORM>
• </BODY>
• <HTML>
• <HTML>
![Page 7: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/7.jpg)
Java Servlet Hello.java piece
• import java.io.*;
• import javax.servlet.*;
• import javax.servlet.http.*;
• public class Hello extends HttpServlet {
• public void doGet(HttpServletRequest req, HttpServletResponse res)
• throws ServletException, IOException {
• // Set the Content-Type header
• res.setContentType("text/html");
• // Return early if this is a HEAD
• if (req.getMethod().equals("HEAD")) return;
•
![Page 8: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/8.jpg)
Java Servlet Hello.java continued
• // Proceed otherwise
• PrintWriter out = res.getWriter();
• String name = req.getParameter("name");
• out.println("<HTML>");
• out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>");
• out.println("<BODY>");
• out.println("Hello, " + name);
• out.println("</BODY></HTML>");
• }
• public void doPost(HttpServletRequest req, HttpServletResponse res)
• throws ServletException, IOException {
• doGet(req, res);
• }
• }
![Page 9: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/9.jpg)
Servlets and eCommerce
• The Web is Stateless
• One servlet for all hits shares data members
• Amazon.com shopper visits many pages
• Need a private shopping cart
• Need a database connection
• Enter Application Servers and Enhydra
![Page 10: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/10.jpg)
Enhydra: #1 Open Source 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 20,000 downloads
• Over 1000 known participating developers
![Page 11: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/11.jpg)
Professional Services
Professional Services
OpenSource
Software
OpenSource
Software
Startup Incubation
Startup Incubation
Lutris
Lutris
Lutris Technologies, Inc.
Founded: July 1995
Employees: 210
Headquarters: Santa Cruz
Services
•eBusiness Analysis
•Architecture and Implementation
•Creative Design and Branding
Recently Funded by Chase, Hambrecht & Quist, Intel and Trans Cosmos
An Open Source Enterprise Software and Services Company
“Enhydra Lutris”
![Page 12: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/12.jpg)
The EnhydraSolutions Community
Open Source
Enhydra
Open Source
Enhydra
Lutris
Support
Professional Services
Add-On Products
Your Company
![Page 13: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/13.jpg)
Genesis
• Motivation for creating Enhydra:
– Commercial products weren’t ready in 1997
– Offer Lutris customers time-to-market value
– Java on the server for platform independence, group development, etc.
• First licensee: FedEx
• Second licensee: Kinko’s
• Continual pull from customers, (especially start-ups in pre-funding mode.)
![Page 14: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/14.jpg)
Value of Open Source to Lutris & Enhydra
• Lead Generation
• Bug Fixing
• Validate
• Features
• Development community
• Support community
• Internationalpresence
• 3rd party tools & modules
– e-mailBBS, Platypus
• Continue to be driven by real world requirements
• De facto standard
![Page 15: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/15.jpg)
www.enhydra.orgfor the Enhydra Community
• Mail lists & Working Groups– [email protected]
• Mail Archive/Search
• Case studies, News
• On-line Demos– Shopping Cart,
Chat Room, Poker
• 3rd party Services and Products
Working Groups:EJB ContainerWeb Container
I18NWireless
ArchitectureJMX
Rocks/XMLCDODS
Working Groups:EJB ContainerWeb Container
I18NWireless
ArchitectureJMX
Rocks/XMLCDODS
![Page 16: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/16.jpg)
Wizshop/Earthlink/Mindspring
Cisco LocalDirector
Cisco LocalDirector
•Sun E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
•Sun E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
The
Int
erne
t
•Sun E450•Oracle DB
•Sun E450•Oracle DB•Sun
E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
•Sun E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
![Page 17: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/17.jpg)
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
– Cluster Support
• Enhydra Application Framework
– “Superservlet Strategy”
• Enhydra Application Wizard (“Newapp”)
– Instant application to jumpstart development
• Enhydra DODS
– Graphical Object-to-SQL mapping application
![Page 18: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/18.jpg)
Enhydra Architecture
![Page 19: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/19.jpg)
Super Servlet Strategy
Enhydra Applications are Super Servlets that contain multiple presentation objects Connects URLs (*.po) and Java classes (presentation objects)
Shared session state/data across multiple URLs
Factoring of common functionality (DB Mgr, Pres Mgr, …)
Presentation objects generate HTML to produce dynamic content JDDI Compiler
XMLC Compiler (encouraged; example later)
![Page 20: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/20.jpg)
Enhydra Multi-Server
Manages the lifecycle of Enhydra Services ServletContainer (now has embedded services)
soon: EJB Container, DatabaseManager Service, …
Establishes connections to ServletContainer
Manages the server configuration file Defines initial state of Enhydra
Connection
JVMMultiServer
<multiserv.conf>
![Page 21: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/21.jpg)
Enhydra ServletContainer
Provides Web Server and Servlet execution HTTP server (will embed full Web Server later)
Runs existing Enhydra servlet applications
Servlet 2.2, JSP 1.1
Manages the lifecycle and connectivity of servlets and Enhydra Applications Provides custom class loader
Supports Connection via http, https, Director
Connection, Channel, Filter structure (more later)
Manages the ServletContainer configuration file section Defines initial state of each application
ServletContainer
![Page 22: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/22.jpg)
Enhydra Director
Connects non-Java web servers to Enhydra App Server Efficient protocol to ServletContainer
Portable design to various Web Servers
Provides load direction capability Map request to available ServletContainer
Session affinity
Header cookie URL rewrite Web
Server
EnhydraDirector
![Page 23: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/23.jpg)
ServletContainer
Connection, Channels & Filters
WebServer
EnhydraDirector
WebBrowser HTTP
WebBrowser HTTPS
WebBrowser
Channel
Connection
Servlet
RR
Servlet
RRChannel
ServletRR
Filter
ServletChannel
RR
R
Channel
![Page 24: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/24.jpg)
Administration Manager
Graphical tool to manage resource parameters HTML interface
Remote accessibility
Management Operation (shown later) Start/Stop applications or servlets
Add/Remove applications or servlets
Modify operational attributes of applications or servlets
Check status of applications or servlets
ServletContainer
Admin Mgr
![Page 25: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/25.jpg)
Presentation Manager Manages loading and execution of
presentation objects Translates URLs to Java classes (*.po)
Uses specified class loader to load classes
Ability to cache presentation objects
One instance per Enhydra application
Executes as a servlet HttpPresentationServlet class
One per Application
![Page 26: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/26.jpg)
Session Manager Provides session key
Cookie URL rewriting
Provides access to session objects Maintain state and user identity across multiple URLs
Session object is passed with each request
Generalized implementation
Session working set management Basic (in memory)
Page to disk
Page to Database
![Page 27: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/27.jpg)
Database Manager
Manages a connection pool Configurable connection pool size
Opened on an as needed basis and are reused
DBQuery Allocates connections from connection pool
Ensures integrity of connections
Manages result sets
DBTransaction Performs a commit or rollback on
inserts, updates, or deletes
![Page 28: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/28.jpg)
DBConnection Pools
![Page 29: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/29.jpg)
Architecture Summary
EnhydraNewApp
EnhydraXMLC
EnhydraDODS
MultiServer
ServletContainer
WebServer
EnhydraDirector
WebBrowser Admin Mgr
Connection
JVM
![Page 30: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/30.jpg)
Overview
• Development Tools
• Development Process
• Example Application
3-Tier Architecture• Database (Back-end)
• Business Logic (Middle-tier)
• Presentation Logic (User Interface)
• Example Code
• Application Deployment
Overview
![Page 31: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/31.jpg)
Enhydra Development Tools
• JBuilder 3 "Foundation"
+ XMLC Wizard
• vi/emacs + xmlc + javac
+ newapp (Utility) + make
• Run-time Debugging– with JBuilder (monitor Java threads, watch values)
– with multiserver (monitor HTTP request/response)
Development Tools
![Page 32: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/32.jpg)
Enhydra Development Tools
• JBuilder Foundation+ XMLC Wizard
![Page 33: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/33.jpg)
Enhydra Development Tools
• Command line tools
– The newapp utility generates "empty" Enhydra project:Directory structure
Stub application classes
make file
– The xmlc utility generates Java classes from HTML or XML templates (more on this later)
Form.html FormHTML.java
![Page 34: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/34.jpg)
Enhydra Development Tools
• What is XMLC?– A compiler for converting an HTML or XML
document into a DOM-compliant Java Object
• What is DOM?– Document Object Model
– W3C specification (www.w3c.org/DOM)
– A standard API to represent a structured document as a traversable tree with branches, nodes, and leaves
– Each markup element in the document becomes a node in the DOM, nested markup elements become child nodes
– Allows HTML documents to be traversed as a tree; nodes can be added, removed, modified, or cloned
![Page 35: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/35.jpg)
Enhydra Development Tools
• Debugging
– In JBuilder+ Multiserver Administration Console
![Page 36: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/36.jpg)
Dynamic
HTML
Dynamic
HTML
Enhydra Development Process
• Typical development steps involve:
• Create database schema
• Typical development steps involve:
• Create data access objects
• Typical development steps involve:
• Create business objects
• Typical development steps involve:
• Create presentation objects
• Typical development steps involve:
![Page 37: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/37.jpg)
Enhydra Multiserver
Enhydra Example Application
• Goal:
Display rows from a SQL query in an HTML table.
• Objects:– Application: App.java– Data: Data.java– Business: Biz.java– Presentation: Pres.java– Template: Table.html
(XMLC generates TableHTML.java)
HTTP Request
HTML Table
Example Java code…
![Page 38: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/38.jpg)
Example Code:
public class App extends StandardApplication {
private Biz biz = null;
public void startup(Config appConfig) throws ApplicationException { super.startup(appConfig);
logChannel.write(Logger.INFO,"Starting up the Example Application");
biz = new Biz(); //Instantiate the "Business" Object. }
public Biz getBiz() { return biz; //Return a reference to the Biz Object. }
} //end class App
App.java
public class App extends StandardApplication {
private Biz biz = null;
public void startup(Config appConfig) throws ApplicationException { super.startup(appConfig);
logChannel.write(Logger.INFO,"Starting up the Example Application");
biz = new Biz(); //Instantiate the "Business" Object. }
public Biz getBiz() { return biz; //Return a reference to the Biz Object. }
} //end class App
![Page 39: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/39.jpg)
Example Code:
public class Biz {
private int requests = 0; //Number of requests serviced.
public String[] getList() { requests++; //Increment the request count. return new Data().query(); //Return list of employee names. }
//Expose number of times a request has been made
public int getRequestCount() { return requests; //Return request count. }
} //end class Biz
Biz.java
public class Biz {
private int requests = 0; //Number of requests serviced.
public String[] getList() { requests++; //Increment the request count. return new Data().query(); //Return list of employee names. }
//Expose number of times a request has been made
public int getRequestCount() { return requests; //Return request count. }
} //end class Biz
![Page 40: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/40.jpg)
Example Code:
public class Data extends Vector {
public String[] query() { //Perform SQL database query.
try { //Use Enhydra database connection pool. DBConnection c = Enhydra.getDatabaseManager().allocateConnection(); ResultSet r = c.executeQuery("select ENAME from EMP"); while (r.next()) add(r.getString(1)); c.reset(); c.release(); // Be sure to release DBConnection... } catch (Exception e) { //...back into the connection pool! e.printStackTrace(); } //Explicit cast is required by compiler. return (String[])toArray(new String[] {}); }
} //end class Data
Data.java
public class Data extends Vector {
public String[] query() { //Perform SQL database query.
try { //Use Enhydra database connection pool. DBConnection c = Enhydra.getDatabaseManager().allocateConnection(); ResultSet r = c.executeQuery("select ENAME from EMP"); while (r.next()) add(r.getString(1)); c.reset(); c.release(); // Be sure to release DBConnection... } catch (Exception e) { //...back into the connection pool! e.printStackTrace(); } //Explicit cast is required by compiler. return (String[])toArray(new String[] {}); }
} //end class Data
![Page 41: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/41.jpg)
Example Code:
<html>
<head> <title>Employee Names</title> </head>
<body>
<table id="exampleTable" border="1" > <tr id="tableRow"> <td><span id="name">Employee Name<span></td> </tr> </table>
</body>
</html>
+ XMLC
Table.html
= TableHTML.java
DOM
HTMLTableRowElement getElementTableRow();
HTMLTableElement getElementExampleTable();
void setTextName();
+"Convenience methods":
![Page 42: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/42.jpg)
Example Code:
public class Pres implements HttpPresentation {
public void run(HttpPresentationComms c) throws HttpPresentationException { TableHTML tableDOM = new TableHTML(); //Generated by XMLC. Biz b = ((example.App)c.application).getBiz(); //Business object. fillTable(tableDOM, b.getList()); //Populate the table. c.response.writeHTML(tableDOM.toDocument()); //Display the table! }
private void fillTable(TableHTML tableDOM, String[] list) { //Manipulate table related elements of DOM. HTMLTableElement table = tableDOM.getElementExampleTable(); // Add new row... for (int i = 0 ; i < list.length ; i++) //...elements to DOM table.appendChild(createNewRow(tableDOM, list[i])); }…
Pres.java
TableHTML tableDOM = new TableHTML();
fillTable(tableDOM, b.getList()); c.response.writeHTML(tableDOM.toDocument());
private void fillTable(TableHTML tableDOM, String[] list)
HTMLTableElement table = tableDOM.getElementExampleTable();
HTMLTableElement table = tableDOM.getElementExampleTable();
![Page 43: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/43.jpg)
Example Code:Pres.java
…
private HTMLTableRowElement createNewRow(TableHTML tableDOM, String name ) { tableDOM.setTextName(name); //Set the <SPAN> text.
return (HTMLTableRowElement) //Return the row element. tableDOM.getElementTableRow().cloneNode(true);
}
} //end class Pres
(cont)
…
private HTMLTableRowElement createNewRow(TableHTML tableDOM, String name ) { tableDOM.setTextName(name); //Set the <SPAN> text.
return (HTMLTableRowElement) //Return the row element. tableDOM.getElementTableRow().cloneNode(true);
}
} //end class Pres
…
private HTMLTableRowElement createNewRow(TableHTML tableDOM, String name ) { tableDOM.setTextName(name); //Set the <SPAN> text.
return (HTMLTableRowElement) //Return the row element. tableDOM.getElementTableRow().cloneNode(true);
}
} //end class Pres
![Page 44: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/44.jpg)
Enhydra Application Development
• make
(…and then a miracle occurs…)
![Page 45: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/45.jpg)
Enhydra Application Deployment
• Example.conf
Server.ClassPath[] = "/enhydra/classes/example.jar"
Server.AppClass = "example.App"
Server.PresentationPrefix = "example/presentation"
Application.DefaultUrl = "Pres.po"
• Created by JBuilder Application Wizard
• …or by running newapp
• …automagically!
![Page 46: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/46.jpg)
Enhydra Application Deployment
• Example.conf (cont.)DatabaseManager.Databases[] = "Example"
DatabaseManager.DefaultDatabase = "Example"
DatabaseManager.DB.Example.ClassType = "Oracle"
DatabaseManager.DB.Example.JdbcDriver = "oracle.jdbc.driver.OracleDriver"
DatabaseManager.DB.Example.Connection.Url = "jdbc:oracle:thin:@artemis:1521:SID2"
DatabaseManager.DB.Example.Connection.User = "scott"
DatabaseManager.DB.Example.Connection.Password = "tiger"
DatabaseManager.DB.Example.ObjectId.CacheSize = 0
![Page 47: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/47.jpg)
Enhydra Application Deployment
• multiserver.conf
Application.Example.ConfFile = "Example.conf"Application.Example.Description = "Example Enhydra Application"Application.Example.Running = "yes"
Connection.Http8001.Type = "http"Connection.Http8001.Port = 8001
Channel.Http8001.ExampleChannel.Servlet = "Example"Channel.Http8001.ExampleChannel.Url = "/"Channel.Http8001.ExampleChannel.Enabled = "yes"
• Created by Enhydra Administration utility
• …automagically!
![Page 48: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/48.jpg)
Enhydra Application Deployment Adding "Example"• Enhydra Administration:
Example
![Page 49: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/49.jpg)
Enhydra XMLC
Separate Graphics from Code
![Page 50: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/50.jpg)
What is XMLC?
• XMLC = XML Compiler
• XMLC - Compiles an HTML or XML document into a DOM (Document Object Model)-compliant tree that can then be used as a java object which can reconstruct that document
• Provides object-oriented access to HTML or XML document templates
• Convenience getElement...() and setText…() direct accessor methods are additionally compiled into the document to facilitate common tasks
![Page 51: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/51.jpg)
...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 rows can be used as templates for other rows.
![Page 52: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/52.jpg)
Embedded Page Languages: Bad Idea!• HTML is developed by graphic artists
– Authoring programs can break the code
– Pages with mocked-up data are 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
![Page 53: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/53.jpg)
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 I18N
![Page 54: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/54.jpg)
JSP Example
<HTML><%@ page language==“java”
imports==“com.wombat.JSP.*” %><H1>Welcome</H1><P>Today is </P><jsp:useBean id==“clock”
class==“calendar.jspCalendar” /><UL><LI>Day: <%==clock.getDayOfMonth() %><LI>Year: <%==clock.getYear() %></UL><% if (Calendar.getInstance().get(Calendar.AM_PM)
== Calendar.AM) { %>Good Morning<% } else { %>Good Afternoon<% } %><%@ include file==“copyright.html” %></HTML>
![Page 55: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/55.jpg)
An HTML Example
<TABLE> <TBODY> <TR> <TH>Name</TH> <TH>City</TH> </TR> <TR> <TD>John Doe</TD> <TD>Atlanta</TD> </TR> </TBODY> </TABLE>
![Page 56: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/56.jpg)
DOM Representation
ID=custName ID=city
![Page 57: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/57.jpg)
Adding ID Attributes
<TABLE> <TBODY> <TR> <TH>Name</TH> <TH>City</TH> </TR> <TR> <TD ID=“custName”>John Doe</TD> <TD ID=“city”>Atlanta</TD> </TR> </TBODY> </TABLE>
![Page 58: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/58.jpg)
Enhydra XMLC
![Page 59: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/59.jpg)
Java DOM Package
• Document: Root of tree
– Provides factory methods for other DOM classes
• Node: Base class of all DOM tree objects
– Contains children and parent links
– Provides methods for manipulating the tree
• Element: Interface for XML tag classes
– Extends Node
– Specific applications may define classes that extend Element (e.g., HTMLTableElement, etc.)
• Text: Nodes that contain the document text
![Page 60: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/60.jpg)
Java DOM HTML Package
• org.w3c.dom.html
– DOM Interfaces for HTML
• HTMLDocument - Root of the HTML hierarchy• HTMLHeadElement - <HEAD>• HTMLBodyElement - <BODY>• HTMLParagraphElement - <P>• HTMLAnchorElement - <A>• HTMLTableElement - <TABLE>• HTMLFontElement - <FONT>• …more…
![Page 61: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/61.jpg)
Simple XMLC ExampleHTML - Hello.html
<H1><FONT ID=“HeadFont” SIZE=“4” COLOR=“red”>Hello World</FONT></H1><P>Hello, my name is <SPAN ID=“CustName”>John Doe</SPAN>
Using the Generated Class HelloHTMLHelloHTML hello = new HelloHTML();HTMLFontElement hfont = hello.getElementHeadFont();hfont.setColor(“Green”);hello.setTextCustName(“Barney Blake”);out.println(hello.toDocument());
![Page 62: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/62.jpg)
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=“CustName”>…</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
![Page 63: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/63.jpg)
Development with Enhydra XMLC
welcome.html
xmlc -class myapp.WelcomeHTML welcome.html
javac
myapp.WelcomeHTML
![Page 64: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/64.jpg)
… Work Flow ...
• XMLC generates “getElement<IDName>()” and “setText<IDName>()”methods in the document object, e.g.
getElementCustName()and setTextCustName() for each ID-tagged HTML page element
• At run-time the programmer instantiates the HTML page as an object and manipulates its properties
![Page 65: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/65.jpg)
…Work Flow
• The programmer can use the XMLC-generated methods like getElementCustName()to clone, remove, or otherwise manipulate page elements
• The programmer can also traverse the DOM tree to manipulate its other nodes directly if desired
• Finally toDocument() is called on the page object to stream the page to the web client as a string
![Page 66: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/66.jpg)
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
![Page 67: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/67.jpg)
...Advantages
• HTML storyboard can be demo’d and modified 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 java environment, such as BEA WebLogic
![Page 68: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/68.jpg)
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
![Page 69: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/69.jpg)
Toward J2EE Enhydra
Other Open Source contributions,including on-going Enhydra evolution
JOnAS,BullSoft
Jonathan,France Telecom
![Page 70: Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML Application Server James Murphy UC Santa Cruz January 2001](https://reader038.vdocuments.us/reader038/viewer/2022103022/56649d6b5503460f94a4ae96/html5/thumbnails/70.jpg)
Open Source Java/XML Application ServerOpen Source Java/XML Application Server