KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > search > basic > expression > CompareExpression


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/expression/CompareExpression.java,v 1.4 2004/07/28 09:34:50 ib Exp $
3  * $Revision: 1.4 $
4  * $Date: 2004/07/28 09:34:50 $
5  *
6  * ====================================================================
7  *
8  * Copyright 1999-2002 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */

23
24 package org.apache.slide.search.basic.expression;
25
26 import java.util.Iterator JavaDoc;
27
28 import org.apache.slide.search.InvalidQueryException;
29 import org.apache.slide.search.PropertyProvider;
30 import org.apache.slide.search.SearchException;
31 import org.apache.slide.search.basic.BasicResultSetImpl;
32 import org.apache.slide.search.basic.ComparableResource;
33 import org.apache.slide.search.basic.ComparableResourcesPool;
34 import org.apache.slide.search.basic.IBasicResultSet;
35 import org.jdom.Element;
36
37 /**
38  * Abstract base class for compare expressions (property compares, contains).
39  *
40  * @version $Revision: 1.4 $
41  */

42 public abstract class CompareExpression extends GenericBasicExpression {
43     
44     /**
45      * The pool of resources to apply the expression to.
46      */

47     protected ComparableResourcesPool requestedResourcesPool = null;
48     
49     /**
50      * The PropertyProvider to use (may be <code>null</code>).
51      */

52     protected PropertyProvider propertyProvider = null;
53     
54     
55     /**
56      * Creates a compare expression according to Element e
57      *
58      * @param e jdom element, that describes the expression
59      * @param requestedResourcesPool the pool of resources to apply the expression to.
60      */

61     CompareExpression (Element e, ComparableResourcesPool requestedResourcesPool) throws InvalidQueryException {
62         super (e);
63         this.requestedResourcesPool = requestedResourcesPool;
64         ((BasicResultSetImpl)resultSet).setPartialResultSet(requestedResourcesPool.partialResult());
65     }
66     
67     /**
68      * Executes the expression.
69      *
70      * @return a Set of RequestedResource objects
71      *
72      * @throws SearchException
73      */

74     public IBasicResultSet execute () throws SearchException {
75         
76         Iterator JavaDoc iterator = getRequestedResourcePool().getPool().iterator();
77         while (iterator.hasNext()) {
78             ComparableResource item =
79                 (ComparableResource)iterator.next();
80             
81             if (compare (item))
82                 resultSet.add (item);
83         }
84         return resultSet;
85     }
86     
87     /**
88      * Returns the RequestedResourcesPool to use.
89      *
90      * @return the RequestedResourcesPool to use.
91      */

92     public ComparableResourcesPool getRequestedResourcePool() {
93         return requestedResourcesPool;
94     }
95
96     /**
97      * The concrete CompareExpression must overwrite this.
98      *
99      * @param item one BasicDataItem out of pool
100      *
101      * @return a boolean
102      *
103      */

104     protected abstract boolean compare (ComparableResource item);
105 }
106
107
Popular Tags