]> git.mxchange.org Git - jcore-utils.git/blobdiff - src/org/mxchange/jcoreee/validator/BaseObjectValidator.java
Continued:
[jcore-utils.git] / src / org / mxchange / jcoreee / validator / BaseObjectValidator.java
diff --git a/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java b/src/org/mxchange/jcoreee/validator/BaseObjectValidator.java
deleted file mode 100644 (file)
index 2e9d26f..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2016 - 2018 Free Software Foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jcoreee.validator;
-
-import java.io.Serializable;
-import java.text.MessageFormat;
-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;
-
-/**
- * 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>
- * @param <Object> Any object that needs validation
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public abstract class BaseObjectValidator<Object> implements Validator, Serializable {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 48_574_878_176_939_512L;
-
-       /**
-        * 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
-        * @param requiredFields Array of required field names (ending with)
-        * @param allowNull      Whether null or empty values are allowed
-        * <p>
-        * @throws ValidatorException If something more horrible went wrong
-        */
-       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, Boolean allowNull) throws ValidatorException {
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("preValidate: context={0},component={1},value={2},requiredFields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
-
-               // Init message and key
-               String requiredMessage = null;
-
-               // Get client id
-               final String clientId = component.getClientId();
-
-               // Check component's id against required fields and find a match
-               for (final String field : requiredFields) {
-                       // Get logger
-                       //this.getLogger().logDebug(MessageFormat.format("preValidate: field={0},clientId={1}", field, clientId)); //NOI18N
-
-                       // Is it the same?
-                       if (clientId.endsWith(field)) {
-                               // Is it null?
-                               if ((!allowNull) && (null == value)) {
-                                       // Value it null
-                                       requiredMessage = MessageFormat.format("Field {0} is null.", field); //NOI18N
-                               }
-
-                               // Abort here
-                               break;
-                       }
-               }
-
-               // Debug message
-               //* NOISY-DEBUG: */ this.getLogger().logDebug(MessageFormat.format("preValidate: requiredMessage={0}", requiredMessage)); //NOI18N
-               // Is it not null?
-               if (null != requiredMessage) {
-                       throw new ValidatorException(new FacesMessage(MessageFormat.format("Value {0} for clientId={1} is not valid/unexpected.", value, clientId)));
-               }
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("preValidate: EXIT!"); //NOI18N
-       }
-
-}