camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Mueller (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (CAMEL-2565) Create a new camel-bean-validation component (based on JSR 303)
Date Sat, 10 Apr 2010 15:57:43 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-2565?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58766#action_58766
] 

Christian Mueller edited comment on CAMEL-2565 at 4/10/10 11:56 AM:
--------------------------------------------------------------------

Claus, I attached a new patch file which only contains changes for this component. Sorry for
the last faulty patch.

Answers to your questions:
1) validator.xml in META-INF is not required. It's only needed and required, if you want define
your constraints via XML and not with annotations (more [here|http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/#d0e1867]).
All settings shown in the validation.xml are optional.

2) An enum make no sense. This parameter is the full qualified name of an interface which
the user has to develop (only a marker interface). This class name is than used in the annotated
bean as group name (Annotation without an explicit group name belongs implicit to the group
'javax.validation.groups.Default').
{code}
    @NotNull
    @Size(min = 5, max = 14, groups = OptionalChecks.class)
    private String licensePlate;
{code}

is equal to 

{code}
    @NotNull(groups = Default.class)
    @Size(min = 5, max = 14, groups = OptionalChecks.class)
    private String licensePlate;
{code}

This group name (or group names) are provided to the validate method. The validator only checks
constraints for this group (or this groups).

{code}
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(bean,
group);
{code}

To keep things simple, the user can only define one group in this camel component. If this
component should check constraints from more than one group, the user has to define a new
marker interface like this:

{code}
@GroupSequence({Default.class, OptionalChecks.class})
public interface OrderedChecks {
}
{code}

and use OrderedChecks as group name. This checks all constraints within the group Default
(or without a group) and OptionalChecks.
Another possibility for the user is to annotate the bean to redefine the default group (more
[here|http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/#section-default-group-class]):

{code}
@GroupSequence({ Car.class, OptionalChecks.class })
public class  Car {
    ...
}
{code}

For the last choice, I still have to write a unit test... :-)

      was (Author: muellerc):
    Claus, I attached a new patch file which only contains changes for this component. Sorry
for the last faulty patch.

Answers to your questions:
1) validator.xml in META-INF is not required. It's only needed and required, if you want define
your constraints via XML and not with annotations (more [here|http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/#d0e1867]).
All settings shown in the validation.xml are optional.

2) An enum make no sense. This parameter is the full qualified name of an interface which
the user has to develop (only a marker interface). This class name is than used in the annotated
bean as group name (Annotation without an explicit group name belongs implicit to the group
'javax.validation.groups.Default').
{code}
    @NotNull
    @Size(min = 5, max = 14, groups = OptionalChecks.class)
    private String licensePlate;
{code}

is equal to 

{code}
    @NotNull(groups = Default.class)
    @Size(min = 5, max = 14, groups = OptionalChecks.class)
    private String licensePlate;
{code}

This group name (or group names) are provided to the validate method. The validator only checks
constraints for this group (or this groups).

{code}
Set<ConstraintViolation<Object>> constraintViolations = validator.validate(bean,
group);
{code}

To keep things simple, the user can only define one group in this camel component. If this
component should check constraints from more than one group, the user has to define a new
marker interface like this:

{code}
@GroupSequence({Default.class, OptionalChecks.class})
public interface OrderedChecks {
}
{code}

and use OrderedChecks as group name. This checks all constraints within the group Default
(or without a group) and OptionalChecks.
Another possibility for the user is to annotate the bean to redefine the default group (more
[here|http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/#section-default-group-class]):

{code}
@GroupSequence({ Default.class, OptionalChecks.class })
public class  Car {
    ...
}
{code}

For the last choice, I still have to write a unit test... :-)
  
> Create a new camel-bean-validation component (based on JSR 303)
> ---------------------------------------------------------------
>
>                 Key: CAMEL-2565
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2565
>             Project: Apache Camel
>          Issue Type: New Feature
>         Environment: All
>            Reporter: Christian Mueller
>            Assignee: Christian Mueller
>             Fix For: 2.3.0
>
>         Attachments: CAMEL-2565.patch, CAMEL-2565.patch, CAMEL-2565.patch
>
>
> We want provide a validation component for java beans (POJOs) based on [JSR 303|http://jcp.org/en/jsr/detail?id=303].
We want to use the reference implementation, which is [Hibernate Validator|http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/].
> The Hibernate Validator (the reference implementation for JSR 303) is licensed under
the Apache License Version 2: http://anonsvn.jboss.org/repos/hibernate/validator/tags/v4_0_2_GA/license.txt
 but not published as an OSGI bundle. So, I opened the issue [SMX4-506]https://issues.apache.org/activemq/browse/SMX4-506]
to provide an OSGI bundle for that library.
> Please have a look into [Nabble|http://old.nabble.com/Proposal-for-a-new-camel-bean-validation-component-based-on-jsr-303-tp27950969p27950969.html]
for details.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/activemq/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message