Java Reference
In-Depth Information
FIRST_NAME LIKE 'M%'
OR
CUSTOMER_NUMBER = '102'
)
The XMLWhereEvaluator evaluates the test vector against each row element in the XML table
document to create a result String. The result String is created from the test vector by appending parens
and boolean operators such as AND and OR directly to the result String and by evaluating the subtests
containing operators. Evaluation of the subtests occurs by calling the appropriate test method for the
operator in the subtest. Only two test methods are implemented here, though implementing additional
tests is quite simple:
 
isLike() , which parses out the '%' wildcard and performs the appropriate String comparison
 
isEqual() , which simply compares the Strings
These test methods return a boolean result. Negation is handled by set a boolean flag used to toggle
the true/false value the test returns. For example, if the WHERE clause is evaluated against a row
containing this element:
<FIRST_NAME>Michael</FIRST_NAME>
The returned result String will be this:
( true OR false )
This result String, which is in infix notation, is passed to the method evaluate(String infix) .
This method uses a simple two-stack approach to evaluate the result String and to return a boolean
result for the overall test, as shown in Listing 19-11 .
Listing 19-11: XMLWhereEvaluator class
package JavaDatabaseBible.ch19.JDBCforXML;
import java.io.*;
import java.util.*;
import java.sql.SQLException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.apache.xerces.parsers.DOMParser;
public class XMLWhereEvaluator{
Element record = null;
Vector testVector = null;
public XMLWhereEvaluator(Vector testVector){
this.testVector = testVector;
}
Search WWH ::




Custom Search