bval-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Benson <gudnabr...@gmail.com>
Subject Re: Fwd: svn commit: r1644258 - in /bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval: cdi/ jsr/
Date Wed, 10 Dec 2014 13:51:31 GMT
On Dec 10, 2014 1:18 AM, "Romain Manni-Bucau" <rmannibucau@gmail.com> 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 : <mbenson@apache.org>
> 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/
> À : <commits@bval.apache.org>
> 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) {

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message