@Inject public InjectingConstraintValidatorFactory(BeanManager beanManager) { Contracts.assertNotNull( beanManager, "The BeanManager cannot be null" ); this.beanManager = beanManager; }
@Override public Integer getTypeArgumentIndex() { Contracts.assertTrue( kind == ElementKind.BEAN || kind == ElementKind.PROPERTY || kind == ElementKind.CONTAINER_ELEMENT, "getTypeArgumentIndex() may only be invoked for nodes of type ElementKind.BEAN, ElementKind.PROPERTY or ElementKind.CONTAINER_ELEMENT." ); if ( parent == null ) { return null; } return parent.typeArgumentIndex; }
@Override public <A extends Annotation> ConstraintDefinitionContext<A> constraintDefinition(Class<A> annotationClass) { Contracts.assertNotNull( annotationClass, MESSAGES.annotationTypeMustNotBeNull() ); Contracts.assertTrue( annotationClass.isAnnotationPresent( Constraint.class ), MESSAGES.annotationTypeMustBeAnnotatedWithConstraint() ); if ( definedConstraints.contains( annotationClass ) ) { // Fail fast for easy-to-detect definition conflicts; other conflicts are handled in ValidatorFactoryImpl throw log.getConstraintHasAlreadyBeenConfiguredViaProgrammaticApiException( annotationClass ); } ConstraintDefinitionContextImpl<A> constraintContext = new ConstraintDefinitionContextImpl<A>( this, annotationClass ); constraintContexts.add( constraintContext ); definedConstraints.add( annotationClass ); return constraintContext; }
@Override public PropertyConstraintMappingContext property(String property, ElementType elementType) { Contracts.assertNotNull( property, "The property name must not be null." ); Contracts.assertNotNull( elementType, "The element type must not be null." ); Contracts.assertNotEmpty( property, MESSAGES.propertyNameMustNotBeEmpty() ); Member member = getMember( beanClass, property, elementType ); if ( member == null || member.getDeclaringClass() != beanClass ) { throw LOG.getUnableToFindPropertyWithAccessException( beanClass, property, elementType ); } if ( configuredMembers.contains( member ) ) { throw LOG.getPropertyHasAlreadyBeConfiguredViaProgrammaticApiException( beanClass, property ); } PropertyConstraintMappingContextImpl context = new PropertyConstraintMappingContextImpl( this, member ); configuredMembers.add( member ); propertyContexts.add( context ); return context; }
private void validateParameters(ParameterScriptAssert constraintAnnotation) { Contracts.assertNotEmpty( constraintAnnotation.script(), MESSAGES.parameterMustNotBeEmpty( "script" ) ); Contracts.assertNotEmpty( constraintAnnotation.lang(), MESSAGES.parameterMustNotBeEmpty( "lang" ) ); } }
/** * Creates a locator that delivers a resource bundle merged from the given * list of source bundles. * * @param bundleNames A list with source bundle names. The returned bundle will * contain all keys from all source bundles. In case a key occurs * in multiple source bundles, the value will be taken from the * first bundle containing the key. * @param delegate A delegate resource bundle locator. The bundle returned by * this locator will be added to the aggregate bundle after all * source bundles. * @param classLoader The classloader to use for loading the bundle. * @since 5.2 */ public AggregateResourceBundleLocator(List<String> bundleNames, ResourceBundleLocator delegate, ClassLoader classLoader) { super( delegate ); Contracts.assertValueNotNull( bundleNames, "bundleNames" ); this.bundleNames = Collections.unmodifiableList( bundleNames ); this.classLoader = classLoader; }
@Override public <A extends Annotation> ConstraintDefinitionContext<A> constraintDefinition(Class<A> annotationClass) { Contracts.assertNotNull( annotationClass, MESSAGES.annotationTypeMustNotBeNull() ); Contracts.assertTrue( annotationClass.isAnnotationPresent( Constraint.class ), MESSAGES.annotationTypeMustBeAnnotatedWithConstraint() ); if ( definedConstraints.contains( annotationClass ) ) { // Fail fast for easy-to-detect definition conflicts; other conflicts are handled in ValidatorFactoryImpl throw LOG.getConstraintHasAlreadyBeenConfiguredViaProgrammaticApiException( annotationClass ); } ConstraintDefinitionContextImpl<A> constraintContext = new ConstraintDefinitionContextImpl<>( this, annotationClass ); constraintContexts.add( constraintContext ); definedConstraints.add( annotationClass ); return constraintContext; }
@Override public PropertyConstraintMappingContext property(String property, ElementType elementType) { Contracts.assertNotNull( property, "The property name must not be null." ); Contracts.assertNotNull( elementType, "The element type must not be null." ); Contracts.assertNotEmpty( property, MESSAGES.propertyNameMustNotBeEmpty() ); Member member = getMember( beanClass, property, elementType ); if ( member == null || member.getDeclaringClass() != beanClass ) { throw log.getUnableToFindPropertyWithAccessException( beanClass, property, elementType ); } if ( configuredMembers.contains( member ) ) { throw log.getPropertyHasAlreadyBeConfiguredViaProgrammaticApiException( beanClass, property ); } PropertyConstraintMappingContextImpl context = new PropertyConstraintMappingContextImpl( this, member ); configuredMembers.add( member ); propertyContexts.add( context ); return context; }
private void validateParameters(ScriptAssert constraintAnnotation) { Contracts.assertNotEmpty( constraintAnnotation.script(), MESSAGES.parameterMustNotBeEmpty( "script" ) ); Contracts.assertNotEmpty( constraintAnnotation.lang(), MESSAGES.parameterMustNotBeEmpty( "lang" ) ); Contracts.assertNotEmpty( constraintAnnotation.alias(), MESSAGES.parameterMustNotBeEmpty( "alias" ) ); } }
/** * Creates a locator that delivers a resource bundle merged from the given * list of source bundles. * * @param bundleNames A list with source bundle names. The returned bundle will * contain all keys from all source bundles. In case a key occurs * in multiple source bundles, the value will be taken from the * first bundle containing the key. * @param delegate A delegate resource bundle locator. The bundle returned by * this locator will be added to the aggregate bundle after all * source bundles. * @param classLoader The classloader to use for loading the bundle. * @since 5.2 */ public AggregateResourceBundleLocator(List<String> bundleNames, ResourceBundleLocator delegate, ClassLoader classLoader) { super( delegate ); Contracts.assertValueNotNull( bundleNames, "bundleNames" ); this.bundleNames = CollectionHelper.toImmutableList( bundleNames ); this.classLoader = classLoader; }
/** * Used to register the method validation interceptor binding annotation. * * @param beforeBeanDiscoveryEvent event fired before the bean discovery process starts * @param beanManager the bean manager. */ public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscoveryEvent, final BeanManager beanManager) { Contracts.assertNotNull( beforeBeanDiscoveryEvent, "The BeforeBeanDiscovery event cannot be null" ); Contracts.assertNotNull( beanManager, "The BeanManager cannot be null" ); // Register the interceptor explicitly. This way, no beans.xml is needed AnnotatedType<ValidationInterceptor> annotatedType = beanManager.createAnnotatedType( ValidationInterceptor.class ); beforeBeanDiscoveryEvent.addAnnotatedType( annotatedType, ValidationInterceptor.class.getName() ); }
@Override public Class<?> getContainerClass() { Contracts.assertTrue( kind == ElementKind.BEAN || kind == ElementKind.PROPERTY || kind == ElementKind.CONTAINER_ELEMENT, "getContainerClass() may only be invoked for nodes of type ElementKind.BEAN, ElementKind.PROPERTY or ElementKind.CONTAINER_ELEMENT." ); if ( parent == null ) { return null; } return parent.containerClass; }
private void validateParameters(ParameterScriptAssert constraintAnnotation) { Contracts.assertNotEmpty( constraintAnnotation.script(), MESSAGES.parameterMustNotBeEmpty( "script" ) ); Contracts.assertNotEmpty( constraintAnnotation.lang(), MESSAGES.parameterMustNotBeEmpty( "lang" ) ); } }
Contracts.assertValueNotNull( subTypeMethod, "subTypeMethod" ); Contracts.assertValueNotNull( superTypeMethod, "superTypeMethod" );
/** * Watches the {@code ProcessBean} event in order to determine whether beans for {@code ValidatorFactory} and * {@code Validator} already have been registered by some other component. * * @param processBeanEvent event fired for each enabled bean. */ public void processBean(@Observes ProcessBean<?> processBeanEvent) { Contracts.assertNotNull( processBeanEvent, "The ProcessBean event cannot be null" ); Bean<?> bean = processBeanEvent.getBean(); if ( bean.getTypes().contains( ValidatorFactory.class ) || bean instanceof ValidatorFactoryBean ) { if ( bean.getQualifiers().contains( defaultQualifier ) ) { defaultValidatorFactoryBean = bean; } if ( bean.getQualifiers().contains( hibernateValidatorQualifier ) ) { hibernateValidatorFactoryBean = bean; } } else if ( bean.getTypes().contains( Validator.class ) || bean instanceof ValidatorBean ) { if ( bean.getQualifiers().contains( defaultQualifier ) ) { defaultValidatorBean = bean; } if ( bean.getQualifiers().contains( hibernateValidatorQualifier ) ) { hibernateValidatorBean = bean; } } }
@Override public int getParameterIndex() { Contracts.assertTrue( kind == ElementKind.PARAMETER, "getParameterIndex() may only be invoked for nodes of type ElementKind.PARAMETER." ); return parameterIndex.intValue(); }
private void validateParameters(ScriptAssert constraintAnnotation) { Contracts.assertNotEmpty( constraintAnnotation.script(), MESSAGES.parameterMustNotBeEmpty( "script" ) ); Contracts.assertNotEmpty( constraintAnnotation.lang(), MESSAGES.parameterMustNotBeEmpty( "lang" ) ); Contracts.assertNotEmpty( constraintAnnotation.alias(), MESSAGES.parameterMustNotBeEmpty( "alias" ) ); } }
Contracts.assertValueNotNull( subTypeMethod, "subTypeMethod" ); Contracts.assertValueNotNull( superTypeMethod, "superTypeMethod" );
/** * Get a list of all methods which the given class declares, implements, * overrides or inherits. Methods are added by adding first all methods of * the class itself and its implemented interfaces, then the super class and * its interfaces, etc. * * @param clazz the class for which to retrieve the methods * * @return set of all methods of the given class */ public static List<Method> getAllMethods(Class<?> clazz) { Contracts.assertNotNull( clazz ); List<Method> methods = newArrayList(); for ( Class<?> hierarchyClass : ClassHierarchyHelper.getHierarchy( clazz ) ) { Collections.addAll( methods, run( GetMethods.action( hierarchyClass ) ) ); } return methods; }
@Override public int getParameterIndex() { Contracts.assertTrue( kind == ElementKind.PARAMETER, "getParameterIndex() may only be invoked for nodes of ElementKind.PARAMETER." ); return parameterIndex.intValue(); }