]> git.mxchange.org Git - addressbook-war.git/blob - src/java/org/mxchange/addressbook/validator/birthday/AddressbookBirthdayValidator.java
moved from jphone-core and jcoreee as here (JSF) it makes more sense than there ...
[addressbook-war.git] / src / java / org / mxchange / addressbook / validator / birthday / AddressbookBirthdayValidator.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.addressbook.validator.birthday;
18
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import javax.faces.component.UIComponent;
22 import javax.faces.context.FacesContext;
23 import javax.faces.validator.FacesValidator;
24 import javax.faces.validator.Validator;
25 import javax.faces.validator.ValidatorException;
26 import javax.naming.Context;
27 import javax.naming.InitialContext;
28 import javax.naming.NamingException;
29 import org.mxchange.jcoreee.validator.date.BaseDateValidator;
30 import org.mxchange.jcoreeelogger.beans.local.logger.Log;
31 import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
32
33 /**
34  * A birthday validator
35  * <p>
36  * @author Roland Haeder<roland@mxchange.org>
37  */
38 @FacesValidator("BirthdayValidator")
39 public class AddressbookBirthdayValidator extends BaseDateValidator implements Validator {
40
41         /**
42          * Serial number
43          */
44         private static final long serialVersionUID = 28_735_756_819_460L;
45
46         /**
47          * Logger bean
48          */
49         @Log
50         private LoggerBeanLocal loggerBeanLocal;
51
52         /**
53          * Default constructor
54          */
55         public AddressbookBirthdayValidator () {
56                 // Try to get it
57                 try {
58                         // Get initial context
59                         Context context = new InitialContext();
60
61                         // Lookup logger
62                         this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
63                 } catch (final NamingException ex) {
64                         // Continue to throw it
65                         throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
66                 }
67         }
68
69         @Override
70         public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
71                 // Trace message
72                 this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
73
74                 // All accepted, required fields
75                 String[] requiredFields = {"birthday", "contactBirthday"}; //NOI18N
76
77                 // Pre-validation (example: not null, not a string, empty string ...)
78                 super.preValidate(context, component, value, requiredFields, false);
79
80                 // Cast value
81                 Date birthday = (Date) value;
82
83                 // @TODO Finish this, e.g. load maximum,minimum birthday from properties file
84
85                 // Trace message
86                 this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
87         }
88
89 }