]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/validator/BaseObjectValidator.java
Let's get rid of this class. It was maybe a good idea, but it required a lot work...
[jcore-utils.git] / src / org / mxchange / jcoreee / validator / BaseObjectValidator.java
index ca021aa62a6feff804be33f1987e0722f10fd665..fa3d625333a19deb0935349e8536f2ca71a99d3c 100644 (file)
 package org.mxchange.jcoreee.validator;
 
 import java.text.MessageFormat;
-import java.util.Arrays;
-import java.util.ResourceBundle;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
-import org.mxchange.jcore.BaseFrameworkSystem;
-import org.mxchange.jcore.FrameworkInterface;
 
 /**
- * A general object validation class. Please implement javax.faces.validator.Validator
- * (with import line!) and call preValidate(). You also may want to try out some
- * other BaseFooValidator classes before directly inheriting from this class.
- *
- * @author Roland Haeder
+ * A general object validation class. Please implement
+ * javax.faces.validator.Validator (with import line!) and call preValidate().
+ * You also may want to try out some other BaseFooValidator classes before
+ * directly inheriting from this class.
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
  */
-public abstract class BaseObjectValidator extends BaseFrameworkSystem implements FrameworkInterface, Validator {
+public abstract class BaseObjectValidator implements Validator {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 48_574_878_176_939_512L;
 
        /**
-        * Needs to be implemented as the Validator interface needs to be implemented.
-        *
+        * Needs to be implemented as the Validator interface needs to be
+        * implemented.
+        * <p>
         * @param context
         * @param component
         * @param value
-        * @throws ValidatorException 
+        * @throws ValidatorException
         */
        @Override
        abstract public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException;
 
        /**
-        * Initializes resource bundle
-        *
-        * @param FacesContext instance
-        */
-       private void initResourceBundle (final FacesContext context) {
-               // Is it set?
-               if (null == this.getBundle()) {
-                       // Set it now
-                       setBundle(ResourceBundle.getBundle("org.mxchange.localization.bundle", context.getViewRoot().getLocale()));
-               }
-       }
-
-       /**
-        * Pre-validation of value, e.g. not null
-        *
+        * The method pre-validates the given value. It makes sure that the
+        * component's id is found in requiredFields and is not null. Once the
+        * component's id has been found, it stops iteration on requiredFields
+        * (which saves execution time).
+        * <p>
         * @param context FacesContext instance
         * @param component UIComponent instance
         * @param value Value to check
@@ -71,14 +64,10 @@ public abstract class BaseObjectValidator extends BaseFrameworkSystem implements
         */
        protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields) throws ValidatorException {
                // Trace message
-               this.getLogger().trace(MessageFormat.format("context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
-
-               // Set resource bundle
-               this.initResourceBundle(context);
+               //this.getLogger().logTrace(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
 
                // Init message and key
                FacesMessage facesMessage = null;
-               String errKey = "error.unknown_id"; //NOI18N
 
                // Get client id
                final String clientId = component.getClientId();
@@ -86,9 +75,10 @@ public abstract class BaseObjectValidator extends BaseFrameworkSystem implements
                // Default is no field is valid
                boolean isValidField = false;
 
+               // Check component's id against required fields and find a match
                for (final String field : requiredFields) {
                        // Get logger
-                       this.getLogger().debug(MessageFormat.format("field={0},clientId={1}", field, clientId)); //NOI18N
+                       //this.getLogger().logDebug(MessageFormat.format("preValidate: field={0},clientId={1}", field, clientId)); //NOI18N
 
                        // Is it the same?
                        if (clientId.endsWith(field)) {
@@ -97,10 +87,8 @@ public abstract class BaseObjectValidator extends BaseFrameworkSystem implements
 
                                // Is it null?
                                if (null == value) {
-                                       errKey = String.format("error.%s.is_null", field); //NOI18N
-
                                        // Value it null
-                                       facesMessage = new FacesMessage(this.getMessageStringFromKey(errKey));
+                                       facesMessage = new FacesMessage(MessageFormat.format("Field {0} is null.", field)); //NOI18N
                                }
 
                                // Abort here
@@ -109,23 +97,21 @@ public abstract class BaseObjectValidator extends BaseFrameworkSystem implements
                }
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("isValidField={0}", isValidField)); //NOI18N
-
+               //this.getLogger().logDebug(MessageFormat.format("preValidate: isValidField={0}", isValidField)); //NOI18N
                // Valid field?
                if (!isValidField) {
                        // Invalid field
-                       facesMessage = new FacesMessage(MessageFormat.format(errKey, clientId));
+                       facesMessage = new FacesMessage(MessageFormat.format("Valure {0} for clientId={1} is not valid/unexpected.", value, clientId)); //NOI18N
                }
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("facesMessage={0}", facesMessage)); //NOI18N
-
+               //this.getLogger().logDebug(MessageFormat.format("preValidate: facesMessage={0}", facesMessage)); //NOI18N
                // Is it not null?
                if (null != facesMessage) {
                        throw new ValidatorException(facesMessage);
                }
 
                // Trace message
-               this.getLogger().trace("EXIT!"); //NOI18N
+               //this.getLogger().logTrace("preValidate: EXIT!"); //NOI18N
        }
 }