001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.databinding.datagrid.api.filter;
020:
021: import org.apache.beehive.netui.util.logging.Logger;
022:
023: /**
024: * <p>
025: * The Filter class is a JavaBean that abstractly represents the data needed to calculate a filter
026: * for a data set. A filter consists of some {@link String} expression, a {@link FilterOperation}
027: * and a filter value. The mechanism for applying a filter to a data set is not provided here.
028: * </p>
029: * <p>
030: * The filter expression is used to abstractly name some part of a data set to filter. The filter operation
031: * is used to describe the operation to use when performing filtering. The set of operations for
032: * available for use should be related to a subclass of the Filter type; there are no implicitly
033: * defined operations. The filter value is used to describe how to filter a given filter expression.
034: * For example, in an application performing filtering using SQL, a filter expression <code>pet</code>
035: * with a filter operation mapping to "equals" and a filter value of "dog" could be transformed
036: * into a SQL WHERE fragment as:
037: * <pre>
038: * WHERE pet = 'dog'
039: * </pre>
040: * The Filter class simply provides an abstraction for a filter's metadata; the mechanism for performing
041: * this transformation from Filter instance to SQL fragment is not provided here.
042: * </p>
043: * <p>
044: * In addition to the fundamental data fora Filter, two additional properties can be defined. The
045: * {@link org.apache.beehive.netui.databinding.datagrid.api.filter.FilterOperationHint} property can
046: * be used to reference a class of operation related to the hint. The
047: * {@link org.apache.beehive.netui.databinding.datagrid.api.filter.FilterTypeHint} property
048: * defines a hint for the type of data associated with the Filter's filter expression. This data can be
049: * used to handle quoting and type conversion for a given filter value. In the example above, a type hint of
050: * a {@link org.apache.beehive.netui.databinding.datagrid.api.filter.FilterTypeHint#STRING} can be used
051: * when constructing the SQL fragment in order to perform the correct quoting of the filter value.
052: */
053: public class Filter implements java.io.Serializable {
054:
055: private static final Logger LOGGER = Logger
056: .getInstance(Filter.class);
057:
058: private String _filterExpression;
059: private FilterOperation _filterOperation;
060: private FilterOperationHint _filterOperationHint;
061: private Object _value;
062:
063: private FilterTypeHint _typeHint = FilterTypeHint.getDefault();
064:
065: /**
066: * Get the type hint for this filter.
067: * @return the filter type hint
068: */
069: public FilterTypeHint getTypeHint() {
070: return _typeHint;
071: }
072:
073: /**
074: * Set the type hint for this filter
075: * @param typeHint the filter type hint
076: */
077: public void setTypeHint(FilterTypeHint typeHint) {
078: _typeHint = typeHint;
079: }
080:
081: /**
082: * Set the filter expression for this filter
083: * @param filterExpression the filter expression
084: */
085: public void setFilterExpression(String filterExpression) {
086: _filterExpression = filterExpression;
087: }
088:
089: /**
090: * Get the filter expression for this filter
091: * @return the filter expression
092: */
093: public String getFilterExpression() {
094: return _filterExpression;
095: }
096:
097: /**
098: * Set the filter operation for this filter
099: * @param filterOperation the filter operation
100: */
101: public void setOperation(FilterOperation filterOperation) {
102: _filterOperation = filterOperation;
103: }
104:
105: /**
106: * Get the filter operation for this filter
107: * @return the filter operation
108: */
109: public FilterOperation getOperation() {
110: return _filterOperation;
111: }
112:
113: /**
114: * Get the operation hint for this filter
115: * @return the filter operation hint
116: */
117: public FilterOperationHint getOperationHint() {
118: return _filterOperationHint;
119: }
120:
121: /**
122: * Set the operation hint for this filter
123: * @param filterOperationHint the filter operation hint
124: */
125: public void setOperationHint(FilterOperationHint filterOperationHint) {
126: _filterOperationHint = filterOperationHint;
127: }
128:
129: /**
130: * Set the value for this filter. Note, in the default implementation, the <code>value</code>
131: * must implement {@link java.io.Serializable}.
132: * @param value the value
133: */
134: public void setValue(Object value) {
135:
136: if (LOGGER.isInfoEnabled()
137: && !(value instanceof java.io.Serializable))
138: LOGGER
139: .info("Warning: setting a filter value tiat is not serializable. The Filter object is serializable and should contain only serializable state");
140:
141: _value = value;
142: }
143:
144: /**
145: * Get the value for this filter.
146: * @return the value
147: */
148: public Object getValue() {
149: return _value;
150: }
151: }
|