KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/expression/ComparePropertyExpression.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 org.apache.slide.content.NodeProperty.NamespaceCache;
27 import org.apache.slide.search.InvalidQueryException;
28 import org.apache.slide.search.basic.ComparableResource;
29 import org.apache.slide.search.basic.ComparableResourcesPool;
30 import org.apache.slide.search.basic.Literals;
31 import org.jdom.Element;
32
33 /**
34  * Abstract base class for compare expressions (GT, EQ, is-collection ...).
35  *
36  * @version $Revision: 1.4 $
37  */

38 public abstract class ComparePropertyExpression extends CompareExpression {
39     
40     protected ComparedProperty comparedProperty;
41     
42     
43     /** the property's value <literal> */
44 // protected String literal;
45
//
46
// /** the property name <prop> */
47
// protected String property;
48
//
49
// /** the property's namespace */
50
// protected String propNamespace;
51
//
52
// /** indicate, if compare should be casesensitive */
53
// protected boolean casesensitive = true;
54
//
55

56     /**
57      * Creates a compare expression according to Element e
58      *
59      * @param e jdom element, that describes the expression
60      * @param requestedResourcesPool the pool of resources to apply the expression to.
61      * @param expectLiteral indicates if a &lt;literal&gt; is expected.
62      */

63     public ComparePropertyExpression (Element e, ComparableResourcesPool requestedResourcesPool, boolean expectLiteral) throws InvalidQueryException {
64         this(e, requestedResourcesPool, new ComparedProperty (e, expectLiteral));
65     }
66     /**
67      * Creates a compare expression according to Element e
68      *
69      * @param e jdom element, that describes the expression
70      * @param requestedResourcesPool the pool of resources to apply the expression to.
71      * @param comparedProperty the property to compare.
72      */

73     protected ComparePropertyExpression (Element e, ComparableResourcesPool requestedResourcesPool, ComparedProperty comparedProperty) throws InvalidQueryException {
74         super (e, requestedResourcesPool);
75         this.comparedProperty = comparedProperty;
76     }
77     
78     
79     
80     /**
81      * The concrete CompareExpression must overwrite this.
82      *
83      * @param item one BasicDataItem out of pool
84      *
85      * @return a boolean
86      *
87      */

88     protected abstract boolean compare (ComparableResource item);
89     
90     /**
91      * String representation for debugging purposes.
92      *
93      * @return this expression as String
94      */

95     protected String JavaDoc toString (String JavaDoc op) {
96         return "(" +comparedProperty.getProperty() + " "
97             + op + " " + comparedProperty.getLiteral() + ")";
98     }
99     
100     /**
101      * extracs the value of <literal> of an expression
102      *
103      * @param e an Expression
104      *
105      * @return the literal as string
106      *
107      * @throws InvalidQueryException if no <literal> found in e
108      *
109      */

110     protected String JavaDoc getLiteral(Element e) throws InvalidQueryException {
111         Element lit = e.getChild (Literals.LITERAL, NamespaceCache.DEFAULT_NAMESPACE);
112         if (lit == null)
113             throw new InvalidQueryException
114                 ("No literal element supplied");
115         
116         return lit.getText ();
117     }
118 }
119
120
Popular Tags