]> git.mxchange.org Git - jcoreee.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 30 May 2020 16:33:25 +0000 (18:33 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 30 May 2020 16:33:25 +0000 (18:33 +0200)
- added validation of parameter: all methods and constructors with access level
  protected, package and public must check if parameters are valid, e.g. not
  null where no null is wanted/expected.
- removed jcore-logger-lib.jar as no logging is possible here

Signed-off-by: Roland Häder <roland@mxchange.org>
nbproject/project.properties
src/org/mxchange/jcoreee/validator/BaseObjectValidator.java
src/org/mxchange/jcoreee/validator/bool/BaseBooleanValidator.java
src/org/mxchange/jcoreee/validator/date/BaseDateValidator.java
src/org/mxchange/jcoreee/validator/number/BaseNumberValidator.java
src/org/mxchange/jcoreee/validator/string/BaseStringValidator.java

index 9da5665ada66debe2b577bffdf5d379196be045c..643d00e4c7c88de08d13932dd9afcbd8e06f48e1 100644 (file)
@@ -30,13 +30,11 @@ dist.jar=${dist.dir}/jcoreee.jar
 dist.javadoc.dir=${dist.dir}/javadoc
 endorsed.classpath=
 excludes=
-file.reference.jcore-logger-lib.jar=lib/jcore-logger-lib.jar
 includes=**
 jar.archive.disabled=${jnlp.enabled}
 jar.compress=false
 jar.index=${jnlp.enabled}
 javac.classpath=\
-    ${file.reference.jcore-logger-lib.jar}:\
     ${libs.javaee-api-7.0.classpath}
 # Space-separated list of extra javac options
 javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
@@ -90,6 +88,5 @@ run.test.classpath=\
     ${javac.test.classpath}:\
     ${build.test.classes.dir}
 source.encoding=UTF-8
-source.reference.jcore-logger-lib.jar=../jcore-logger-lib/src/
 src.dir=src
 test.src.dir=test
index e1ea37fe943822bd137631c27f06ebfb5db74453..fe24f2780fc646df11740ba165e36a3c89fb2024 100644 (file)
@@ -55,9 +55,21 @@ public abstract class BaseObjectValidator<Object> implements Validator, Serializ
         * <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
+       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, final Boolean allowNull) throws ValidatorException {
+               // Are all parameter set?
+               if (null == context) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter context is null"); //NOI18N
+               } else if (null == component) {
+                       // Throw NPE again
+                       throw new NullPointerException("Parameter component is null"); //NOI18N
+               } else if (null == requiredFields) {
+                       // Throw it again
+                       throw new NullPointerException("Parameter requiredFields is null"); //NOI18N
+               } else if (null == allowNull) {
+                       // Throw it once more
+                       throw new NullPointerException("Parameter allowNull is null"); //NOI18N
+               }
 
                // Init message and key
                String requiredMessage = null;
@@ -67,9 +79,6 @@ public abstract class BaseObjectValidator<Object> implements Validator, Serializ
 
                // 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?
@@ -83,15 +92,10 @@ public abstract class BaseObjectValidator<Object> implements Validator, Serializ
                        }
                }
 
-               // 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)));
+                       throw new ValidatorException(new FacesMessage(MessageFormat.format("Value {0} for clientId={1} is not valid/unexpected.", value, clientId))); //NOI18N
                }
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("preValidate: EXIT!"); //NOI18N
        }
 
 }
index 045f867641cf63debac8d8194ab0d76d4b3d658e..dd7e5af32a59a3f71e6972214834f1bd7acb89db 100644 (file)
@@ -39,22 +39,31 @@ public abstract class BaseBooleanValidator extends BaseObjectValidator<Object> {
        private static final long serialVersionUID = 42_378_178_715_910_689L;
 
        @Override
-       public 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
+       public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, final Boolean allowNull) throws ValidatorException {
+               // Are all parameter set?
+               if (null == context) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter context is null"); //NOI18N
+               } else if (null == component) {
+                       // Throw NPE again
+                       throw new NullPointerException("Parameter component is null"); //NOI18N
+               } else if (null == requiredFields) {
+                       // Throw it again
+                       throw new NullPointerException("Parameter requiredFields is null"); //NOI18N
+               } else if (null == allowNull) {
+                       // Throw it once more
+                       throw new NullPointerException("Parameter allowNull is null"); //NOI18N
+               }
 
                // Pre-validate
                super.preValidate(context, component, value, requiredFields, allowNull);
 
                // Get client id and init message + key
-               String clientId = component.getClientId();
+               final String clientId = component.getClientId();
                String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
-                       // Debug message
-                       //this.getLogger().logDebug(MessageFormat.format("preValidate: field={0},clientId={1}", field, clientId)); //NOI18N
-
                        // Is it the same?
                        if (clientId.endsWith(field)) {
                                // Compare value's type
index 9d5b1d68e2106105d919c6399ccee75e3a271e03..b808279b28b1405876f0a67634cdfdd84328eb3b 100644 (file)
@@ -38,21 +38,30 @@ public abstract class BaseDateValidator extends BaseObjectValidator<Object> {
 
        @Override
        public 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
+               // Are all parameter set?
+               if (null == context) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter context is null"); //NOI18N
+               } else if (null == component) {
+                       // Throw NPE again
+                       throw new NullPointerException("Parameter component is null"); //NOI18N
+               } else if (null == requiredFields) {
+                       // Throw it again
+                       throw new NullPointerException("Parameter requiredFields is null"); //NOI18N
+               } else if (null == allowNull) {
+                       // Throw it once more
+                       throw new NullPointerException("Parameter allowNull is null"); //NOI18N
+               }
 
                // Pre-validate
                super.preValidate(context, component, value, requiredFields, allowNull);
 
                // Get client id and init message + key
-               String clientId = component.getClientId();
+               final String clientId = component.getClientId();
                String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
-                       // Debug message
-                       //this.getLogger().logDebug(MessageFormat.format("preValidate: field={0},clientId={1}", field, clientId)); //NOI18N
-
                        // Is it the same?
                        if (clientId.endsWith(field)) {
                                // Compare value's type
index 8d212b530a51da4321506a5586e918c99653c2fe..0bd5aac86cbaa622d3a9bd0636e0a82dc4438d37 100644 (file)
@@ -36,15 +36,27 @@ public abstract class BaseNumberValidator extends BaseObjectValidator<Object> {
        private static final long serialVersionUID = 25_481_878_590_589_321L;
 
        @Override
-       public 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},allowNull={4} - CALLED!", context, component, value, Arrays.toString(requiredFields, allowNull))); //NOI18N
+       public void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, final Boolean allowNull) throws ValidatorException {
+               // Are all parameter set?
+               if (null == context) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter context is null"); //NOI18N
+               } else if (null == component) {
+                       // Throw NPE again
+                       throw new NullPointerException("Parameter component is null"); //NOI18N
+               } else if (null == requiredFields) {
+                       // Throw it again
+                       throw new NullPointerException("Parameter requiredFields is null"); //NOI18N
+               } else if (null == allowNull) {
+                       // Throw it once more
+                       throw new NullPointerException("Parameter allowNull is null"); //NOI18N
+               }
 
                // Pre-validate
                super.preValidate(context, component, value, requiredFields, allowNull);
 
                // Get client id and init message + key
-               String clientId = component.getClientId();
+               final String clientId = component.getClientId();
                String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
index acec6d53d716f28d63c41b7fc400efca2336b6e6..58f9c6b6492ccfdb6522b48204637ac4b387e5eb 100644 (file)
@@ -37,22 +37,31 @@ public abstract class BaseStringValidator extends BaseObjectValidator<Object> {
        private static final long serialVersionUID = 15_484_578_781_760_287L;
 
        @Override
-       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},fields={3} - CALLED!", context, component, value, Arrays.toString(requiredFields))); //NOI18N
+       protected void preValidate (final FacesContext context, final UIComponent component, final Object value, final String[] requiredFields, final Boolean allowNull) throws ValidatorException {
+               // Are all parameter set?
+               if (null == context) {
+                       // Throw NPE
+                       throw new NullPointerException("Parameter context is null"); //NOI18N
+               } else if (null == component) {
+                       // Throw NPE again
+                       throw new NullPointerException("Parameter component is null"); //NOI18N
+               } else if (null == requiredFields) {
+                       // Throw it again
+                       throw new NullPointerException("Parameter requiredFields is null"); //NOI18N
+               } else if (null == allowNull) {
+                       // Throw it once more
+                       throw new NullPointerException("Parameter allowNull is null"); //NOI18N
+               }
 
                // Pre-validate (example: on null)
                super.preValidate(context, component, value, requiredFields, allowNull);
 
                // Get client id and init message + key
-               String clientId = component.getClientId();
+               final String clientId = component.getClientId();
                String requiredMessage = null;
 
                // So far all fine, no check if the field is fine
                for (final String field : requiredFields) {
-                       // Debug message
-                       //this.getLogger().logDebug(MessageFormat.format("preValidate: field={0},clientId={1}", field, clientId)); //NOI18N
-
                        // Is it the same?
                        if (clientId.endsWith(field)) {
                                // Compare value's type
@@ -75,16 +84,10 @@ public abstract class BaseStringValidator extends BaseObjectValidator<Object> {
                        }
                }
 
-               // Debug message
-               //this.getLogger().logDebug(MessageFormat.format("preValidate: requiredMessage={0}", requiredMessage)); //NOI18N
-
                // Is it not null?
                if (null != requiredMessage) {
                        // Then there was something wrong with it
                        throw new ValidatorException(new FacesMessage(requiredMessage));
                }
-
-               // Trace message
-               //* NOISY-DEBUG: */ System.out.println("preValidate: EXIT!"); //NOI18N
        }
 }