001: /*
002: Mdarad-Toolobox is a collection of tools for Architected RAD
003: (Rapid Application Development) based on an MDA approach.
004: The toolbox contains frameworks and generators for many environments
005: (JAVA, J2EE, Hibernate, .NET, C++, etc.) which allow to generate
006: applications from a design Model
007: Copyright (C) 2004-2005 Elapse Technologies Inc.
008:
009: This library is free software; you can redistribute it and/or
010: modify it under the terms of the GNU General Public
011: License as published by the Free Software Foundation; either
012: version 2.1 of the License, or (at your option) any later version.
013:
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: General Public License for more details.
018:
019: You should have received a copy of the GNU General Public
020: License along with this library; if not, write to the Free Software
021: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022: */
023: package org.mdarad.framework.util.struts.criteria;
024:
025: import java.sql.Date;
026: import java.util.Locale;
027:
028: import org.apache.commons.beanutils.ConvertUtils;
029: import org.dataisland.primitives.format.DataIslandFormat;
030: import org.dataisland.primitives.format.DateDataIslandFormat;
031:
032: /**
033: * This classe representes a criterion that is used with "date" properties.
034: * It defines the operators used with a numeric criterion.
035: * @author Philippe Brouillette
036: * @version 1.0
037: */
038: public class DateCriterion extends NumericCriterion {
039:
040: /**
041: * Constructor that takes all the needed properties to
042: * initialize a date criterion.
043: * @param name name of the criterion, this name is used as a key
044: * in the criterion map
045: * @param associatedEntity class type associated to this criterion
046: * @param property property used for the query criterion
047: * @param bundleName bundle name
048: * @param locale locale information
049: * @see FormCriterion#FormCriterion(String, CriterionProperty, String, Locale) FormCriterion
050: */
051: public DateCriterion(String name, Class associatedEntity,
052: CriterionProperty property, String bundleName, Locale locale) {
053: super (name, associatedEntity, property, bundleName, locale);
054: }
055:
056: /**
057: * Constructor that clones a query criterion. This constructor is used
058: * to instanciate a criterion in a search form when the form
059: * contains dynamic criteria.
060: * @param criterion query criterion that must be of
061: * type <code>DateCriterion</code>
062: * @see FormCriterion#FormCriterion(FormCriterion) FormCriterion
063: */
064: public DateCriterion(DateCriterion criterion) {
065: super (criterion);
066: }
067:
068: /**
069: * Method that assigns the value of the criterion as a String. This method
070: * is needed for the user interface which uses only string values.
071: * @param value value to be assigned
072: * @see FormCriterion#setPropertyValue(java.lang.String)
073: */
074: public void setPropertyValue(String value) {
075: if (value != null && value.trim().length() > 0) {
076: Date dateValue = (Date) ConvertUtils.convert(value,
077: Date.class);
078: setValue(dateValue);
079: }
080: }
081:
082: /**
083: * Method that returns the value as a string. In this case, it converts
084: * from Integer to String.
085: * @see FormCriterion#getPropertyValue()
086: */
087: public String getPropertyValue() {
088: if (getValue() != null) {
089: return DateDataIslandFormat.format(getValue(), Locale
090: .getDefault());
091: }
092:
093: return "";
094: }
095:
096: /**
097: * Method that returns the object type of the criterion value. In this
098: * case it returns a Date object.
099: *
100: * @see FormCriterion#getObjectType()
101: */
102: public Class getObjectType() {
103: return Date.class;
104: }
105: }
|