KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > databinding > datagrid > api > filter > Filter


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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  * $Header:$
17  */

18 package org.apache.beehive.netui.databinding.datagrid.api.filter;
19
20 import org.apache.beehive.netui.util.logging.Logger;
21
22 /**
23 * <p>
24 * The Filter class is a JavaBean that abstractly represents the data needed to calculate a filter
25 * for a data set. A filter consists of some {@link String} expression, a {@link FilterOperation}
26 * and a filter value. The mechanism for applying a filter to a data set is not provided here.
27 * </p>
28 * <p>
29  * The filter expression is used to abstractly name some part of a data set to filter. The filter operation
30  * is used to describe the operation to use when performing filtering. The set of operations for
31  * available for use should be related to a subclass of the Filter type; there are no implicitly
32  * defined operations. The filter value is used to describe how to filter a given filter expression.
33  * For example, in an application performing filtering using SQL, a filter expression <code>pet</code>
34  * with a filter operation mapping to "equals" and a filter value of "dog" could be transformed
35  * into a SQL WHERE fragment as:
36  * <pre>
37  * WHERE pet = 'dog'
38  * </pre>
39  * The Filter class simply provides an abstraction for a filter's metadata; the mechanism for performing
40  * this transformation from Filter instance to SQL fragment is not provided here.
41  * </p>
42  * <p>
43  * In addition to the fundamental data fora Filter, two additional properties can be defined. The
44  * {@link org.apache.beehive.netui.databinding.datagrid.api.filter.FilterOperationHint} property can
45  * be used to reference a class of operation related to the hint. The
46  * {@link org.apache.beehive.netui.databinding.datagrid.api.filter.FilterTypeHint} property
47  * defines a hint for the type of data associated with the Filter's filter expression. This data can be
48  * used to handle quoting and type conversion for a given filter value. In the example above, a type hint of
49  * a {@link org.apache.beehive.netui.databinding.datagrid.api.filter.FilterTypeHint#STRING} can be used
50  * when constructing the SQL fragment in order to perform the correct quoting of the filter value.
51  */

52 public class Filter
53     implements java.io.Serializable JavaDoc {
54
55     private static final Logger LOGGER = Logger.getInstance(Filter.class);
56
57     private String JavaDoc _filterExpression;
58     private FilterOperation _filterOperation;
59     private FilterOperationHint _filterOperationHint;
60     private Object JavaDoc _value;
61
62     private FilterTypeHint _typeHint = FilterTypeHint.getDefault();
63
64     /**
65      * Get the type hint for this filter.
66      * @return the filter type hint
67      */

68     public FilterTypeHint getTypeHint() {
69         return _typeHint;
70     }
71
72     /**
73      * Set the type hint for this filter
74      * @param typeHint the filter type hint
75      */

76     public void setTypeHint(FilterTypeHint typeHint) {
77         _typeHint = typeHint;
78     }
79
80     /**
81      * Set the filter expression for this filter
82      * @param filterExpression the filter expression
83      */

84     public void setFilterExpression(String JavaDoc filterExpression) {
85         _filterExpression = filterExpression;
86     }
87
88     /**
89      * Get the filter expression for this filter
90      * @return the filter expression
91      */

92     public String JavaDoc getFilterExpression() {
93         return _filterExpression;
94     }
95
96     /**
97      * Set the filter operation for this filter
98      * @param filterOperation the filter operation
99      */

100     public void setOperation(FilterOperation filterOperation) {
101         _filterOperation = filterOperation;
102     }
103
104     /**
105      * Get the filter operation for this filter
106      * @return the filter operation
107      */

108     public FilterOperation getOperation() {
109         return _filterOperation;
110     }
111
112     /**
113      * Get the operation hint for this filter
114      * @return the filter operation hint
115      */

116     public FilterOperationHint getOperationHint() {
117         return _filterOperationHint;
118     }
119
120     /**
121      * Set the operation hint for this filter
122      * @param filterOperationHint the filter operation hint
123      */

124     public void setOperationHint(FilterOperationHint filterOperationHint) {
125         _filterOperationHint = filterOperationHint;
126     }
127
128     /**
129      * Set the value for this filter. Note, in the default implementation, the <code>value</code>
130      * must implement {@link java.io.Serializable}.
131      * @param value the value
132      */

133     public void setValue(Object JavaDoc value) {
134
135         if(LOGGER.isInfoEnabled() && !(value instanceof java.io.Serializable JavaDoc))
136             LOGGER.info("Warning: setting a filter value tiat is not serializable. The Filter object is serializable and should contain only serializable state");
137
138         _value = value;
139     }
140
141     /**
142      * Get the value for this filter.
143      * @return the value
144      */

145     public Object JavaDoc getValue() {
146         return _value;
147     }
148 }
149
Popular Tags