15.6 A Query Builder

Building Parsers with Java
By Steven  John  Metsker

Table of Contents
Chapter  15.   Parsing a Query Language


As a parser parses a user 's query, the parser sees select terms, class names , and where clause comparisons. After all these pieces are parsed, you can build a Query object that is a translation of the user's input.

The builder pattern applies when "the algorithm for creating a complex object should be independent of the parts that make up the object and how they are assembled " [Gamma et al.]. You use a builder to collect the various aspects of a query and then ask the builder for a query after parsing all the input text. Figure 15.13 shows the QueryBuilder class.

Figure 15.13. The QueryBuilder class. A QueryBuilder object collects information about a desired query and then builds the query on demand.


The constructor for QueryBuilder takes a Speller object, described in the next section. The speller lets the QueryBuilder correct the spelling of class names; a QueryBuilder throws a runtime exception if a class name is unknown to the speller.


Building Parsers with Java
Building Parsers With Javaв„ў
ISBN: 0201719622
EAN: 2147483647
Year: 2000
Pages: 169

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net