View Javadoc

1   /********************************************************************************
2    * InternetCafe is a software solution that helps the management of Cybercafes 
3    * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4    * Copyright (C) 2006  Guido Angelo Ingenito
5   
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10  
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19   *******************************************************************************/
20  
21  package base.user.jcard;
22  
23  import javax.print.attribute.standard.MediaSize.ISO;
24  
25  public class Birthdate extends Property {
26  
27  	private int yyyy;
28  	private int mm;
29  	private int dd;
30  	
31  	private static final String BIRTHDATE_FIELD_DELIMITER = "-";
32  	
33  	/***
34  	 * Sets the birthdate of the contact.
35  	 * @param yyyy 4 digit year 
36  	 * @param mm 2 digit month
37  	 * @param dd 2 digit day
38  	 * @see ISO 8601 date encoding standard
39  	 */
40  	public void setBirthdate(int yyyy, int mm, int dd) {
41  		this.yyyy = yyyy;
42  		this.mm = mm;
43  		this.dd = dd;
44  	}
45  	
46  	@Override
47  	protected void setPropertyName() {
48  		super.PROPERTY_NAME = "BDAY:";
49  	}
50  	
51  	@Override
52  	public void doValidate() throws JCardException {
53  		if(dd < 1 || dd > 31	||
54  			mm < 1 || mm > 12	||
55  			yyyy < 1900)	// may need to change year validation
56  			throw new JCardException("Validation error: Valid date not entered");
57  	}
58  
59  	@Override
60  	public String toString() {
61  		StringBuffer birthdate = new StringBuffer(21);	
62  		birthdate.append(Integer.toString(yyyy));
63  		birthdate.append(BIRTHDATE_FIELD_DELIMITER);
64  		birthdate.append(Integer.toString(mm));
65  		birthdate.append(BIRTHDATE_FIELD_DELIMITER);
66  		birthdate.append(Integer.toString(dd));
67  		return birthdate.toString();
68  	}
69  
70  }