Fwd since gmail sent it to Matt only, sorry guys " Well it really slows down the boot, at least in tomee cause we skip them which even if they have a beans.xml cause we optimize container stuff to let business codz only be peocessed.
This is clearly not a user api and im happy to have to use a setter on the extension as well (not easily doable for a user without knowing owb code) Without it tomee will need to wrap the extension. This is feasible as well but I rhink bval can benefit from it ootb. " Romain Manni-Bucau @rmannibucau http://www.tomitribe.com http://rmannibucau.wordpress.com https://github.com/rmannibucau 2014-12-11 0:55 GMT+01:00 Matt Benson <[email protected]>: > On Wed, Dec 10, 2014 at 9:39 AM, Romain Manni-Bucau > <[email protected]> wrote: >> 2014-12-10 16:09 GMT+01:00 Matt Benson <[email protected]>: >>> What is the reason for avoiding ServiceLoader? Don't OWB and others call it? >>> Other than that this approach is fine, but what did you think about a well >>> known resource name as well? >>> >> >> OWB does...excepted in TomEE ;) + OWB singleton uses the same thing. >> This was in my mind a container container and not a user feature - we >> can reconsider it but users have <scan /> now. Well BatchEE and OWB >> use more or less the same thing for their "environemnt" proveider >> (singleton/locator in OWB) and I think we are not bad. Idea is to >> avoid going through ServiceLoader *by default* (a bit like in BVal for >> default impls). It doesn't prevent the impl to use ServiceLoader >> behind. >> >> Main issues with SL are: >> - you need to be sure of the classloader you use >> - if you have conflcts what do you do? AND/OR/fail? >> - go through the classpath which can be big and classloader can be >> slow (maven rrhhhh) >> >> >> If it is bad we can change it later, we just need to tag it is internal for >> now. > > I kind of worry about statements like this; we've delayed 1.0 for > years because we're trying to get the codebase into a state where we > are satisfied with it. What is the performance impact of simply > removing the skip() method and observing all ProcessAnnotatedType > events? This should only be happening for types in bean archives, thus > I don't know why we would need to filter java.* and javax.* anyway. > Then, as the comments say we must be forever on guard that any other > patterns we choose to filter here never use BV executable validation > themselves? > >> >>> Matt >>> >>> Matt >>> >>> On Dec 10, 2014 8:01 AM, "Romain Manni-Bucau" <[email protected]> wrote: >>>> >>>> I would avoid ServiceLoader if possible (at least in TomEE I think we >>>> would like to avoid it and have a default custom filter). >>>> >>>> What about this (pseudo code): >>>> >>>> public static void setFilter(Filter filter) { GLOBAL_FILTER = filter; } >>>> public static Filter getFilter() { >>>> if (GLOBAL_FILTER == null) { >>>> // ServiceLoader on Filter >>>> // if nothing then return DefaultFilter.INSTANCE which uses >>>> current prefixes to filter >>>> } >>>> return GLOBAL_FILTER; >>>> } >>>> >>>> This filter will be retrieved by BValExtension in its constructor a >>>> single time (why we can call the ServiceLoader once/extension if no >>>> global filtering is set. >>>> >>>> wdyt? >>>> >>>> >>>> >>>> Romain Manni-Bucau >>>> @rmannibucau >>>> http://www.tomitribe.com >>>> http://rmannibucau.wordpress.com >>>> https://github.com/rmannibucau >>>> >>>> >>>> 2014-12-10 14:51 GMT+01:00 Matt Benson <[email protected]>: >>>> > On Dec 10, 2014 1:18 AM, "Romain Manni-Bucau" <[email protected]> >>>> > wrote: >>>> >> >>>> >> Hi Matt >>>> >> >>>> >> SKIPPED_PREFIXES was designed to be modifiable. >>>> >> >>>> > >>>> > Sorry; thanks for the note. >>>> > >>>> >> It is not sexy but idea was to let other products like tomee change it >>>> >> without having to release bval. >>>> >> >>>> >> Id be happy to have a Filter.accept(fqn) as well if you find it cleaner >>>> >> - >>>> > I >>>> >> think we should actually. >>>> >> >>>> >> Wdyt? >>>> > >>>> > I guess I need more info to understand what kind of structure you're >>>> > suggesting. Could an SPI work, possibly with the default impl looking >>>> > for a >>>> > well known resource name to make it super-simple? >>>> > >>>> > Matt >>>> > >>>> >> ---------- Message transféré ---------- >>>> >> De : <[email protected]> >>>> >> Date : 10 déc. 2014 01:14 >>>> >> Objet : svn commit: r1644258 - in >>>> >> /bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval: cdi/ >>>> >> jsr/ >>>> >> À : <[email protected]> >>>> >> Cc : >>>> >> >>>> >> Author: mbenson >>>> >> Date: Wed Dec 10 00:14:41 2014 >>>> >> New Revision: 1644258 >>>> >> >>>> >> URL: http://svn.apache.org/r1644258 >>>> >> Log: >>>> >> javadoc, cleanup >>>> >> >>>> >> Modified: >>>> >> >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java >>>> >> >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java >>>> >> >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java >>>> >> >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java >>>> >> >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorBean.java >>>> >> >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorFactoryBean.java >>>> >> >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java >>>> >> >>>> >> Modified: >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java >>>> >> URL: >>>> >> >>>> > >>>> > http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java?rev=1644258&r1=1644257&r2=1644258&view=diff >>>> >> >>>> > >>>> > ============================================================================== >>>> >> --- >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java >>>> >> (original) >>>> >> +++ >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValBinding.java >>>> >> Wed Dec 10 00:14:41 2014 >>>> >> @@ -24,7 +24,9 @@ import java.lang.annotation.Retention; >>>> >> import java.lang.annotation.RetentionPolicy; >>>> >> import java.lang.annotation.Target; >>>> >> >>>> >> -//TODO javadoc >>>> >> +/** >>>> >> + * Custom {@link InterceptorBinding} to invoke executable validations >>>> >> on >>>> >> CDI beans. >>>> >> + */ >>>> >> @Retention(RetentionPolicy.RUNTIME) >>>> >> @Target({ElementType.TYPE}) >>>> >> @InterceptorBinding >>>> >> >>>> >> Modified: >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java >>>> >> URL: >>>> >> >>>> > >>>> > http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java?rev=1644258&r1=1644257&r2=1644258&view=diff >>>> >> >>>> > >>>> > ============================================================================== >>>> >> --- >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java >>>> >> (original) >>>> >> +++ >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java >>>> >> Wed Dec 10 00:14:41 2014 >>>> >> @@ -41,28 +41,34 @@ import javax.validation.executable.Execu >>>> >> import javax.validation.executable.ValidateOnExecution; >>>> >> import javax.validation.metadata.BeanDescriptor; >>>> >> import javax.validation.metadata.MethodType; >>>> >> + >>>> >> import java.lang.reflect.Modifier; >>>> >> import java.lang.reflect.Type; >>>> >> import java.util.Collection; >>>> >> import java.util.Collections; >>>> >> +import java.util.EnumSet; >>>> >> import java.util.HashSet; >>>> >> import java.util.Set; >>>> >> -import java.util.concurrent.CopyOnWriteArraySet; >>>> >> import java.util.logging.Level; >>>> >> import java.util.logging.Logger; >>>> >> >>>> >> +/** >>>> >> + * CDI {@link Extension} for Apache BVal setup. >>>> >> + */ >>>> >> public class BValExtension implements Extension { >>>> >> private static final Logger LOGGER = >>>> >> Logger.getLogger(BValExtension.class.getName()); >>>> >> >>>> >> // extension point, we can add a SPI if needed, today mainly a >>>> >> fallback "API" for TomEE if we encounter an issue >>>> >> - public static Collection<String> SKIPPED_PREFIXES = new >>>> >> HashSet<String>(); >>>> >> + public static final Set<String> SKIPPED_PREFIXES; >>>> >> static { >>>> >> - SKIPPED_PREFIXES.add("java."); >>>> >> - SKIPPED_PREFIXES.add("javax."); >>>> >> - SKIPPED_PREFIXES.add("org.apache.bval."); >>>> >> - SKIPPED_PREFIXES.add("org.apache.openejb."); >>>> >> - SKIPPED_PREFIXES.add("org.apache.deltaspike."); // should be >>>> >> checked when upgrading >>>> >> - SKIPPED_PREFIXES.add("org.apache.myfaces."); // should be >>>> >> checked >>>> >> when upgrading >>>> >> + final Set<String> s = new HashSet<String>(); >>>> >> + s.add("java."); >>>> >> + s.add("javax."); >>>> >> + s.add("org.apache.bval."); >>>> >> + s.add("org.apache.openejb."); >>>> >> + s.add("org.apache.deltaspike."); // should be checked when >>>> >> upgrading >>>> >> + s.add("org.apache.myfaces."); // should be checked when >>>> >> upgrading >>>> >> + SKIPPED_PREFIXES = Collections.unmodifiableSet(s); >>>> >> } >>>> >> >>>> >> private boolean validatorFound = >>>> >> Boolean.getBoolean("bval.in-container"); >>>> >> @@ -84,11 +90,12 @@ public class BValExtension implements Ex >>>> >> config = Validation.byDefaultProvider().configure(); >>>> >> try { >>>> >> final BootstrapConfiguration bootstrap = >>>> >> config.getBootstrapConfiguration(); >>>> >> - globalExecutableTypes = >>>> >> convertToRuntimeTypes(bootstrap.getDefaultValidatedExecutableTypes()); >>>> >> + globalExecutableTypes = >>>> >> >>>> > >>>> > Collections.unmodifiableSet(convertToRuntimeTypes(bootstrap.getDefaultValidatedExecutableTypes())); >>>> >> isExecutableValidationEnabled = >>>> >> bootstrap.isExecutableValidationEnabled(); >>>> >> >>>> >> + // TODO we never contain IMPLICIT or ALL >>>> >> validBean = >>>> >> globalExecutableTypes.contains(ExecutableType.IMPLICIT) || >>>> >> globalExecutableTypes.contains(ExecutableType.ALL); >>>> >> - validConstructors =validBean || >>>> >> globalExecutableTypes.contains(ExecutableType.CONSTRUCTORS); >>>> >> + validConstructors = validBean || >>>> >> globalExecutableTypes.contains(ExecutableType.CONSTRUCTORS); >>>> >> validBusinessMethods = validBean || >>>> >> globalExecutableTypes.contains(ExecutableType.NON_GETTER_METHODS); >>>> >> validGetterMethods = >>>> >> globalExecutableTypes.contains(ExecutableType.ALL) || >>>> >> globalExecutableTypes.contains(ExecutableType.GETTER_METHODS); >>>> >> } catch (final Exception e) { // custom providers can throw an >>>> >> exception >>>> >> @@ -105,22 +112,28 @@ public class BValExtension implements Ex >>>> >> return; >>>> >> } >>>> >> config.addProperty("bval.before.cdi", "true"); // ignore parts >>>> >> of >>>> >> the config relying on CDI since we didn't start yet >>>> >> - factory = factory != null ? factory : >>>> >> config.buildValidatorFactory(); >>>> >> + if (factory == null) { >>>> >> + factory = config.buildValidatorFactory(); >>>> >> + } >>>> >> validator = factory.getValidator(); >>>> >> } >>>> >> >>>> >> private static Set<ExecutableType> convertToRuntimeTypes(final >>>> >> Set<ExecutableType> defaultValidatedExecutableTypes) { >>>> >> - final Set<ExecutableType> types = new >>>> >> CopyOnWriteArraySet<ExecutableType>(); >>>> >> + final Set<ExecutableType> types = >>>> >> EnumSet.noneOf(ExecutableType.class); >>>> >> for (final ExecutableType type : >>>> > defaultValidatedExecutableTypes) { >>>> >> - if (ExecutableType.IMPLICIT.equals(type)) { >>>> >> - types.add(ExecutableType.CONSTRUCTORS); >>>> >> - types.add(ExecutableType.NON_GETTER_METHODS); >>>> >> - } else if (ExecutableType.ALL.equals(type)) { >>>> >> + if (ExecutableType.NONE == type) { >>>> >> + continue; >>>> >> + } >>>> >> + if (ExecutableType.ALL == type) { >>>> >> types.add(ExecutableType.CONSTRUCTORS); >>>> >> types.add(ExecutableType.NON_GETTER_METHODS); >>>> >> types.add(ExecutableType.GETTER_METHODS); >>>> >> break; >>>> >> - } else if (!ExecutableType.NONE.equals(type)) { >>>> >> + } >>>> >> + if (ExecutableType.IMPLICIT == type) { >>>> >> + types.add(ExecutableType.CONSTRUCTORS); >>>> >> + types.add(ExecutableType.NON_GETTER_METHODS); >>>> >> + } else { >>>> >> types.add(type); >>>> >> } >>>> >> } >>>> >> @@ -166,10 +179,12 @@ public class BValExtension implements Ex >>>> >> if >>>> >> (annotatedType.isAnnotationPresent(ValidateOnExecution.class) >>>> >> || >>>> >> hasValidationAnnotation(annotatedType.getMethods()) >>>> >> || >>>> >> hasValidationAnnotation(annotatedType.getConstructors()) >>>> >> - || (validBean && classConstraints != null >>>> >> && >>>> >> classConstraints.isBeanConstrained()) >>>> >> - || (validConstructors && classConstraints >>>> >> != >>>> >> null && !classConstraints.getConstrainedConstructors().isEmpty()) >>>> >> - || (validBusinessMethods && >>>> >> classConstraints >>>> >> != null && >>>> >> >>>> >> !classConstraints.getConstrainedMethods(MethodType.NON_GETTER).isEmpty()) >>>> >> - || (validGetterMethods && classConstraints >>>> >> != >>>> >> null && >>>> >> !classConstraints.getConstrainedMethods(MethodType.GETTER).isEmpty())) >>>> >> { >>>> >> + || classConstraints != null >>>> >> + && (validBean && >>>> >> classConstraints.isBeanConstrained() >>>> >> + || validConstructors && >>>> >> !classConstraints.getConstrainedConstructors().isEmpty() >>>> >> + || validBusinessMethods && >>>> >> >>>> >> !classConstraints.getConstrainedMethods(MethodType.NON_GETTER).isEmpty() >>>> >> + || validGetterMethods && >>>> >> !classConstraints.getConstrainedMethods(MethodType.GETTER).isEmpty()) >>>> >> + ) { >>>> >> // TODO: keep track of bValAnnotatedType and >>>> >> remove @BValBinding in >>>> >> // ProcessBean event if needed cause here we >>>> > can't >>>> >> really add @ValidateOnExecution >>>> >> // through an extension >>>> >> @@ -250,10 +265,11 @@ public class BValExtension implements Ex >>>> >> } >>>> >> } >>>> >> >>>> >> - private static ClassLoader loader() { >>>> >> - return Thread.currentThread().getContextClassLoader(); >>>> >> - } >>>> >> - >>>> >> + /** >>>> >> + * Request that an instance of the specified type be provided by >>>> >> the >>>> >> container. >>>> >> + * @param clazz >>>> >> + * @return the requested instance wrapped in a {@link Releasable}. >>>> >> + */ >>>> >> public static <T> Releasable<T> inject(final Class<T> clazz) { >>>> >> try { >>>> >> final BeanManager beanManager = >>>> > CDI.current().getBeanManager(); >>>> >> @@ -280,6 +296,10 @@ public class BValExtension implements Ex >>>> >> return CDI.current().getBeanManager(); >>>> >> } >>>> >> >>>> >> + /** >>>> >> + * Represents an item that can be released from a {@link >>>> >> CreationalContext} at some point in the future. >>>> >> + * @param <T> >>>> >> + */ >>>> >> public static class Releasable<T> { >>>> >> private final CreationalContext<T> context; >>>> >> private final InjectionTarget<T> injectionTarget; >>>> >> >>>> >> Modified: >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java >>>> >> URL: >>>> >> >>>> > >>>> > http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java?rev=1644258&r1=1644257&r2=1644258&view=diff >>>> >> >>>> > >>>> > ============================================================================== >>>> >> --- >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java >>>> >> (original) >>>> >> +++ >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptor.java >>>> >> Wed Dec 10 00:14:41 2014 >>>> >> @@ -26,6 +26,7 @@ import javax.inject.Inject; >>>> >> import javax.interceptor.AroundConstruct; >>>> >> import javax.interceptor.AroundInvoke; >>>> >> import javax.interceptor.Interceptor; >>>> >> +import javax.interceptor.InterceptorBinding; >>>> >> import javax.interceptor.InvocationContext; >>>> >> import javax.validation.ConstraintViolation; >>>> >> import javax.validation.ConstraintViolationException; >>>> >> @@ -42,19 +43,23 @@ import java.util.ArrayList; >>>> >> import java.util.Arrays; >>>> >> import java.util.Collection; >>>> >> import java.util.Collections; >>>> >> -import java.util.HashSet; >>>> >> +import java.util.EnumSet; >>>> >> import java.util.List; >>>> >> import java.util.Map; >>>> >> import java.util.Set; >>>> >> import java.util.concurrent.ConcurrentHashMap; >>>> >> -import java.util.concurrent.CopyOnWriteArraySet; >>>> >> >>>> >> +/** >>>> >> + * Interceptor class for the {@link BValBinding} {@link >>>> >> InterceptorBinding}. >>>> >> + */ >>>> >> @Interceptor >>>> >> @BValBinding >>>> >> -@Priority(4800) // TODO: maybe add it through ASM to be compliant with >>>> > CDI >>>> >> 1.0 containers using simply this class as a template to generate >>>> >> another >>>> >> one for CDI 1.1 impl >>>> >> +@Priority(4800) >>>> >> +// TODO: maybe add it through ASM to be compliant with CDI 1.0 >>>> >> containers >>>> >> using simply this class as a template to >>>> >> +// generate another one for CDI 1.1 impl >>>> >> public class BValInterceptor { >>>> >> private final Map<Method, Boolean> methodConfiguration = new >>>> >> ConcurrentHashMap<Method, Boolean>(); >>>> >> - private Collection<ExecutableType> classConfiguration; >>>> >> + private Set<ExecutableType> classConfiguration; >>>> >> private Boolean constructorValidated; >>>> >> >>>> >> @Inject >>>> >> @@ -65,7 +70,8 @@ public class BValInterceptor { >>>> >> >>>> >> private ExecutableValidator executableValidator; >>>> >> >>>> >> - @AroundConstruct // TODO: see previous one >>>> >> + @AroundConstruct >>>> >> + // TODO: see previous one >>>> >> public Object construct(final InvocationContext context) throws >>>> >> Exception { >>>> >> @SuppressWarnings("rawtypes") >>>> >> final Constructor constructor = context.getConstructor(); >>>> >> @@ -84,7 +90,8 @@ public class BValInterceptor { >>>> >> >>>> >> { >>>> >> @SuppressWarnings("unchecked") >>>> >> - final Set<ConstraintViolation<?>> violations = >>>> >> executableValidator.validateConstructorParameters(constructor, >>>> >> context.getParameters()); >>>> >> + final Set<ConstraintViolation<?>> violations = >>>> >> + >>>> >> executableValidator.validateConstructorParameters(constructor, >>>> >> context.getParameters()); >>>> >> if (!violations.isEmpty()) { >>>> >> throw new ConstraintViolationException(violations); >>>> >> } >>>> >> @@ -94,7 +101,8 @@ public class BValInterceptor { >>>> >> >>>> >> { >>>> >> @SuppressWarnings("unchecked") >>>> >> - final Set<ConstraintViolation<?>> violations = >>>> >> executableValidator.validateConstructorReturnValue(constructor, >>>> >> context.getTarget()); >>>> >> + final Set<ConstraintViolation<?>> violations = >>>> >> + >>>> >> executableValidator.validateConstructorReturnValue(constructor, >>>> >> context.getTarget()); >>>> >> if (!violations.isEmpty()) { >>>> >> throw new ConstraintViolationException(violations); >>>> >> } >>>> >> @@ -141,7 +149,8 @@ public class BValInterceptor { >>>> >> return result; >>>> >> } >>>> >> >>>> >> - private boolean isConstructorValidated(final Class<?> targetClass, >>>> >> final Constructor<?> constructor) throws NoSuchMethodException { >>>> >> + private boolean isConstructorValidated(final Class<?> targetClass, >>>> >> final Constructor<?> constructor) >>>> >> + throws NoSuchMethodException { >>>> >> initClassConfig(targetClass); >>>> >> >>>> >> if (constructorValidated == null) { >>>> >> @@ -206,18 +215,22 @@ public class BValInterceptor { >>>> >> if (validateOnExecution == null) { >>>> >> methodConfig = doValidMethod(method, >>>> >> classConfiguration); >>>> >> } else { >>>> >> - final Collection<ExecutableType> config = new >>>> >> HashSet<ExecutableType>(); >>>> >> + final Set<ExecutableType> config = >>>> >> EnumSet.noneOf(ExecutableType.class); >>>> >> for (final ExecutableType type : >>>> >> validateOnExecution.type()) { >>>> >> + if (ExecutableType.NONE == type) { >>>> >> + continue; >>>> >> + } >>>> >> + if (ExecutableType.ALL == type) { >>>> >> + >>>> >> config.add(ExecutableType.NON_GETTER_METHODS); >>>> >> + >>>> > config.add(ExecutableType.GETTER_METHODS); >>>> >> + break; >>>> >> + } >>>> >> if (ExecutableType.IMPLICIT == type) { // >>>> >> on >>>> >> method it just means validate, even on getters >>>> >> >>>> >> config.add(ExecutableType.NON_GETTER_METHODS); >>>> >> if (lastClassWithTheMethod == null) { >>>> >> >>>> >> config.add(ExecutableType.GETTER_METHODS); >>>> >> } // else the annotation was not on >>>> >> the >>>> >> method so implicit doesn't mean getters >>>> >> - } else if (ExecutableType.ALL == type) { >>>> >> - >>>> >> config.add(ExecutableType.NON_GETTER_METHODS); >>>> >> - >>>> > config.add(ExecutableType.GETTER_METHODS); >>>> >> - break; >>>> >> - } else if (ExecutableType.NONE != type) { >>>> >> + } else { >>>> >> config.add(type); >>>> >> } >>>> >> } >>>> >> @@ -235,22 +248,26 @@ public class BValInterceptor { >>>> >> if (classConfiguration == null) { >>>> >> synchronized (this) { >>>> >> if (classConfiguration == null) { >>>> >> - classConfiguration = new >>>> >> CopyOnWriteArraySet<ExecutableType>(); >>>> >> + classConfiguration = >>>> >> EnumSet.noneOf(ExecutableType.class); >>>> >> >>>> >> final ValidateOnExecution annotation = >>>> >> targetClass.getAnnotation(ValidateOnExecution.class); >>>> >> if (annotation == null) { >>>> >> >>>> >> >>>> > >>>> > classConfiguration.addAll(globalConfiguration.getGlobalExecutableTypes()); >>>> >> } else { >>>> >> for (final ExecutableType type : >>>> >> annotation.type()) { >>>> >> - if (ExecutableType.IMPLICIT ==type) { >>>> >> - >>>> >> classConfiguration.add(ExecutableType.CONSTRUCTORS); >>>> >> - >>>> >> classConfiguration.add(ExecutableType.NON_GETTER_METHODS); >>>> >> - } else if (ExecutableType.ALL == type) { >>>> >> + if (ExecutableType.NONE == type) { >>>> >> + continue; >>>> >> + } >>>> >> + if (ExecutableType.ALL == type) { >>>> >> >>>> >> classConfiguration.add(ExecutableType.CONSTRUCTORS); >>>> >> >>>> >> classConfiguration.add(ExecutableType.NON_GETTER_METHODS); >>>> >> >>>> >> classConfiguration.add(ExecutableType.GETTER_METHODS); >>>> >> break; >>>> >> - } else if (ExecutableType.NONE != type) { >>>> >> + } >>>> >> + if (ExecutableType.IMPLICIT == type) { >>>> >> + >>>> >> classConfiguration.add(ExecutableType.CONSTRUCTORS); >>>> >> + >>>> >> classConfiguration.add(ExecutableType.NON_GETTER_METHODS); >>>> >> + } else { >>>> >> classConfiguration.add(type); >>>> >> } >>>> >> } >>>> >> @@ -270,14 +287,14 @@ public class BValInterceptor { >>>> >> } >>>> >> } >>>> >> >>>> >> - private static boolean doValidMethod(final Method method, final >>>> >> Collection<ExecutableType> config) { >>>> >> - final boolean getter = isGetter(method); >>>> >> - return (!getter && >>>> >> config.contains(ExecutableType.NON_GETTER_METHODS)) >>>> >> - || (getter && >>>> > config.contains(ExecutableType.GETTER_METHODS)); >>>> >> + private static boolean doValidMethod(final Method method, final >>>> >> Set<ExecutableType> config) { >>>> >> + return isGetter(method) ? >>>> >> config.contains(ExecutableType.GETTER_METHODS) : config >>>> >> + .contains(ExecutableType.NON_GETTER_METHODS); >>>> >> } >>>> >> >>>> >> private static boolean isGetter(final Method method) { >>>> >> final String name = method.getName(); >>>> >> - return (name.startsWith("get") || name.startsWith("is")) && >>>> >> method.getParameterTypes().length == 0; >>>> >> - } >>>> >> + return method.getParameterTypes().length == 0 && >>>> >> !Void.TYPE.equals(method.getReturnType()) >>>> >> + && (name.startsWith("get") || name.startsWith("is") && >>>> >> boolean.class.equals(method.getReturnType())); >>>> >> + } >>>> >> } >>>> >> >>>> >> Modified: >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java >>>> >> URL: >>>> >> >>>> > >>>> > http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java?rev=1644258&r1=1644257&r2=1644258&view=diff >>>> >> >>>> > >>>> > ============================================================================== >>>> >> --- >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java >>>> >> (original) >>>> >> +++ >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValInterceptorBean.java >>>> >> Wed Dec 10 00:14:41 2014 >>>> >> @@ -33,6 +33,9 @@ import java.util.Collections; >>>> >> import java.util.HashSet; >>>> >> import java.util.Set; >>>> >> >>>> >> +/** >>>> >> + * {@link BValInterceptor} CDI {@link Bean}. >>>> >> + */ >>>> >> public class BValInterceptorBean implements Bean<BValInterceptor>, >>>> >> PassivationCapable { >>>> >> private final Set<Type> types; >>>> >> private final Set<Annotation> qualifiers; >>>> >> @@ -40,13 +43,15 @@ public class BValInterceptorBean impleme >>>> >> private final InjectionTarget<BValInterceptor> injectionTarget; >>>> >> >>>> >> public BValInterceptorBean(final BeanManager bm) { >>>> >> - types = new HashSet<Type>(); >>>> >> - types.add(BValInterceptor.class); >>>> >> - types.add(Object.class); >>>> >> + final Set<Type> t = new HashSet<Type>(); >>>> >> + t.add(BValInterceptor.class); >>>> >> + t.add(Object.class); >>>> >> + types = Collections.unmodifiableSet(t); >>>> >> >>>> >> - qualifiers = new HashSet<Annotation>(); >>>> >> - qualifiers.add(DefaultLiteral.INSTANCE); >>>> >> - qualifiers.add(AnyLiteral.INSTANCE); >>>> >> + final Set<Annotation> q = new HashSet<Annotation>(); >>>> >> + q.add(DefaultLiteral.INSTANCE); >>>> >> + q.add(AnyLiteral.INSTANCE); >>>> >> + qualifiers = Collections.unmodifiableSet(q); >>>> >> >>>> >> injectionTarget = >>>> >> >>>> >> bm.createInjectionTarget(bm.createAnnotatedType(BValInterceptor.class)); >>>> >> injectionPoints = >>>> >> >>>> >> Modified: >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorBean.java >>>> >> URL: >>>> >> >>>> > >>>> > http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorBean.java?rev=1644258&r1=1644257&r2=1644258&view=diff >>>> >> >>>> > >>>> > ============================================================================== >>>> >> --- >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorBean.java >>>> >> (original) >>>> >> +++ >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorBean.java >>>> >> Wed Dec 10 00:14:41 2014 >>>> >> @@ -31,7 +31,10 @@ import java.util.Collections; >>>> >> import java.util.HashSet; >>>> >> import java.util.Set; >>>> >> >>>> >> -public class ValidatorBean implements Bean<Validator> , >>>> > PassivationCapable{ >>>> >> +/** >>>> >> + * {@link Validator} CDI {@link Bean}. >>>> >> + */ >>>> >> +public class ValidatorBean implements Bean<Validator> , >>>> > PassivationCapable >>>> >> { >>>> >> private final Set<Type> types; >>>> >> private final Set<Annotation> qualifiers; >>>> >> private final ValidatorFactory factory; >>>> >> @@ -41,13 +44,15 @@ public class ValidatorBean implements Be >>>> >> this.factory = factory; >>>> >> this.instance = validator; >>>> >> >>>> >> - types = new HashSet<Type>(); >>>> >> - types.add(Validator.class); >>>> >> - types.add(Object.class); >>>> >> + final Set<Type> t = new HashSet<Type>(); >>>> >> + t.add(Validator.class); >>>> >> + t.add(Object.class); >>>> >> + types = Collections.unmodifiableSet(t); >>>> >> >>>> >> - qualifiers = new HashSet<Annotation>(); >>>> >> - qualifiers.add(DefaultLiteral.INSTANCE); >>>> >> - qualifiers.add(AnyLiteral.INSTANCE); >>>> >> + final Set<Annotation> q = new HashSet<Annotation>(); >>>> >> + q.add(DefaultLiteral.INSTANCE); >>>> >> + q.add(AnyLiteral.INSTANCE); >>>> >> + qualifiers = Collections.unmodifiableSet(q); >>>> >> } >>>> >> >>>> >> public Set<Type> getTypes() { >>>> >> >>>> >> Modified: >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorFactoryBean.java >>>> >> URL: >>>> >> >>>> > >>>> > http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorFactoryBean.java?rev=1644258&r1=1644257&r2=1644258&view=diff >>>> >> >>>> > >>>> > ============================================================================== >>>> >> --- >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorFactoryBean.java >>>> >> (original) >>>> >> +++ >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/ValidatorFactoryBean.java >>>> >> Wed Dec 10 00:14:41 2014 >>>> >> @@ -30,6 +30,9 @@ import java.util.Collections; >>>> >> import java.util.HashSet; >>>> >> import java.util.Set; >>>> >> >>>> >> +/** >>>> >> + * {@link ValidatorFactory} CDI {@link Bean}. >>>> >> + */ >>>> >> public class ValidatorFactoryBean implements Bean<ValidatorFactory> , >>>> >> PassivationCapable{ >>>> >> private final Set<Type> types; >>>> >> private final Set<Annotation> qualifiers; >>>> >> @@ -38,13 +41,15 @@ public class ValidatorFactoryBean implem >>>> >> public ValidatorFactoryBean(final ValidatorFactory >>>> >> validatorFactory) >>>> > { >>>> >> this.instance = validatorFactory; >>>> >> >>>> >> - types = new HashSet<Type>(); >>>> >> - types.add(ValidatorFactory.class); >>>> >> - types.add(Object.class); >>>> >> + final Set<Type> t = new HashSet<Type>(); >>>> >> + t.add(ValidatorFactory.class); >>>> >> + t.add(Object.class); >>>> >> + types = Collections.unmodifiableSet(t); >>>> >> >>>> >> - qualifiers = new HashSet<Annotation>(); >>>> >> - qualifiers.add(DefaultLiteral.INSTANCE); >>>> >> - qualifiers.add(AnyLiteral.INSTANCE); >>>> >> + final Set<Annotation> q = new HashSet<Annotation>(); >>>> >> + q.add(DefaultLiteral.INSTANCE); >>>> >> + q.add(AnyLiteral.INSTANCE); >>>> >> + qualifiers = Collections.unmodifiableSet(q); >>>> >> } >>>> >> >>>> >> public Set<Type> getTypes() { >>>> >> >>>> >> Modified: >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java >>>> >> URL: >>>> >> >>>> > >>>> > http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java?rev=1644258&r1=1644257&r2=1644258&view=diff >>>> >> >>>> > >>>> > ============================================================================== >>>> >> --- >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java >>>> >> (original) >>>> >> +++ >>>> >> >>>> > >>>> > bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java >>>> >> Wed Dec 10 00:14:41 2014 >>>> >> @@ -33,7 +33,7 @@ import java.util.concurrent.CopyOnWriteA >>>> >> * Description: create constraint instances with the default / no-arg >>>> >> constructor <br/> >>>> >> */ >>>> >> public class DefaultConstraintValidatorFactory implements >>>> >> ConstraintValidatorFactory, Closeable { >>>> >> - private final Collection< BValExtension.Releasable<?>> releasables >>>> >> = >>>> >> new CopyOnWriteArrayList<BValExtension.Releasable<?>>(); >>>> >> + private final Collection<BValExtension.Releasable<?>> releasables >>>> >> = >>>> >> new CopyOnWriteArrayList<BValExtension.Releasable<?>>(); >>>> >> private Boolean useCdi = null; // store it to avoid >>>> >> NoClassDefFoundError when cdi is not present (it is slow) + lazily (to >>>> > wait >>>> >> cdi is started) >>>> >> >>>> >> /** >>>> >> @@ -47,11 +47,11 @@ public class DefaultConstraintValidatorF >>>> >> synchronized (this) { >>>> >> if (useCdi == null) { >>>> >> try { >>>> >> - useCdi = BValExtension.getBeanManager() != >>>> >> null; >>>> >> + useCdi = >>>> >> Boolean.valueOf(BValExtension.getBeanManager() != null); >>>> >> } catch (final NoClassDefFoundError error) { >>>> >> - useCdi = false; >>>> >> + useCdi = Boolean.FALSE; >>>> >> } catch (final Exception e) { >>>> >> - useCdi = false; >>>> >> + useCdi = Boolean.FALSE; >>>> >> } >>>> >> } >>>> >> } >>>> >> @@ -60,7 +60,7 @@ public class DefaultConstraintValidatorF >>>> >> // 2011-03-27 jw: Do not use PrivilegedAction. >>>> >> // Otherwise any user code would be executed with the >>>> >> privileges >>>> >> of this class. >>>> >> try { >>>> >> - if (useCdi) { >>>> >> + if (useCdi.booleanValue()) { >>>> >> try { >>>> >> final BValExtension.Releasable<T> instance = >>>> >> BValExtension.inject(constraintClass); >>>> >> if (instance != null) {
