KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mdarad > framework > util > struts > criteria > DateCriterion


1 /*
2     Mdarad-Toolobox is a collection of tools for Architected RAD
3     (Rapid Application Development) based on an MDA approach.
4     The toolbox contains frameworks and generators for many environments
5     (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
6     applications from a design Model
7     Copyright (C) 2004-2005 Elapse Technologies Inc.
8
9     This library is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public
11     License as published by the Free Software Foundation; either
12     version 2.1 of the License, or (at your option) any later version.
13
14     This library is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17     General Public License for more details.
18
19     You should have received a copy of the GNU General Public
20     License along with this library; if not, write to the Free Software
21     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */

23 package org.mdarad.framework.util.struts.criteria;
24
25 import java.sql.Date JavaDoc;
26 import java.util.Locale JavaDoc;
27
28 import org.apache.commons.beanutils.ConvertUtils;
29 import org.dataisland.primitives.format.DataIslandFormat;
30 import org.dataisland.primitives.format.DateDataIslandFormat;
31
32 /**
33  * This classe representes a criterion that is used with "date" properties.
34  * It defines the operators used with a numeric criterion.
35  * @author Philippe Brouillette
36  * @version 1.0
37  */

38 public class DateCriterion extends NumericCriterion {
39
40     /**
41      * Constructor that takes all the needed properties to
42      * initialize a date criterion.
43      * @param name name of the criterion, this name is used as a key
44      * in the criterion map
45      * @param associatedEntity class type associated to this criterion
46      * @param property property used for the query criterion
47      * @param bundleName bundle name
48      * @param locale locale information
49      * @see FormCriterion#FormCriterion(String, CriterionProperty, String, Locale) FormCriterion
50      */

51     public DateCriterion(String JavaDoc name, Class JavaDoc associatedEntity, CriterionProperty property, String JavaDoc bundleName, Locale JavaDoc locale) {
52         super(name, associatedEntity, property, bundleName, locale);
53     }
54
55     /**
56      * Constructor that clones a query criterion. This constructor is used
57      * to instanciate a criterion in a search form when the form
58      * contains dynamic criteria.
59      * @param criterion query criterion that must be of
60      * type <code>DateCriterion</code>
61      * @see FormCriterion#FormCriterion(FormCriterion) FormCriterion
62      */

63     public DateCriterion(DateCriterion criterion) {
64         super(criterion);
65     }
66  
67     
68     /**
69      * Method that assigns the value of the criterion as a String. This method
70      * is needed for the user interface which uses only string values.
71      * @param value value to be assigned
72      * @see FormCriterion#setPropertyValue(java.lang.String)
73      */

74     public void setPropertyValue(String JavaDoc value) {
75         if (value != null && value.trim().length() > 0) {
76             Date JavaDoc dateValue = (Date JavaDoc) ConvertUtils.convert(value, Date JavaDoc.class);
77             setValue(dateValue);
78         }
79     }
80     
81     /**
82      * Method that returns the value as a string. In this case, it converts
83      * from Integer to String.
84      * @see FormCriterion#getPropertyValue()
85      */

86     public String JavaDoc getPropertyValue() {
87         if (getValue() != null) {
88             return DateDataIslandFormat.format(getValue(), Locale.getDefault());
89         }
90         
91         return "";
92     }
93
94     /**
95      * Method that returns the object type of the criterion value. In this
96      * case it returns a Date object.
97      *
98      * @see FormCriterion#getObjectType()
99      */

100     public Class JavaDoc getObjectType() {
101         return Date JavaDoc.class;
102     }
103 }
Popular Tags