From: Roland Haeder Date: Mon, 15 Feb 2016 19:29:58 +0000 (+0100) Subject: Added logger X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=40bd7d3b92fc7bf5a6c6a953b657883bbd2d1274;p=jaddressbook-share-lib.git Added logger --- diff --git a/src/org/mxchange/addressbook/validator/user/UserIdValidator.java b/src/org/mxchange/addressbook/validator/user/UserIdValidator.java index 28dd35e..2f50468 100644 --- a/src/org/mxchange/addressbook/validator/user/UserIdValidator.java +++ b/src/org/mxchange/addressbook/validator/user/UserIdValidator.java @@ -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 *

@@ -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 + } } }