Package javax.validation

Examples of javax.validation.ValidationException


  }

  private <A extends Annotation> Class<?> getAnnotationParameterType(Class<A> annotationClass, String name) {
    Method m = ReflectionHelper.getMethod( annotationClass, name );
    if ( m == null ) {
      throw new ValidationException( "Annotation of type " + annotationClass.getName() + " does not contain a parameter " + name + "." );
    }
    return m.getReturnType();
  }
View Full Code Here


    removeEmptyContentElements( elementType );

    boolean isArray = returnType.isArray();
    if ( !isArray ) {
      if ( elementType.getContent().size() != 1 ) {
        throw new ValidationException( "Attempt to specify an array where single value is expected." );
      }
      return getSingleValue( elementType.getContent().get( 0 ), returnType );
    }
    else {
      List<Object> values = newArrayList();
View Full Code Here

        @SuppressWarnings("unchecked")
        Class<Annotation> annotationClass = (Class<Annotation>) returnType;
        returnValue = createAnnotation( annotationType, annotationClass );
      }
      catch ( ClassCastException e ) {
        throw new ValidationException( "Unexpected parameter value", e );
      }
    }
    else {
      throw new ValidationException( "Unexpected parameter value" );
    }
    return returnValue;

  }
View Full Code Here

    if ( returnType.getName().equals( byte.class.getName() ) ) {
      try {
        returnValue = Byte.parseByte( value );
      }
      catch ( NumberFormatException e ) {
        throw new ValidationException( "Invalid byte format", e );
      }
    }
    else if ( returnType.getName().equals( short.class.getName() ) ) {
      try {
        returnValue = Short.parseShort( value );
      }
      catch ( NumberFormatException e ) {
        throw new ValidationException( "Invalid short format", e );
      }
    }
    else if ( returnType.getName().equals( int.class.getName() ) ) {
      try {
        returnValue = Integer.parseInt( value );
      }
      catch ( NumberFormatException e ) {
        throw new ValidationException( "Invalid int format", e );
      }
    }
    else if ( returnType.getName().equals( long.class.getName() ) ) {
      try {
        returnValue = Long.parseLong( value );
      }
      catch ( NumberFormatException e ) {
        throw new ValidationException( "Invalid long format", e );
      }
    }
    else if ( returnType.getName().equals( float.class.getName() ) ) {
      try {
        returnValue = Float.parseFloat( value );
      }
      catch ( NumberFormatException e ) {
        throw new ValidationException( "Invalid float format", e );
      }
    }
    else if ( returnType.getName().equals( double.class.getName() ) ) {
      try {
        returnValue = Double.parseDouble( value );
      }
      catch ( NumberFormatException e ) {
        throw new ValidationException( "Invalid double format", e );
      }
    }
    else if ( returnType.getName().equals( boolean.class.getName() ) ) {
      returnValue = Boolean.parseBoolean( value );
    }
    else if ( returnType.getName().equals( char.class.getName() ) ) {
      if ( value.length() != 1 ) {
        throw new ValidationException( "Invalid char value: " + value );
      }
      returnValue = value.charAt( 0 );
    }
    else if ( returnType.getName().equals( String.class.getName() ) ) {
      returnValue = value;
    }
    else if ( returnType.getName().equals( Class.class.getName() ) ) {
      returnValue = ReflectionHelper.loadClass( value, this.getClass() );
    }
    else {
      try {
        @SuppressWarnings("unchecked")
        Class<Enum> enumClass = (Class<Enum>) returnType;
        returnValue = Enum.valueOf( enumClass, value );
      }
      catch ( ClassCastException e ) {
        throw new ValidationException(
            "Invalid return type: " + returnType + ". Should be a enumeration type.", e
        );
      }
    }
    return returnValue;
View Full Code Here

  public T run() {
    try {
      return clazz.newInstance();
    }
    catch ( InstantiationException e ) {
      throw new ValidationException( "Unable to instantiate " + message + ": " + clazz, e );
    }
    catch ( IllegalAccessException e ) {
      throw new ValidationException( "Unable to instantiate " + clazz, e );
    }
    catch ( RuntimeException e ) {
      throw new ValidationException( "Unable to instantiate " + clazz, e );
    }
  }
View Full Code Here

    return returnValue;
  }

  private void checkNameIsValid(String name) {
    if ( MESSAGE_PARAM.equals( name ) || GROUPS_PARAM.equals( name ) ) {
      throw new ValidationException( MESSAGE_PARAM + ", " + GROUPS_PARAM + ", " + PAYLOAD_PARAM + " are reserved parameter names." );
    }
  }
View Full Code Here

    List<Class<? extends Payload>> payloadList = newArrayList();
    for ( String groupClass : payloadType.getValue() ) {
      Class<?> payload = getClass( groupClass, defaultPackage );
      if ( !Payload.class.isAssignableFrom( payload ) ) {
        throw new ValidationException( "Specified payload class " + payload.getName() + " does not implement javax.validation.Payload" );
      }
      else {
        payloadList.add( (Class<? extends Payload>) payload );
      }
    }
View Full Code Here

      constraintMappings = root.getValue();
    }
    catch ( JAXBException e ) {
      String msg = "Error parsing mapping file.";
      log.error( msg );
      throw new ValidationException( msg, e );
    }
    return constraintMappings;
  }
View Full Code Here

  public <T> T unwrap(Class<T> type) {
    if ( HibernateValidatorFactory.class.equals( type ) ) {
      return type.cast( this );
    }
    throw new ValidationException( "Type " + type + " not supported" );
  }
View Full Code Here

    A annotation;
    try {
      annotation = AnnotationFactory.create( annotationDescriptor );
    }
    catch ( RuntimeException e ) {
      throw new ValidationException(
          "Unable to create annotation for configured constraint: " + e.getMessage(), e
      );
    }
    return annotation;
  }
View Full Code Here

TOP

Related Classes of javax.validation.ValidationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.