@Override public Configuration<?> configure() { ValidationProviderResolver resolver = this.resolver == null ? getDefaultValidationProviderResolver() : this.resolver; validationProviders = resolver.getValidationProviders(); throw new ValidationException( "Unable to get available provider resolvers.", re ); config = resolver.getValidationProviders().get( 0 ).createGenericConfiguration( this ); throw new ValidationException( "Unable to instantiate Configuration.", re );
@Override protected FailureAnalysis analyze(Throwable rootFailure, ValidationException cause) { if (cause.getMessage().startsWith(MISSING_IMPLEMENTATION_MESSAGE)) { return new FailureAnalysis( "The Bean Validation API is on the classpath but no implementation" + " could be found", "Add an implementation, such as Hibernate Validator, to the" + " classpath", cause); } return null; }
@Override public final ValidationException getUnableToCreateAnnotationForConfiguredConstraintException(final RuntimeException e) { final ValidationException result = new ValidationException(String.format(getLoggingLocale(), getUnableToCreateAnnotationForConfiguredConstraintException$str()), e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String getUnableToFindPropertyWithAccessException = "HV000013: The class %1$s does not have a property '%2$s' with access %3$s.";
@Override public T run() { try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException | RuntimeException e) { throw new ValidationException( "Cannot instantiate provider type: " + clazz, e ); } } }
public T configure() { if ( validationProviderClass == null ) { throw new ValidationException( "builder is mandatory. Use Validation.byDefaultProvider() to use the generic provider discovery mechanism" ); GenericBootstrapImpl state = new GenericBootstrapImpl(); return provider.createSpecializedConfiguration( state ); state.providerResolver( resolver ); resolvers = resolver.getValidationProviders(); throw new ValidationException( "Unable to get available provider resolvers.", re ); if ( validationProviderClass.isAssignableFrom( provider.getClass() ) ) { ValidationProvider<T> specificProvider = validationProviderClass.cast( provider ); return specificProvider.createSpecializedConfiguration( state ); throw new ValidationException( "Unable to find provider: " + validationProviderClass );
public static boolean nullOrEmpty(String value) { return value == null || value.trim().equals("") ? true : false; } public void yourMethod(){ try{ //YourCode Here String fname=Fname.getText(); if(nullOrEmpty(fname)){ new throw ValidationException("First name should not be null."); } //YourCode Here }catch(ValidationException e){ System.err.println("Exception:"+e.getMessage()); } }
private ValidationProvider<?> findProvider() { if (providerClass != null) { for (ValidationProvider<?> provider : providerResolver .getValidationProviders()) { if (providerClass.isAssignableFrom(provider.getClass())) { return provider; } } throw new ValidationException( "Unable to find suitable provider: " + providerClass); } else { List<ValidationProvider<?>> providers = providerResolver.getValidationProviders(); return providers.get(0); } }
@Override public final ValidationException getExceptionDuringIsValidCallException(final RuntimeException e) { final ValidationException result = new ValidationException(String.format(getLoggingLocale(), getExceptionDuringIsValidCallException$str()), e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String getConstraintValidatorFactoryMustNotReturnNullException = "HV000029: Constraint factory returned null when trying to create instance of %s.";
@Override @SuppressWarnings("unchecked") public <T> T unwrap(@Nullable Class<T> type) { if (type == null || !ValidatorFactory.class.isAssignableFrom(type)) { try { return super.unwrap(type); } catch (ValidationException ex) { // ignore - we'll try ValidatorFactory unwrapping next } } if (this.validatorFactory != null) { try { return this.validatorFactory.unwrap(type); } catch (ValidationException ex) { // ignore if just being asked for ValidatorFactory if (ValidatorFactory.class == type) { return (T) this.validatorFactory; } throw ex; } } throw new ValidationException("Cannot unwrap to " + type); }
public T configure() { if (providerClass == null) throw new ValidationException("No resolver provided"); // create a default resolver if not supplied by providerResolver() GenericBootstrapImpl impl = new GenericBootstrapImpl(); if ( vpResolver == null ) vpResolver = impl.getDefaultValidationProviderResolver(); else impl.providerResolver(vpResolver); // check each provider discovered by the resolver for (ValidationProvider<?> vProvider : vpResolver.getValidationProviders()) { if (providerClass.isAssignableFrom(vProvider.getClass())) { // Create a ValidationProvider<T> from the above bootstrap impl // and configurationType return providerClass.cast(vProvider).createSpecializedConfiguration(impl); } } // throw a Spec required exception throw new ValidationException("No provider found for " + providerClass); } }
@Test @SpecAssertion(section = Sections.VALIDATIONAPI_MESSAGE_CUSTOMRESOLUTION, id = "g") public void testExceptionDuringMessageInterpolationIsWrappedIntoValidationException() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); ExceptionThrowingMessageInterpolator interpolator = new ExceptionThrowingMessageInterpolator(); Validator validator = factory.usingContext().messageInterpolator( interpolator ).getValidator(); try { validator.validate( new TestBeanWithPropertyConstraint( "Bob" ) ); fail( "Expected exception wasn't thrown." ); } catch ( ValidationException ve ) { assertEquals( ve.getCause(), interpolator.exception ); } }
@Override public final ValidationException getUnableToInstantiateMessageInterpolatorClassException(final String messageInterpolatorClassName, final Exception e) { final ValidationException result = new ValidationException(String.format(getLoggingLocale(), getUnableToInstantiateMessageInterpolatorClassException$str(), messageInterpolatorClassName), e); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String getUnableToInstantiateTraversableResolverClassException = "HV000098: Unable to instantiate traversable resolver class %s.";
@Override public Configuration<?> configure() { ValidationProviderResolver aResolver = getDefaultValidationProviderResolver(); List<ValidationProvider<?>> resolvers; try { resolvers = aResolver.getValidationProviders(); } catch (RuntimeException re) { throw new ValidationException( "Unable to get available provider resolvers.", re); } if (resolvers.size() == 0) { // FIXME looks like an assertion error almost throw new ValidationException("Unable to find a default provider"); } Configuration<?> config; try { config = aResolver.getValidationProviders().get(0).createGenericConfiguration( this); } catch (RuntimeException re) { throw new ValidationException("Unable to instantiate Configuration.", re); } return config; }
public PredicateDefinition(String text) { int eqIdx = text.indexOf('='); if (eqIdx <= 0) { throw new ValidationException("Unable to parse PredicateDefinition text '" + text + "'" + ", must be of the form name=value"); } setName(text.substring(0, eqIdx)); String[] args = tokenizeToStringArray(text.substring(eqIdx+1), ","); for (int i=0; i < args.length; i++) { this.args.put(NameUtils.generateName(i), args[i]); } }
public T configure() { if (providerClass == null) throw new ValidationException("No resolver provided"); // create a default resolver if not supplied by providerResolver() GenericBootstrapImpl impl = new GenericBootstrapImpl(); if ( vpResolver == null ) vpResolver = impl.getDefaultValidationProviderResolver(); else impl.providerResolver(vpResolver); // check each provider discovered by the resolver for (ValidationProvider<?> vProvider : vpResolver.getValidationProviders()) { if (providerClass.isAssignableFrom(vProvider.getClass())) { // Create a ValidationProvider<T> from the above bootstrap impl // and configurationType return providerClass.cast(vProvider).createSpecializedConfiguration(impl); } } // throw a Spec required exception throw new ValidationException("No provider found for " + providerClass); } }
private static ErrorResponse toErrorResponse(ValidationException ve) { if ( ve instanceof ConstraintViolationException ) { return constraintViolationExceptionToErrorResponse((ConstraintViolationException) ve); } else { ErrorResponse result = new ErrorResponse(); result.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); result.setMessage(ve.getMessage()); return result; } }
@Test(expected = ConstraintDeclarationException.class) public void shouldHandleMissingStartDate() throws Throwable { MissingStartDate obj = new MissingStartDate(); obj.end = new Date(); try { validator.validate(obj); } catch (ValidationException e) { throw e.getCause(); } }
@Override public final ValidationException getAttemptToSpecifyAnArrayWhereSingleValueIsExpectedException() { final ValidationException result = new ValidationException(String.format(getLoggingLocale(), getAttemptToSpecifyAnArrayWhereSingleValueIsExpectedException$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String getUnexpectedParameterValueException = "HV000109: Unexpected parameter value.";
public Configuration<?> configure() { ValidationProviderResolver resolv = vpResolver; try { if (resolv == null) resolv = getDefaultValidationProviderResolver(); return resolv.getValidationProviders().get(0).createGenericConfiguration(this); } catch (Exception e) { throw new ValidationException("Could not create Configuration.", e); } } }