/** * Used to validate the case when the Bean Validation API is not available. * * @param modes The requested validation modes. */ private void validateMissingBeanValidationApi(Set<ValidationMode> modes) { if ( modes.contains( ValidationMode.CALLBACK ) ) { throw new IntegrationException( "Bean Validation API was not available, but 'callback' validation was requested" ); } if ( modes.contains( ValidationMode.DDL ) ) { throw new IntegrationException( "Bean Validation API was not available, but 'ddl' validation was requested" ); } }
/** * Used to validate a supplied ValidatorFactory instance as being castable to ValidatorFactory. * * @param object The supplied ValidatorFactory instance. */ @SuppressWarnings( {"UnusedDeclaration"}) public static void validateSuppliedFactory(Object object) { if ( ! ValidatorFactory.class.isInstance( object ) ) { throw new IntegrationException( "Given object was not an instance of " + ValidatorFactory.class.getName() + "[" + object.getClass().getName() + "]" ); } }
private static ValidatorFactory resolveProvidedFactory(SessionFactoryOptions options) { final Object validatorFactoryReference = options.getValidatorFactoryReference(); if ( validatorFactoryReference == null ) { return null; } try { return ValidatorFactory.class.cast( validatorFactoryReference ); } catch ( ClassCastException e ) { throw new IntegrationException( String.format( Locale.ENGLISH, "ValidatorFactory reference (provided via %s) was not castable to %s : %s", SessionFactoryOptions.class.getName(), ValidatorFactory.class.getName(), validatorFactoryReference.getClass().getName() ) ); } }
@SuppressWarnings("UnusedDeclaration") public static void activate(ActivationContext activationContext) { final ValidatorFactory factory; try { factory = getValidatorFactory( activationContext ); } catch (IntegrationException e) { if ( activationContext.getValidationModes().contains( ValidationMode.CALLBACK ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'callback' validation was requested", e ); } if ( activationContext.getValidationModes().contains( ValidationMode.DDL ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'ddl' validation was requested", e ); } LOG.debug( "Unable to acquire Bean Validation ValidatorFactory, skipping activation" ); return; } applyRelationalConstraints( factory, activationContext ); applyCallbackListeners( factory, activationContext ); }
throw ( (HibernateException) e.getTargetException() ); throw new IntegrationException( "Error activating Bean Validation integration", e.getTargetException() ); throw new IntegrationException( "Error activating Bean Validation integration", e );
private static ValidatorFactory getValidatorFactory(ActivationContext activationContext) { // IMPL NOTE : We can either be provided a ValidatorFactory or make one. We can be provided // a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory in the following order: // 1) Look into SessionFactoryOptions.getValidatorFactoryReference() // 2) Look into ConfigurationService // 3) build a new ValidatorFactory // 1 - look in SessionFactoryOptions.getValidatorFactoryReference() ValidatorFactory factory = resolveProvidedFactory( activationContext.getSessionFactory().getSessionFactoryOptions() ); if ( factory != null ) { return factory; } // 2 - look in ConfigurationService factory = resolveProvidedFactory( activationContext.getServiceRegistry().getService( ConfigurationService.class ) ); if ( factory != null ) { return factory; } // 3 - build our own try { return Validation.buildDefaultValidatorFactory(); } catch ( Exception e ) { throw new IntegrationException( "Unable to build the default ValidatorFactory", e ); } }
/** * Used to validate the case when the Bean Validation API is not available. * * @param modes The requested validation modes. */ private void validateMissingBeanValidationApi(Set<ValidationMode> modes) { if ( modes.contains( ValidationMode.CALLBACK ) ) { throw new IntegrationException( "Bean Validation API was not available, but 'callback' validation was requested" ); } if ( modes.contains( ValidationMode.DDL ) ) { throw new IntegrationException( "Bean Validation API was not available, but 'ddl' validation was requested" ); } }
/** * Used to validate a supplied ValidatorFactory instance as being castable to ValidatorFactory. * * @param object The supplied ValidatorFactory instance. */ @SuppressWarnings( {"UnusedDeclaration"}) public static void validateSuppliedFactory(Object object) { if ( ! ValidatorFactory.class.isInstance( object ) ) { throw new IntegrationException( "Given object was not an instance of " + ValidatorFactory.class.getName() + "[" + object.getClass().getName() + "]" ); } }
private static ValidatorFactory resolveProvidedFactory(SessionFactoryOptions options) { final Object validatorFactoryReference = options.getValidatorFactoryReference(); if ( validatorFactoryReference == null ) { return null; } try { return ValidatorFactory.class.cast( validatorFactoryReference ); } catch ( ClassCastException e ) { throw new IntegrationException( String.format( Locale.ENGLISH, "ValidatorFactory reference (provided via %s) was not castable to %s : %s", SessionFactoryOptions.class.getName(), ValidatorFactory.class.getName(), validatorFactoryReference.getClass().getName() ) ); } }
@SuppressWarnings("UnusedDeclaration") public static void activate(ActivationContext activationContext) { final ValidatorFactory factory; try { factory = getValidatorFactory( activationContext ); } catch (IntegrationException e) { if ( activationContext.getValidationModes().contains( ValidationMode.CALLBACK ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'callback' validation was requested", e ); } if ( activationContext.getValidationModes().contains( ValidationMode.DDL ) ) { throw new IntegrationException( "Bean Validation provider was not available, but 'ddl' validation was requested", e ); } LOG.debug( "Unable to acquire Bean Validation ValidatorFactory, skipping activation" ); return; } applyRelationalConstraints( factory, activationContext ); applyCallbackListeners( factory, activationContext ); }
throw ( (HibernateException) e.getTargetException() ); throw new IntegrationException( "Error activating Bean Validation integration", e.getTargetException() ); throw new IntegrationException( "Error activating Bean Validation integration", e );
private static ValidatorFactory getValidatorFactory(ActivationContext activationContext) { // IMPL NOTE : We can either be provided a ValidatorFactory or make one. We can be provided // a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory in the following order: // 1) Look into SessionFactoryOptions.getValidatorFactoryReference() // 2) Look into ConfigurationService // 3) build a new ValidatorFactory // 1 - look in SessionFactoryOptions.getValidatorFactoryReference() ValidatorFactory factory = resolveProvidedFactory( activationContext.getSessionFactory().getSessionFactoryOptions() ); if ( factory != null ) { return factory; } // 2 - look in ConfigurationService factory = resolveProvidedFactory( activationContext.getServiceRegistry().getService( ConfigurationService.class ) ); if ( factory != null ) { return factory; } // 3 - build our own try { return Validation.buildDefaultValidatorFactory(); } catch ( Exception e ) { throw new IntegrationException( "Unable to build the default ValidatorFactory", e ); } }