javax.xml.bind.ValidationException Java Examples

The following examples show how to use javax.xml.bind.ValidationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractDerivedCRS.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Invoked by JAXB after all elements have been unmarshalled. At this point we should have the
 * coordinate system (CS). The CS information is required by {@code createConversionFromBase(…)}
 * in order to create a {@link MathTransform} with correct axis swapping and unit conversions.
 */
private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) throws ValidationException {
    String property = "conversion";
    if (conversionFromBase != null) {
        final SingleCRS baseCRS = CC_Conversion.setBaseCRS(conversionFromBase, null);  // Clear the temporary value now.
        property = "coordinateSystem";
        if (super.getCoordinateSystem() != null) {
            property = "baseCRS";
            if (baseCRS != null) {
                conversionFromBase = createConversionFromBase(null, baseCRS, conversionFromBase);
                return;
            }
        }
    }
    /*
     * If we reach this point, we failed to update the conversion. The 'baseCRS' information will be lost
     * and call to 'getConversionFromBase()' will throw a ClassCastException if this instance is actually
     * a ProjectedCRS (because of the method overriding with return type covariance).
     */
    throw new ValidationException(Errors.format(Errors.Keys.MissingValueForProperty_1, property));
}
 
Example #2
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Convert the given {@code JAXBException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occurred
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
Example #3
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given {@code JAXBException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occured
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
Example #4
Source File: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Convert the given {@code JAXBException} to an appropriate exception
 * from the {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occurred
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
Example #5
Source File: SupplierValidator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #6
Source File: SupplierValidator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #7
Source File: SupplierValidator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #8
Source File: SupplierValidator.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #9
Source File: SupplierValidator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #10
Source File: SupplierValidator.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #11
Source File: SupplierValidator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #12
Source File: SupplierValidator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #13
Source File: SupplierValidator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #14
Source File: SupplierValidator.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #15
Source File: Validators.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
/**
 * 认证
 *
 * @param method    方法
 * @param target    目标对象
 * @param arguments 参数
 * @throws ValidationException
 */
public static void validate(final Method method, final Object target, final Object... arguments) throws
        ValidationException {
    if (method == null || target == null || arguments == null || arguments.length == 0) {
        return;
    }
    // 获取方法验证
    MethodValidation valid = getMethodValidation(method, target);
    if (valid != null && valid.validation != null) {
        Validator validator;
        // 遍历参数
        for (int i = 0; i < valid.types.length; i++) {
            if (valid.annotations[i] != null) {
                // 遍历声明
                for (Annotation annotation : valid.annotations[i]) {
                    // 获取验证器
                    validator = getValidator(annotation);
                    // 判断是否能验证
                    if (validator != null) {
                        // 验证
                        validator.validate(target, annotation,
                                new Validator.Value(valid.names[i], valid.types[i], arguments[i]));
                    }
                }
            }
        }
    }
}
 
Example #16
Source File: SupplierValidator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #17
Source File: Attributes.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static void validate(Iterable<AttributeDefinition> definition, AttributeMap attributes) throws ValidationException {
Set<AttributeKey<?>> missing = new HashSet<>();
  for(AttributeDefinition attribute: definition) {
  	if(attribute.isOptional()) {
  		continue;
  	}
  	if(attributes.containsKey(attribute.getKey())) {
  		continue;
  	}
  	missing.add(attribute.getKey());
  }
  if(!missing.isEmpty()) {
  	throw new ValidationException("Missing required attribute(s): " + missing);
  }
 }
 
Example #18
Source File: SupplierValidator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Validates the supplier.
 *
 * @param supplier - Supplier that needs to be validated.
 * @return true if supplier has passed validation check. False otherwise.
 */
public static boolean validate(Supplier<?> supplier) {
    for (Validate annotation
            : supplier.getClass().getAnnotationsByType(Validate.class)) {
        try {
            annotation.value().validate(supplier);
        } catch (ValidationException e) {
            System.out.println(annotation.description());
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
Example #19
Source File: FederationsAdminController.java    From waggle-dance with Apache License 2.0 4 votes vote down vote up
@ExceptionHandler(ValidationException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public ValidationError handleValidationException(HttpServletRequest req, ValidationException exception) {
  return ValidationError.builder().error(exception.getMessage()).build();
}