KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > parser > ParserManager


1 /*
2  * Created on 17-Jul-2005
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package com.jofti.parser;
8
9 import com.jofti.api.IndexQuery;
10 import com.jofti.core.IParsedQuery;
11 import com.jofti.exception.JoftiException;
12 import com.jofti.introspect.ClassIntrospector;
13 import com.jofti.query.EJBQuery;
14 import com.jofti.query.SQLQuery;
15
16 /**
17  * @author xenephon (xenephon@jofti.com)
18  *
19  */

20 public class ParserManager {
21
22      
23      
24      private IQueryParser nativeQueryParser = null;
25      private IQueryParser ejb3QueryParser = null;
26
27      public ParserManager(ClassIntrospector introspector){
28          nativeQueryParser = new NativeQueryParser(introspector);
29          ejb3QueryParser = new EJBQueryParser(introspector);
30          }
31      
32     /**
33      * Parses a String representation of a query. Uses the SimpleQuery Parser.
34      *
35      * @param originalQuery
36      * @return the parsed query
37      * @throws JoftiException
38      */

39      public IParsedQuery parseQuery(IndexQuery originalQuery) throws JoftiException{
40         if (originalQuery instanceof EJBQuery){
41             return ejb3QueryParser.parseQuery(originalQuery);
42         }else if (originalQuery instanceof SQLQuery) {
43             return nativeQueryParser.parseQuery(originalQuery);
44             
45         }else{
46             return new ConvenienceQueryWrapper(originalQuery);
47         }
48         
49         
50      }
51      
52      public IndexQuery addQuery(String JavaDoc name, IndexQuery originalQuery) throws JoftiException{
53         
54         if (originalQuery instanceof EJBQuery){
55             return ejb3QueryParser.parseQuery(name,originalQuery);
56         }else if (originalQuery instanceof SQLQuery){
57             return nativeQueryParser.parseQuery(name, originalQuery);
58         } else{
59             throw new JoftiException("Only " + EJBQuery.class + " or " + SQLQuery.class + " are allowed to be added");
60             
61         }
62         
63      }
64      
65      public IndexQuery addQuery(String JavaDoc name, String JavaDoc query) throws JoftiException{
66         
67         return addQuery(name, new EJBQuery(query));
68         
69      }
70      public IndexQuery getQuery(String JavaDoc name){
71         IndexQuery query = ejb3QueryParser.getQuery(name);
72         if (query ==null){
73             query = nativeQueryParser.getQuery(name);
74         }
75         return query;
76      }
77
78 }
79
Popular Tags