KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > query > QueryFactoryImpl


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.query;
17
18 import org.outerj.daisy.query.model.PredicateExpr;
19 import org.outerj.daisy.query.model.Query;
20 import org.outerj.daisy.repository.query.QueryException;
21
22 import java.io.StringReader JavaDoc;
23
24 /**
25  * @avalon.component version="1.0" name="queryfactory" lifestyle="singleton"
26  * @avalon.service type="org.outerj.daisy.query.QueryFactory"
27  */

28 public class QueryFactoryImpl implements QueryFactory {
29     public PredicateExpr parsePredicateExpression(String JavaDoc expression) throws QueryException {
30         QueryParser qp = new QueryParser(new StringReader JavaDoc(expression));
31         PredicateExpr predicateExpr;
32         try {
33             predicateExpr = qp.standAloneWhereClause();
34         } catch (TokenMgrError e) {
35             throw new QueryException("Error parsing expression.", e);
36         } catch (ParseException e) {
37             throw new QueryException("Error parsing expression.", e);
38         }
39         return predicateExpr;
40     }
41
42     public Query parseQuery(String JavaDoc queryString) throws QueryException {
43         QueryParser qp = new QueryParser(new StringReader JavaDoc(queryString));
44         Query query;
45         try {
46             query = qp.query();
47         } catch (TokenMgrError e) {
48             throw new QueryException("Error parsing expression.", e);
49         } catch (ParseException e) {
50             throw new QueryException("Error parsing expression.", e);
51         }
52         return query;
53     }
54 }
55
Popular Tags