[bv-dev] bv-dev] [BVAL-251] Improve Bean Validation support for modularized environments

Gunnar Morling gunnar.morling at googlemail.com
Mon May 14 15:06:41 EDT 2012


2012/5/14 Emmanuel Bernard <emmanuel at hibernate.org>:
>
> On 14 mai 2012, at 17:19, Hardy Ferentschik wrote:
>
>>>>>>
>>>>>> From where:
>>>>>
>>>>> - from the user application or from the module depending on BV
>>>>
>>>> I am also trying to understand what a modular environment means for a shared ValidatorFactory.
>>>> If a user application depends on BV and also uses custom constraints, does it not mean the application
>>>> would need to build its own ValidatorFactory via ValidatorFactory#usingContext()#classLoaderService(classLoaderService).
>>>
>>> That would sucks balls!
>>
>> How else do you ensure class visibility (mind you I am just trying to understand how these environments work)
>
> I'm unclear too. I wish to OSGi semi-gods would step in. But I imagine that OSGi imposing these string would lead to a custom way to initialize the ValidatorFactory. Some kind of bootstrapper class at the module level would have to be implemented to wire things up together. The bootstrapper class would be responsible from providing the ClassloaderService impl as well as ConstraintValidatorFactory etc.

That's my understanding of how it should work on OSGi.

The bootstrapper class you're mentioning would be a bundle activator
in OSGi. The bundle and its activator (and thus its class loader)
should be able to see all resources (descriptors, custom constraints
etc.) provided by the application. Within the activator the validator
factory could be bootstrapped (passing the bundle class loader to BV)
and for instance be registered as OSGi service.

If the application is made up of several modules, the activator of
some application module (having dependencies to all other modules and
thus seeing all their exported resources) should be in charge of
bootstrapping the factory.

I thought of simply passing a class loader during bootstrapping like
this (option #3 in Neil Bartlett's post which Hardy mentioned [1]):

ClassLoader cl = obtainRightClassLoaderForLoadingApplicationResources();

Validation
    .byDefaultProvider()
    .configure()
    .userClassLoader( cl )
    .buildValidatorFactory();

AFAIU at least in OSGi there should be one CL which is able to load
all user resources (not sure about other modular environments). BV
would use this class loader to load all user provided resources. If no
CL is provided this way the TCCL could be used as fallback.

I'm trying to prototype something along these lines at the moment and
will hopefully be able to report on the findings soon.

--Gunnar

[1] http://njbartlett.name/2010/08/30/osgi-readiness-loading-classes.html

>
> As I said that's guesstimate on my part but every time I tried to ask this question, people started to walk the other direction or for the bravest going full stream theoretical and conceptual ;)
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev



More information about the beanvalidation-dev mailing list