Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 50 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
50
Dung lượng
1,74 MB
Nội dung
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 ina 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 ina 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 ina “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 ina relational database system.You are invited to bring your comments and participation to http://www.bonforum.org , 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 http://www.bonForum.org A fun and smart way to search the Web http://www.links2go.com/ A huge number of Java links from Cetus Links http://www.cetus-links.org/oo_java.html XML-based information retrieval http://www.goxml.com 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 http://www.textpad.com The World Wide Web Consortium http://www.w3c.org/ W3C recommendations http://www.w3.org/TR/#Recommendations Internet Engineering Task Force http://www.ietf.org/ Mailing lists and archives http://archives.java.sun.com/cgi-bin/wa http://archives.java.sun.com/archives/index.html Sun Java Forums http://forum.java.sun.com/ 12.2 Apache Software Foundation Apache Software Foundation http://www.apache.org/ Apache Conference http://apachecon.com/ Apache mailing lists http://xml.apache.org/mail.html http://jakarta.apache.org/getinvolved/mail.html News about Apache http://slashdot.org/index.pl?section=apache 12.3 Big Corporations IBM http://www.ibm.com IBM Alphaworks http://www.alphaworks.ibm.com/ IBM DeveloperWorks http://www.ibm.com/developer/ Microsoft http://www.microsoft.com/ MSDN http://msdn.microsoft.com/ Sun Microsystems http://www.sun.com 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 http://www.sun.com/developers/ 12.4 CSS Cascading Style Sheets information http://www.w3.org/TR/REC-CSS2/ CSS and XSL overview http://www.w3.org/Style/Activity 12.5 DOM Information Recommendations http://www.w3.org/TR/#Recommendations DOM Scripting WebRing http://nav.webring.org/hub?ring=domscript;list XML via the Document Object Model http://wdvl.com/Authoring/Languages/XML/DOM/Intro/ 12.6 HTML Recommendations http://www.w3.org/TR/html401/ http://www.w3.org/TR/REC-html32 HTML reformulated as XML http://www.w3.org/TR/xhtml1/ Web Developers Library links for HTML http://wdvl.com/Authoring/HTML/ The HTML Guide http://www.webfrontier.org/html/index.html 12.7 HTTP Description of HTTP http://www.ietf.org/rfc/rfc2068.txt 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 http://java.sun.com/j2se/1.3/download-windows.html 12.8.2 Java: Books, Articles, and Magazines Thinking inJava, free downloadable book http://www.bruceeckel.com/TIJ2/index.html Java Developer’s Journal http://www.sys-con.com/java/newjava.cfm JBuilder Developer’s Journal http://www.sys-con.com/jbuilder/index.html The Swing Connection http://java.sun.com/products/jfc/tsc/articles/index.html 12.8.3 Java: Information Sun BluePrints design guidelines for J2EE http://java.sun.com/j2ee/blueprints/ Enterprise JavaBeans technology http://java.sun.com/features/1999/12/ejb.html Information on setting the class path http://java.sun.com/products/jdk/1.2/docs/tooldocs/win32/classpath.html About three-tier distributed architecture at Java Report Online http://www.javareport.com/html/features/archive/9804/reese.shtml Tomcat servlet and JSP development with VisualAge for Java http://www7.software.ibm.com/vad.nsf/data/document2389?OpenDocument Java extensions FAQ http://java.sun.com/products/jdk/1.2/docs/guide/extensions/ext_faq.html Bridging Java and Active X with Java plug-in scripting http://java.sun.com/products/plugin/1.2/docs/script.html 12.8.4 Java: Language The Java Language Specification: Gosling http://java.sun.com/docs/books/jls/html/index.html http://java.sun.com/docs/books/jls/html/1.1Update.html 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 http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html 12.8.5 Java: Resources Bruce Eckel’s MindView, Inc., OOP resources http://www.bruceeckel.com/ Java programming resources at Gamelan.com http://www.gamelan.com/ 12.8.6 Java: Tools JavaBeans and BDK1.1 http://java.sun.com/products/javabeans/ Forte for Java, free Community Edition http://www.sun.com/forte/ffj/ce/ ElixirIDE http://elixirtech.com Java Beanshell: interactive Java shell http://www.beanshell.org JPython http://www.jpython.org/ IBM alphaWorks Bean Scripting Framework http://www.alphaworks.ibm.com/tech/bsf Java for Linux http://blackdown.org/ 12.8.7 Java: Tutorials The Java Tutorial http://java.sun.com/docs/books/tutorial/index.html 12.9 JavaServer Pages 12.9.1 JSP: Main Web Site JavaServer Pages technology http://java.sun.com/products/jsp/ 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. [...]... DAMAGE NOTE:This software is provided for tutorial use! It is part of bonForum, aWeb chat application that is fully discussed in a book by Westy Rockwell called XML,XSLT,Java,andJSP: A CaseStudyinDevelopinga Web Application,” published by New Riders Publishing (http://www.newriders.com/).This book is published in German as XML,XSLT,Java, und JSP: Eine Professionelle Webapplikation Programmieren”... “http://java.sun.com/j2ee/dtds /web- app_2.2.dtd”> bonForum Webmaster email@bonforum.org Logging Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 15 1089-9 XC 6/26/01 7:40 AM Page 466... to use and modify the Web applications featured in this book, you need the Sun Java SDK Information about obtaining and installing the Java SDK is given in the first two chapters of this book, as well as at http://java.sun.org, from where you may download the SDK \Apache The Apache folder and its subfolders contain three open source product releases from the Apache Software Foundation, which are fully... originally based on software copyright 1999, International Business Machines, Inc., http://www.apache.org For more information on the Apache Software Foundation, please see http://www.apache.org/ Apache Xalan License The Apache Software License, version 1.1 Copyright 1999 The Apache Software Foundation All rights reserved Redistribution and use in source and binary forms, with or without modification,... contact apache@apache.org 5 Products derived from this software may not be called “Apache,” nor may “Apache” appear in their names without prior written permission of the Apache Group THIS SOFTWARE IS PROVIDED “AS IS,” AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED IN NO EVENT SHALL... software should be portable to other operating systems, because it is all written inJava, JSP, HTML, XML,and so on, but no guarantees of any kind can be given Please check the Web site at http://www.bonforum.org for possible information about using the software with operating systems other than Windows NT 4.0.That Web site also lists known problems, fixes, and updates for the software featured in this... 12.16 Web Servers Apache Server http://www.apache.org/httpd.html Jigsaw Web Server (W3C) http://www.w3.org/Jigsaw/ http://www.w3.org/Jigsaw/User/Introduction/wp.html Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark 12 1089-9 CH12 6/26/01 7:37 AM Page 447 12.17 Jakarta Tomcat main Web site http://jakarta.apache.org/ FAQ index for Tomcat http://jakarta.apache.org/faq/faqindex.html... http://msdn.microsoft.com/xml/default.asp XMLHack: great way to keep current on XML http://xmlhack.com Pineapplesoft Online Java, XML from Belgium (Benoit Marchal) http://www.pineapplesoft.com/ IBM developerWorks XML Standards: Describing Data http://www2.software.ibm.com/developer/standards.nsf/xml-describing-byname XML APIs for databases http://developer.java.sun.com/developer/technicalArticles/xml/api/ Activity in the XML... Page 466 466 Appendix C Source Code for bonForum Web Application all BonForumEngine de.tarent.forum.BonForumEngine bonfoo47 bonbar47 snoop SnoopServlet... appear in their name, without prior written permission of the Apache Software Foundation THIS SOFTWARE IS PROVIDED “AS IS,” AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, . this watermark. 447 12.17 XML Jakarta Tomcat main Web site http://jakarta.apache.org/ FAQ index for Tomcat http://jakarta.apache.org/faq/faqindex.html Latest. 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