KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > grid > util > DateFilter


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
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 package com.blandware.atleap.webapp.taglib.core.grid.util;
17
18 import java.sql.Timestamp JavaDoc;
19 import java.util.Date JavaDoc;
20
21 /**
22  * <p>Filter for date fields</p>
23  * <p><a HREF="DateFilter.java.htm"><i>View Source</i></a></p>
24  *
25  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
26  * @version $Revision: 1.3 $ $Date: 2005/08/05 17:48:33 $
27  */

28 public class DateFilter extends BaseFilter {
29
30
31     // ~ Instance variables
32

33     private String JavaDoc firstCondition = FilterConditions.DATE_EQUAL;
34     private Date JavaDoc firstValue = null;
35     private String JavaDoc secondCondition = FilterConditions.CONDITION_NOT_SET;
36     private Date JavaDoc secondValue = null;
37     private String JavaDoc logicCopula = FilterConditions.LOGIC_COPULA_AND;
38
39     /**
40      * Creates new instance of DateFilter
41      *
42      * @param fieldName Name of field to associate filter with
43      */

44     public DateFilter(String JavaDoc fieldName) {
45         super(fieldName);
46     }
47
48     /**
49      * Creates clause from specified condition and date to compare our field to
50      *
51      * @param condition Condition to insert into clause
52      * @param compareTo Date to compare to
53      * @return Constructed clause
54      */

55     private String JavaDoc createClause(String JavaDoc condition, Date JavaDoc compareTo) {
56         if ( condition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NULL) || condition.equalsIgnoreCase(FilterConditions.OBJECT_IS_NOT_NULL) ) {
57             return createNullComparison(condition);
58         }
59         Timestamp JavaDoc timestamp = new Timestamp JavaDoc(compareTo.getTime());
60         return fieldName + " " + condition + " '" + timestamp.toString() + "'";
61     }
62
63     /**
64      * Creates first clause
65      *
66      * @param condition Congruence condition
67      * @param compareTo Date to compare to
68      */

69     public void createFirstClause(String JavaDoc condition, Date JavaDoc compareTo) {
70         this.firstCondition = condition;
71         this.firstValue = compareTo;
72         setFirstClause(createClause(condition, compareTo));
73     }
74
75     /**
76      * Creates second clause
77      *
78      * @param condition Congruence condition
79      * @param compareTo Date to compare to
80      * @param logicCopula Logic copula to place between first and second conditions
81      */

82     public void createSecondClause(String JavaDoc condition, Date JavaDoc compareTo, String JavaDoc logicCopula) {
83         this.secondCondition = condition;
84         this.secondValue = compareTo;
85         this.logicCopula = logicCopula;
86         setSecondClause(createClause(condition, compareTo), logicCopula);
87     }
88
89     /**
90      * Creates second clause with AND logic copula
91      *
92      * @param condition Congruence condition
93      * @param compareTo Date to compare to
94      */

95     public void createSecondClause(String JavaDoc condition, Date JavaDoc compareTo) {
96         createSecondClause(condition, compareTo, FilterConditions.LOGIC_COPULA_AND);
97     }
98
99     /**
100      * Returns first condition
101      *
102      * @return first condition
103      */

104     public String JavaDoc getFirstCondition() {
105         return firstCondition;
106     }
107
108     /**
109      * Returns first value
110      *
111      * @return first value
112      */

113     public Date JavaDoc getFirstValue() {
114         return firstValue;
115     }
116
117     /**
118      * Returns second condition
119      *
120      * @return second condition
121      */

122     public String JavaDoc getSecondCondition() {
123         return secondCondition;
124     }
125
126     /**
127      * Returns first value
128      *
129      * @return first value
130      */

131     public Date JavaDoc getSecondValue() {
132         return secondValue;
133     }
134
135     /**
136      * Returns logic copula
137      *
138      * @return logic copula
139      */

140     public String JavaDoc getLogicCopula() {
141         return logicCopula;
142     }
143 }
144
Popular Tags