Tải bản đầy đủ (.pdf) (50 trang)

Tài liệu XML, XSLT, Java, and JSP: A Case Study in Developing a Web Application- P10 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.74 MB, 50 trang )

432
Chapter 11 XML Data Storage Class: ForestHashtable
wally::Hey! I’m here charlie. Are you there?
</message>
<chat nodeKey=”
965503120064.965501552059.965501551959
” moderated=”
no

itemKey=”
965503120084.965501558519.965501558509
”>
<guestKey nodeKey=”
965506098637.965503120064.965501552059
”>
965506098557.965501551999.965501551959
</guestKey>
<messageKey nodeKey=”
965503142136.965503120064.965501552059
”>
965503142126.965501552059.965501551959
</messageKey>
<hostKey nodeKey=”
965503120074.965503120064.965501552059
”>
965503119944.965501551999.965501551959
</hostKey>
</chat>
</things>
</bonForum>
11.12.1 Chat Data in the XML Data Example


At the time the bonForum data was dumped to an XML file, two chats had been
started.The nicknames and ages of the two chat hosts are stored inside
host
elements
as children of the
actors
element. Only one guest has joined a chat, and that guest’s
nickname and age are stored in a
guest
element also as a child of the
actors
element.
Adam is the host of a topic with the subject Vehicles.Trucks.Other and the topic
“my other truck is a ferrari.” Adam is still awaiting his first guest, and only his own
single message appears in the chat. It could be displayed as follows:
[Saturday 05 09:08:09 2000]
adam::this is dynamite!
Charlie is the host of a chat with the subject Animals.Fish.Piranhas and the topic “pet
piranha stories.” Charlie and his guest,Wally, have each entered one message to the
chat, which could be displayed as follows:
[Saturday 05 09:19:02 2000]
charlie::Is anybody there?
[Saturday 05 10:09:35 2000]
wally::I’m here, charlie.
11.13 More ForestHashtable Considerations
In this last part of this chapter, we will mention a few final things that are important
to the understanding and future development of the
ForestHashtable
class.
11.13.1 Some Important Data Characteristics

In the example of bonForum XML data content at runtime shown previously, you can
notice the following two characteristics of the way the chat data is kept in the
ForestHashtable
:
11 1089-9 CH11 6/26/01 7:36 AM Page 432
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
433
11.13 More ForestHashtable Considerations
1. The objects stored in a
Hashtable
have no order.Therefore, the order of sibling
elements in the XML document has no meaning. For human readability, if that
is needed, some XML elements could be sorted by modifying the XSLT style
sheet. Sorting could also be implemented by changing the underlying data struc-
ture to a
SortedMap
implementer, such as
TreeMap
, or by keeping an external
sorted index in the manner of an RDB.
2. The
NodeKey
values are referred to by other key attributes, to relate the informa-
tion in different elements together. For example, a chat element has a
hostKey
child that contains the value of the chat’s host’s
NodeKey
.That is why we pre-
serve the
NodeKey

values in
NodeKey
” attributes within each element when the
XML is output from the
ForestHashtable
.
11.13.2 Setting ForestHashtable Capacity
By reading the API documentation on the
java.util.Hashtable
class, you can learn
about the issue of the capacity of a
Hashtable
object.The only way we have dealt
with this so far is to provide a constructor for the class that takes an argument called
capacity
, which (surprise!) sets the capacity of a
ForestHashtable
.
The idea is that this capacity setting can be determined by the Web application,
perhaps by having it saved as a parameter in the Web app deployment descriptor
(web.xml) of the application. For the bonForum Web chat application example, we set
the capacity to 5000.This number was selected by estimating 200 bytes per node.
More testing is necessary to tune this factor, which is very important for the experi-
ence of using the Web application. Setting the capacity correctly can minimize the
inevitable rehashing time.
11.13.3 XPATH Modeling Planned
One premise behind the design of
ForestHashtable
is that is could be easier or faster
to manipulate a triple-valued key than to work with the (infinitely) long path expres-

sions that can be present in an XML data document.The hierarchy of nodes can be
modeled as a forest of trees by a table with a double- or triple-valued key.
A plan for the future is to see if we can create methods that fulfill all the XPATH
functionality solely by processing the keys in the table.
11.13.4 Self-Healing XML Documents
Another idea of ours is to create an XML document representation that would create,
by default, any “missing” set of nodes.These nodes that would be supplied form a
node path connection between a “disconnected” XML fragment and the “closest”
existing related node.
Why do that? Because that means you can put a tree-fragment into empty space in
the forest.Then you could either tell or ask the forest to “decide” which tree the frag-
11 1089-9 CH11 6/26/01 7:36 AM Page 433
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
434
Chapter 11 XML Data Storage Class: ForestHashtable
ment belongs in.This would cause the forest to “grow” any necessary branches to con-
nect the fragment with the tree, thus creating one new tree that can be expressed as a
valid XML document.
Two practical outcomes appear here. First, if the keys for the forest are globally
unique identifiers, you can throw together two or more forests of data, and they will
still function as a forest (that is, the keys will not clash).That would be great for mix-
ing data from laptops and servers, for example. Second, the self-sticking tree fragment
addition to the forest means that relations among combined data sets can be “patched”
by using default values, which preserves displayability and processability, in many cases.
It might even keep your browser from choking!
11.13.5 Improvement of Algorithms
Much of the code in this class, as in the bonForum project in general, is intentionally
written in a “dumb” style, leaving much room for optimization. Rather than trying to
get too smart and doing many things in one statement, we think that it is easier to
debug code that is spread out over smaller steps. Our motto is, “First get it working,

and then get it working right!”
moveNode()
Further optimization will include addition of new methods. One candidate, for exam-
ple, is a
moveNode()
method that would have the following signature:
moveNode(NodeKey KeyOfNodeToMove, NodeKey KeyOfNewParentNode, Boolean IfLeafOnly);
The
moveNode()
method would also have a
leafOnly
argument, as the
deleteNode()
method does. If
IfLeafOnly
is
true
, then the node would not be moved if it has one
or more child nodes. If
IfLeafOnly
is
false
, then the node and all its descendants
would be moved.
Another argument called
NewParentNode
would tell the method the destination to
which it should move a node. If the
NewParentNode
is null, then the

NodeToMove
would
be made a root node in the forest.
11.13.6 Enforcing Uniqueness Among Nodes
In the
addNode()
method of
ForestHashtable
, uniqueness is enforced for
nodeNameHashtable
entries.When we remove an “old” cached
NodeKey
from
the
nodeNameHashtable
, we cannot simultaneously remove the node in the
ForestHashtable
because it may be in use in other thread.
However, we need to enforce unique sibling names in some situations—for exam-
ple within descendant levels of the Subjects subtree in the bonForum Web chat appli-
cation XML data. Also, at least in that application of the
ForestHashtable
, we would
like to somehow enforce unique
chatTopic
values and
nickName
values by using a
mechanism intrinsic to the
ForestHashtable

.This is left as a task for a future time.
11 1089-9 CH11 6/26/01 7:36 AM Page 434
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
435
11.13 More ForestHashtable Considerations
11.13.7 Usability of the ForestHashtable Class
Without having tested the
ForestHashtable
experimental class sufficiently, it is not yet
possible to characterize its runtime performance versus the quantity of data and thread
loading. Certainly, processing will slow down at some point, but that depends on many
factors, including the hardware on which it is running.
ForestHashtable Is a Design Laboratory
The
ForestHashtable
class is primarily a design laboratory.We will be implementing
some of the ideas tried out there in a relational database system.You are invited to
bring your comments and participation to

, our open source
site for the bonForum project on SourceForge.
11 1089-9 CH11 6/26/01 7:36 AM Page 435
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
11 1089-9 CH11 6/26/01 7:36 AM Page 436
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
Online Information Sources
12
T
HESE
I

NTERNET LINKS ARE MOSTLY
to XML, XSLT, Java servlet, and JSP informa-
tion. Some cover what was left out of this book, intentionally or otherwise. Some link
to topics that were discussed in this book.To keep current with all these technologies,
you might want to subscribe to some mailing list groups and search and surf the Web
frequently.This list does not pretend to be complete or fair—it simply offers some
starting points on the Internet. It also is available on the CD-ROM accompanying this
book and online at
www.bonForum.org
, where you can click on the links. Our apolo-
gies go out to all the developers who have been ignored—we promise that it was not
done intentionally!
12.1 Always Useful Sites
Web site for the bonForum Web application project

A fun and smart way to search the Web
/>A huge number of Java links from Cetus Links
/>XML-based information retrieval

12 1089-9 CH12 6/26/01 7:37 AM Page 437
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
438
Chapter 12 Online Information Sources
A great multilingual text editor

The World Wide Web Consortium
/>W3C recommendations
/>Internet Engineering Task Force
/>Mailing lists and archives
/> />Sun Java Forums

/>12.2 Apache Software Foundation
Apache Software Foundation
/>Apache Conference
/>Apache mailing lists
/> />News about Apache
/>12.3 Big Corporations
IBM

IBM Alphaworks
/>IBM DeveloperWorks
/>Microsoft
/>MSDN
/>Sun Microsystems

12 1089-9 CH12 6/26/01 7:37 AM Page 438
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
439
12.7 HTTP
Sun Developers
/>12.4 CSS
Cascading Style Sheets information
/>CSS and XSL overview
/>12.5 DOM Information
Recommendations
/>DOM Scripting WebRing
/>XML via the Document Object Model
/>12.6 HTML
Recommendations
/> />HTML reformulated as XML
/>Web Developers Library links for HTML

/>The HTML Guide
/>12.7 HTTP
Description of HTTP
/>12 1089-9 CH12 6/26/01 7:37 AM Page 439
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
440
Chapter 12 Online Information Sources
12.8 Java
12.8.1 Java: Compilers and SDKs
Java 2 SDK, Standard Edition, download
/>12.8.2 Java: Books, Articles, and Magazines
Thinking in Java, free downloadable book
/>Java Developer’s Journal
/>JBuilder Developer’s Journal
/>The Swing Connection
/>12.8.3 Java: Information
Sun BluePrints design guidelines for J2EE
/>Enterprise JavaBeans technology
/>Information on setting the class path
/>About three-tier distributed architecture at Java Report Online
/>Tomcat servlet and JSP development with VisualAge for Java
/>Java extensions FAQ
/>Bridging Java and Active X with Java plug-in scripting
/>12.8.4 Java: Language
The Java Language Specification: Gosling
/> />12 1089-9 CH12 6/26/01 7:37 AM Page 440
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
441
12.9 JavaServer Pages
Code conventions for the Java Programming Language contents

/>12.8.5 Java: Resources
Bruce Eckel’s MindView, Inc., OOP resources
/>Java programming resources at Gamelan.com
/>12.8.6 Java: Tools
JavaBeans and BDK1.1
/>Forte for Java, free Community Edition
/>ElixirIDE

Java Beanshell: interactive Java shell

JPython
/>IBM alphaWorks Bean Scripting Framework
/>Java for Linux
/>12.8.7 Java: Tutorials
The Java Tutorial
/>12.9 JavaServer Pages
12.9.1 JSP: Main Web Site
JavaServer Pages technology
/>12 1089-9 CH12 6/26/01 7:37 AM Page 441
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
442
Chapter 12 Online Information Sources
12.9.2 JSP: Specifications
JavaServer Pages (JSP) Specfication,Version 1.1
/>12.9.3 JSP: Books
JavaServer Pages book
/>Group writing a JSP book online
/> />12.9.4 JSP: Companies
Information about commercial products supporting JSP
/>tarent GmbH


12.9.5 JSP: FAQ
Sun JSP FAQ
/>Good FAQ for JSP, maintained by Richard Vowles
/>12.9.6 JSP: Hosting
Free server space on the Internet, including Java servlet and JSP support

12.9.7 JSP: Information
JSP syntax cards, tutorials, a technical FAQ, and various presentations
/>JavaServer Pages technology: white paper
/>Chat about JavaServer Pages
/>jl0222.html
12 1089-9 CH12 6/26/01 7:37 AM Page 442
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
443
12.10 Java Servlets
JSP versus ASP
/>ml
Introduction to JavaServer Pages
/>12.9.8 JSP: Taglibs
Example
/>12.9.9 JSP: Tutorials
JavaServer Pages tutorial
/>Servlet and JSP short courses
/>Basic JSP tutorial
/>IBM tutorial on JSP
/>12.10 Java Servlets
12.10.1 Servlets: Main Web Site
Servlet Web site at Sun
/>12.10.2 Servlets: Specifications

Servlet implementations and specifications
/>Servlet API Javadoc online
/>12.10.3 Servlets: Books, Articles, and Magazines
Server-side Java magazine online

12 1089-9 CH12 6/26/01 7:37 AM Page 443
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
444
Chapter 12 Online Information Sources
12.10.4 Servlets: Companies
JRun developer Web Site
/>tarent GmbH

12.10.5 Servlets: Hosting
Free server space on the Internet, including Java servlet and JSP support

Servlet hosting
/> /> />12.10.6 Servlets: Information
Good overview of servlets
/>Information about servlets
/>12.10.7 Servlets: Mailing Lists
Archives of

/>12.10.8 Servlets: Resources
Jason Hunter’s Web site

Free, open source Java servlets

Servlets Taverne, with links to information in French
/>Information on XML, Java, JDBC, and servlets by Nazmul Idris

/>12 1089-9 CH12 6/26/01 7:37 AM Page 444
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
445
12.12 Open Source
12.10.9 Servlets: Tutorials
Servlets tutorial
/>12.11 Linux
Linux Open Source Magazine
/>Java Programming on Linux, the book
/>12.12 Open Source
Online book: Open Sources:Voices from the Open Source Revolution
/>Eric S. Raymond’s The Cathedral and the Bazaar
/>SourceXchange
/>The Open Source Page
/>The Techie-Hacker’s Case for Open Source
/>Ask Tim at O’Reilly
/>ExoLab.org Open Source & Enterprise Java
/>Free support for Open Source projects
/>Licensing Open Source Software: Jason Hunter’s license
/>ClueTrain Manifesto

Mozilla
/>Open source version control software
/>Open XML
/>12 1089-9 CH12 6/26/01 7:37 AM Page 445
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
446
Chapter 12 Online Information Sources
Open Source Enhydra Java-XML Application Server Home
/>Free XML software

/>12.13 RDF
Resource description framework
/>12.14 Web Applications
Open Source Enhydra Java-XML Application Server Home
/>IBM white paper, “The Web Application Programming Model”
/>XML:The Key to E-Business
/>IBM white papers
/>12.15 Web Browsers
Microsoft Internet Explorer 5.5
/>MSDN Online Voices: Extreme XML
/>Information about IE5.5 XML
/> />Mozilla (open source Netscape Web browser)
/>12.16 Web Servers
Apache Server
/>Jigsaw Web Server (W3C)
/> />12 1089-9 CH12 6/26/01 7:37 AM Page 446
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
447
12.17 XML
Jakarta Tomcat main Web site
/>FAQ index for Tomcat
/>Latest Tomcat Users Guide
/>tomcat-ug.html
12.17 XML
12.17.1 XML: Specs and Recommendations
W3C recommendation
/>XML.com:The Annotated XML Specification
/>Specifications of all XML-related technologies
/>12.17.2 XML: Articles, Books, and Magazines
XML Developer’s Journal

/>XML Books: Mastering XML from Sybex
/>Writings of Benoit Marchal
/>Articles by Jon Bosak
/>XML Developers Conference proceedings
/>An Introduction to XML for Java Programmers
/>pmwin99.asp
Fatbrain.com: books about XML
/>12 1089-9 CH12 6/26/01 7:37 AM Page 447
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
448
Chapter 12 Online Information Sources
12.17.3 XML: Companies
Bluestone Software, Inc.

tarent GmbH

12.17.4 XML: Editors and Tools
Links and information for many XML editors
/>Free XML software
/>XMLwriter
/>XMetal
/>XML Spy
/>Xeena and visual XML tools from IBM
/>Visual XML
/>12.17.5 XML: Examples
All Shakespeare works in XML
/>An XML-based project for instant messaging
/>XMLBinder and XSLServlet projects
/>12.17.6 XML: Information
Anything related to XML

/>XML Global

XML Search Engine People

12 1089-9 CH12 6/26/01 7:37 AM Page 448
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
449
12.17 XML
Cafe con Leche XML news and resources
/>Extensible Markup Language (XML)
/>Chinese XML Now (English home page)
/>MSDN Online XML Developer Center
/>XMLHack: great way to keep current on XML

Pineapplesoft Online Java, XML from Belgium (Benoit Marchal)
/>IBM developerWorks XML Standards: Describing Data
/>XML APIs for databases
/>Activity in the XML world
/>XML in Spanish

XML, Java, JDBC, and servlets information
/>12.17.7 XML: Mailing Lists
Apache XML Project mailing lists
/>XML-DEV for XML developers around the world:To subscribe to this list, send an
email message to

with “subscribe xml-dev ”
in the body.
XML-DEV archive
/>The xmlhack Daily News Digest

/>12.17.8 XML: Microsoft
XML-related product downloads
/>12 1089-9 CH12 6/26/01 7:37 AM Page 449
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
450
Chapter 12 Online Information Sources
Information about MSXML
/>An XML manifesto
/>MSDN Online XML Developer Center
/>XML Magazine
/>12.17.9 XML: Namespaces
W3C recommendation
/>12.17.10 XML: Organizations
Oasis XML and SGML organization

XML.ORG:The XML Industry Portal, hosted by OASIS
/>Biztalk.org
/>12.17.11 XML: Parsers
Apache XML Project
/>Open XML
/>XML Parser for Java, another alphaWorks technology
/>XP
/>Expat
/>Python XML parser
/>TclXML
/>Fxp, a parser written in SML
/>12 1089-9 CH12 6/26/01 7:37 AM Page 450
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
451
12.17 XML

12.17.12 XML: SAX API
Megginson Technologies, Ltd.
/>SAX:The simple API for XML
/>12.17.13 XML: SVG
W3C Scalable Vector Graphics (SVG)
/>The SVG viewer applet demos
/>12.17.14 XML: Tutorials
Very complete XML tutorial, based on JAXP
/>Tutorial on XML and Java

Zvon tutorials
/>IBM developerWorks XML Education: online courses
/>transforming-xml-to-html/index.html
Introduction to XML
/>XML and Java
/>XML for Linux
/>The Foundation XML, XSL, X-Link
/>Good online XML guide slanted toward Microsoft version of XML
/>12.17.15 XML: XHTML
HTML reformulated as XML
/>12 1089-9 CH12 6/26/01 7:37 AM Page 451
Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

×