logo
 
Assignment Two
CS 6890 - Web-based Database Management Systems
Utah State University
Home
Lectures
Homework   
Syllabus
Resources
People

Overview

Weight: The homework will count 11% of your final grade.
Due Date Thursday, March 6 (by 11:59PM)
This assignment is to implement a system to query XML. The query language will be a subset of XPath. Part of the assignment is in the tarred, gzipped, directory two.tar.gz (also available as two.zip You may do the assignment using Windows or Linux.

The results of running some tests are also available in the tarred, gzipped, directory tests.tar.gz or as a zip file tests.zip. The test code is in the xpath package in the assignment directory, e.g., Attribute.java.

Groups

We will not grade groups differently than individuals. Forming a group will usually result in less work for each group member, but you may choose to do the assignment individually if you so desire. To register your group, please follow the instructions at groups.htm. Once a group is formed, there will be no changes to the group for any reason. Ideally, each group will be happy and harmonious, but if not, then you are responsible for the entire assignment.

Turnin

All code should be developed in the #!two directory. Turnin in the assignment as many times as you like using the turnin page. You may turn in two.zip, two.tar or two.tar.gz.

To create a tarred, gzipped copy of your directory using the Makefile do the following.

  make tar
It will do a make clean to first remove all of the .class files in your directory. It will then create the file two.tar.gz in your directory.

Documentation

All documentation should be done using javadoc.

Grading

The assignment will be graded for good programming style (indentation and appropriate comments), as well as clean compilation and execution (the programs should work).

Makefile

The Makefile has targets to compile and test your code, as in the previous assignment.

xpath package

Develop a Java package for xpath. (By convention, packages start with a lower case letter in Java, hence xpath rather than XPath.) The xpath directory will contain the Step.java and Query.java classes.

The Step class implements a Step in an XPath query. Recall that each Step has an axis, a node test, and a predicate. In this assignment you will implement the axis, node test, and some predicates. A Step is evaluated starting from a single node. The Step's result is initially an empty list. Each node in the axis, e.g., child, is tested using the node test, e.g., node, and those that qualify are added to the result. The result is kept in memory, hence we will ignore the problem of the result being larger than memory. The Step module contains (at the least) the following methods. You may add public and private methods as needed.

  • Step() - Create a step. By default, create a step with a self axis and any node test.
  • evaluate(Document doc, Node node) - Evaluate the step on the given document starting at the given node. The evaluate method will build a list of nodes that comprises the result as an instance variable.
  • getResult() - Return an object handle for the result.
  • setSelfAxis() - Set the axis of the step to be self.
  • setChildAxis() - The child axis is all the children of a node.
  • setParentAxis() - The parent axis is the parent of a node. The parent of the root is empty.
  • setDescendentAxis() - The descendent axis is everything below the node.
  • setDescendentOrSelfAxis() - Grab descendents but keep the current context too.
  • setAncestorAxis() - The ancestor axis is every node on a path to the root.
  • setAncestorOrSelfAxis() - Ancestors plus self axis.
  • setFollowingAxis() - The following axis is the union of the descendents of the children to the right of each ancestor node. In common parlance, following is everything to the 'right'.
  • setPrecedingAxis() - Preceding is everything to the 'left'. The preceding axis is the union of the descendents of the children to the left of each ancestor node.
  • setFollowingSiblingAxis() - All siblings to the 'right'.
  • setPrecedingSiblingAxis() - All siblings to the 'left'.
  • setAttributeAxis() - All attributes.
  • setNodeNodeTest() - The node test is true for any node.
  • setAnyNodeTest() - The any node test is true for element nodes.
  • setAnyNodeTest(String elementName) - The any node test is true for any element named by elementName.
  • setAttributeNodeTest() - True for an attribute node.
  • setAttributeNodeTest(String attrName) - True for an attribute node named by attrName.
  • addPredicate(Predicate p) - Add the predicate to a list of predicates. All the predicates must evaluate to true for a node to qualify for the result, i.e., the predicates are conjuncts.

The Query class implements an XPath query. A query is a sequence of Steps.

  • Query() - This constructor creates an empty query.
  • addStep(Step step) - Add a step to the end of the query. Note that it does not evaluate a query, rather it stores the information necessary for later evaluation.
  • evaluate(Document doc) - Evaluate the query step-by-step. Each step will generate a result. The result will be used to seed the starting position of a subsequent step. This method will store the query result (the result of the final step).
  • setContext(Node node) - set the context node to the passed node, by default the context node is the document root (set by the constructor).
  • getResult() - return the result as a list of nodes.
  • resultAsXML() - return the result as a string, formatted as XML (do not pretty print it).
The Predicate class represents a predicate in an XPath step. A predicate consists of two parts. The first is a Query. The second part is a constraint. The idea is that the query is evaluated from a context node. This results in a list of nodes. For each node in the list the constraint is subsequently applied. If the node satisfies the constraint then the entire predicate evaluates to true. If none of the nodes satisfy the constraint, then the predicate evaluates to false.

The Predicate class has the following methods.

  • Predicate() - This constructor builds a default query, consisting of one Step, self::node() (i.e., a Step that just evaluates to the context node).
  • Predicate(Query query) - This constructor takes as input a Query.
  • boolean evaluate(Document doc, Node node) - Evaluate the predicate on the given document starting at the indicated node. The method will return the truth value of the evaluated predicate.
  • setNotEmptyTest() - Evaluates to true if the Query results in at least one node.
  • setEmptyTest() - Evaluates to true if the Query results in zero nodes.
  • setEqualTest(String value) - Test the value the node to determine if it equals the given string.
  • setNotEqualTest(String value) - Test the value the node to determine if it is not equal to the given string.


                                                                                                                                                                                                                                                                                                                                             

  E-mail questions or comments to Curtis.Dyreson at usu dot edu