]> git.mxchange.org Git - jbonuscard-lib.git/commitdiff
Added logger
authorRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 19:29:58 +0000 (20:29 +0100)
committerRoland Haeder <roland@mxchange.org>
Mon, 15 Feb 2016 19:29:58 +0000 (20:29 +0100)
src/org/mxchange/addressbook/validator/user/UserIdValidator.java

index 28dd35ef4d33d011e264feb88012027e8d72dffa..2f504686334499acbd450d79506af594bdab00fd 100644 (file)
@@ -19,7 +19,6 @@ package org.mxchange.addressbook.validator.user;
 import java.text.MessageFormat;
 import java.util.Set;
 import java.util.TreeSet;
-import javax.ejb.EJB;
 import javax.enterprise.event.Observes;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
@@ -27,7 +26,12 @@ import javax.faces.context.FacesContext;
 import javax.faces.validator.FacesValidator;
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import org.mxchange.jcoreee.validator.number.BaseLongValidator;
+import org.mxchange.jcoreeelogger.beans.local.logger.Log;
+import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal;
 import org.mxchange.jusercore.events.registration.UserRegisteredEvent;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
@@ -53,9 +57,14 @@ public class UserIdValidator extends BaseLongValidator implements Validator {
        /**
         * Remote bean
         */
-       @EJB (mappedName = "ejb/stateless-user")
        private UserSessionBeanRemote userBean;
 
+       /**
+        * Logger instance
+        */
+       @Log
+       private LoggerBeanLocal loggerBeanLocal;
+
        /**
         * Event fired when the user registration is complete
         * <p>
@@ -63,7 +72,7 @@ public class UserIdValidator extends BaseLongValidator implements Validator {
         */
        public void afterRegistrationEvent (final @Observes UserRegisteredEvent event) {
                // Trace message
-               System.out.println(MessageFormat.format("UserIdValidator:afterRegistrationEvent: event={0} - CALLED!", event)); //NOI18N
+               this.loggerBeanLocal.logTrace(MessageFormat.format("UserIdValidator:afterRegistrationEvent: event={0} - CALLED!", event)); //NOI18N
 
                // event should not be null
                if (null == event) {
@@ -96,7 +105,7 @@ public class UserIdValidator extends BaseLongValidator implements Validator {
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
                // Trace message
-               //this.getLogger().logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
+               this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N
 
                // All accepted, required fields
                String[] requiredFileds = {"userId"}; //NOI18N
@@ -129,6 +138,26 @@ public class UserIdValidator extends BaseLongValidator implements Validator {
                UserIdValidator.cachedStatus.add(userId);
 
                // Trace message
-               //this.getLogger().logTrace("validate: EXIT!"); //NOI18N
+               this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N
+       }
+
+       /**
+        * Initialization of this converter
+        */
+       public UserIdValidator () {
+               // Try to get it
+               try {
+                       // Get initial context
+                       Context context = new InitialContext();
+
+                       // Lookup logger
+                       this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N
+
+                       // ... and user controller
+                       this.userBean = (UserSessionBeanRemote) context.lookup("java:global/juser-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
+               } catch (final NamingException ex) {
+                       // Continue to throw it
+                       throw new RuntimeException("context.lookup() failed.", ex); //NOI18N
+               }
        }
 }