KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jofti > tree > NameSpacedTreeIndex


1 /*
2  *
3  * Created on 01 June 2003, 08:32
4  */

5
6 package com.jofti.tree;
7
8 import java.util.Collection JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Properties JavaDoc;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 import com.jofti.api.IndexQuery;
17 import com.jofti.api.NameSpaceKey;
18 import com.jofti.btree.BTOperations;
19 import com.jofti.btree.BTree;
20 import com.jofti.btree.ValueObject;
21 import com.jofti.cache.adapter.NameSpaceWrapper;
22 import com.jofti.core.IParsedQuery;
23 import com.jofti.core.InternalIndex;
24 import com.jofti.core.QueryId;
25 import com.jofti.exception.JoftiException;
26 import com.jofti.introspect.ClassIntrospector;
27 import com.jofti.parser.ConvenienceQueryWrapper;
28 import com.jofti.parser.ParserManager;
29 import com.jofti.query.MatchInQuery;
30 import com.jofti.query.MatchNotQuery;
31 import com.jofti.query.MatchQuery;
32 import com.jofti.query.MatchRangeQuery;
33 import com.jofti.query.namespace.MatchNSInQuery;
34 import com.jofti.query.namespace.MatchNSLargerQuery;
35 import com.jofti.query.namespace.MatchNSNotQuery;
36 import com.jofti.query.namespace.MatchNSQuery;
37 import com.jofti.query.namespace.MatchNSRangeQuery;
38 import com.jofti.query.namespace.MatchNSSmallerQuery;
39 /**
40  *
41  * @author xenephon (xenephon@jofti.com)
42  */

43 public class NameSpacedTreeIndex extends TreeIndex
44 {
45     
46     
47     private static Log log = LogFactory.getLog(NameSpacedTreeIndex.class);
48     
49     
50     
51     
52     public NameSpacedTreeIndex(){
53             super();
54     }
55     
56     
57     public NameSpacedTreeIndex(BTree tree, ClassIntrospector parser)
58     {
59         
60         super(tree,parser);
61         
62        
63         
64     }
65     
66     public NameSpacedTreeIndex(BTree tree, ClassIntrospector parser, Map JavaDoc indexedDimensions)
67     {
68         
69         super(tree,parser, indexedDimensions);
70         
71        
72         
73     }
74     
75     /* (non-Javadoc)
76      * @see com.jofti.tree.TreeIndex#init(java.util.Properties)
77      */

78     public void init(Properties JavaDoc props) throws JoftiException{
79         tree.init(props);
80         engine = new NameSpacedTreeMatcherEngine();
81         // start expiry clean up thread
82
parserManager = new ParserManager(introspector);
83         this.treeAdapter = new NameSpaceTreeOperationAdapter();
84         
85     }
86     
87
88     public Map JavaDoc query(IndexQuery query) throws JoftiException {
89         
90         // query lock is delegated to matching engine for this method
91
NameSpacedTreeMatcherEngine tempEngine = (NameSpacedTreeMatcherEngine)engine;
92         
93        
94         if (query == null){
95             throw new JoftiException("Query object cannot be null");
96         }
97         
98         QueryId queryId = (QueryId)query;
99         
100         switch(queryId.getQueryType().type){
101             case 200 :
102                  MatchNSQuery tempQuery = (MatchNSQuery)((ConvenienceQueryWrapper)query).getQuery();
103                  if (tempQuery.getPropertyName() ==null && tempQuery.getValue() == null){
104                      return tempEngine.matchNameSpace(tempQuery, this);
105                  } else{
106                      return tempEngine.matchProperty(tempQuery, this);
107                  }
108             case 201:
109                 return tempEngine.matchPropertyRange((MatchNSRangeQuery) ((ConvenienceQueryWrapper)query).getQuery(), this);
110             case 202:
111                 return tempEngine.matchNotProperty((MatchNSNotQuery) ((ConvenienceQueryWrapper)query).getQuery(), this);
112                 //common query type
113
case 0:
114                 return tempEngine.processQuery((IParsedQuery)query, this);
115             case 203:
116                 return tempEngine.matchProperty((MatchNSInQuery)((ConvenienceQueryWrapper)query).getQuery(), this);
117             default:
118                 throw new JoftiException("Query type "+ query.getClass() + " cannot be used for Name Spaced IndexCache");
119
120         }
121
122
123     }
124     
125     /**
126      * Gets a Collection of all the key entries.<p>
127      * @return a Collection
128      * @throws JoftiException
129      */

130     public Collection JavaDoc getAllKeyEntriesFromTree() throws JoftiException {
131
132         return ((NameSpaceTreeOperationAdapter)treeAdapter).getAllValuesForDimension(tree,introspector);
133     }
134     
135     
136
137     
138
139 }
140
Popular Tags