logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Sicker <boa...@gmail.com>
Subject Re: [2/8] git commit: Add validation message to @RequiresNonNull.
Date Mon, 15 Sep 2014 16:28:40 GMT
Well, it's certainly worth trying. However, if we went that route, would we
have a hard dependency on the javax.validation API? Or would we
package-rename things and embed it?

On 15 September 2014 11:24, Gary Gregory <garydgregory@gmail.com> wrote:

> It all depends on your POV ;-) , one of which is, what we are doing now is
> overkill compared to what we started with...
>
> So, why not Bean Validation, more precisely? It seems we owe it to the
> project to try it (in a branch perhaps) and _know_ that it is possible or
> not a right fit.
>
> Conceptually, it's hard to see how it would not be a right fit.
>
> Gary
>
> On Mon, Sep 15, 2014 at 11:10 AM, Matt Sicker <boards@gmail.com> wrote:
>
>> I was looking at bean validation, and not only is it overkill for our
>> situation, but I don't know how well it would work either.
>>
>> On 15 September 2014 05:50, Gary Gregory <garydgregory@gmail.com> wrote:
>>
>>> I don't about this... I feel we need to discuss this before we reinvent
>>> the bean validation JSR wheel and Hibernate Validator or some other
>>> implementation. Why are we forcing users to learn another framework instead
>>> of using a standard? This is almost -1 territory... I feel we need to clean
>>> up the builder pattern mess before we make another decision on plugins...
>>>
>>> Gary
>>>
>>>
>>> -------- Original message --------
>>> From: mattsicker@apache.org
>>> Date:09/14/2014 23:34 (GMT-05:00)
>>> To: commits@logging.apache.org
>>> Subject: [2/8] git commit: Add validation message to @RequiresNonNull.
>>>
>>> Add validation message to @RequiresNonNull.
>>>
>>>
>>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>> Commit:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/20e739a5
>>> Tree:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/20e739a5
>>> Diff:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/20e739a5
>>>
>>> Branch: refs/heads/master
>>> Commit: 20e739a5308023e4f5b03a49ea12f473193dcbea
>>> Parents: 84e7fed
>>> Author: Matt Sicker <mattsicker@apache.org>
>>> Authored: Sun Sep 14 20:26:48 2014 -0500
>>> Committer: Matt Sicker <mattsicker@apache.org>
>>> Committed: Sun Sep 14 20:26:48 2014 -0500
>>>
>>> ----------------------------------------------------------------------
>>> .../validation/constraints/RequiresNonNull.java       |  5 +++++
>>> .../validators/RequiresNonNullValidator.java          | 14 +++++++++++++-
>>> 2 files changed, 18 insertions(+), 1 deletion(-)
>>> ----------------------------------------------------------------------
>>>
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20e739a5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
>>> ----------------------------------------------------------------------
>>> diff --git
>>> a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
>>> index b3ef11d..7eb83e2 100644
>>> ---
>>> a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
>>> +++
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/constraints/RequiresNonNull.java
>>> @@ -36,4 +36,9 @@ import
>>> org.apache.logging.log4j.core.config.plugins.validation.validators.Requir
>>> @Target({ElementType.FIELD, ElementType.PARAMETER})
>>> @Constraint(RequiresNonNullValidator.class)
>>> public @interface RequiresNonNull {
>>> +
>>> +    /**
>>> +     * The message to be logged if this constraint is violated. This
>>> should normally be overridden.
>>> +     */
>>> +    String message() default "The parameter is null";
>>> }
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20e739a5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
>>> ----------------------------------------------------------------------
>>> diff --git
>>> a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
>>> index 49c5806..9a39d4d 100644
>>> ---
>>> a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
>>> +++
>>> b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/validation/validators/RequiresNonNullValidator.java
>>> @@ -16,8 +16,10 @@
>>>   */
>>> package
>>> org.apache.logging.log4j.core.config.plugins.validation.validators;
>>>
>>> +import org.apache.logging.log4j.Logger;
>>> import
>>> org.apache.logging.log4j.core.config.plugins.validation.ConstraintValidator;
>>> import
>>> org.apache.logging.log4j.core.config.plugins.validation.constraints.RequiresNonNull;
>>> +import org.apache.logging.log4j.status.StatusLogger;
>>>
>>> /**
>>>   * Validator implementation for {@link RequiresNonNull}.
>>> @@ -25,12 +27,22 @@ import
>>> org.apache.logging.log4j.core.config.plugins.validation.constraints.Requi
>>>   * @since 2.1
>>>   */
>>> public class RequiresNonNullValidator implements
>>> ConstraintValidator<RequiresNonNull, Object> {
>>> +
>>> +    private static final Logger LOGGER = StatusLogger.getLogger();
>>> +
>>> +    private RequiresNonNull annotation;
>>> +
>>>      @Override
>>>      public void initialize(final RequiresNonNull annotation) {
>>> +        this.annotation = annotation;
>>>      }
>>>
>>>      @Override
>>>      public boolean isValid(final Object value) {
>>> -        return value != null;
>>> +        if (value != null) {
>>> +            return true;
>>> +        }
>>> +        LOGGER.error(annotation.message());
>>> +        return false;
>>>      }
>>> }
>>>
>>>
>>
>>
>> --
>> Matt Sicker <boards@gmail.com>
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <boards@gmail.com>

Mime
View raw message