public static BeanValidationException providerNotFound(String prefix, Throwable internalException) { BeanValidationException bve = new BeanValidationException(ExceptionMessageGenerator.buildMessage (BeanValidationException.class, PROVIDER_NOT_FOUND, new Object[]{prefix}), internalException); bve.setErrorCode(PROVIDER_NOT_FOUND); return bve; }
@Override public void marshal(Object object, File file) throws JAXBException { try { FileOutputStream outputStream = new FileOutputStream(file); try { marshal(object, outputStream); // link to the other one } finally { outputStream.close(); } } catch (BeanValidationException bve) { throw new MarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve); } catch (Exception ex) { throw new MarshalException(ex); } }
/** * Lazy getter for SAX parser. */ private SAXParser getSaxParser() { if (saxParser == null) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); saxParser = factory.newSAXParser(); } catch (ParserConfigurationException | SAXException e) { String msg = "ValidationXMLReader initialization failed. Exception: " + e.getMessage(); LOGGER.severe(msg); throw new BeanValidationException(msg, e); } } return saxParser; }
/** * INTERNAL: * * Builds ConstraintViolationException with constraintViolations, but no message. * Builds BeanValidationException with fully descriptive message, containing * the ConstraintViolationException. * * @return BeanValidationException, containing ConstraintViolationException. */ @SuppressWarnings({"RedundantCast", "unchecked"}) private BeanValidationException buildConstraintViolationException() { ConstraintViolationException cve = new ConstraintViolationException( (Set<ConstraintViolation<Object>>) /* Do not remove the cast. */ constraintViolations); return BeanValidationException.constraintViolation(createConstraintViolationExceptionArgs(), cve); }
break; default: throw BeanValidationException.illegalValidationMode(prefix, beanValidationMode.toString());
throw BeanValidationException.providerNotFound(prefix, ve); } else { // mode AUTO stopSearchingForValidator = true; // Will not try to initialize validator on next tries.
if (property.isNotNullAnnotated()) throw BeanValidationException.notNullAndNillable(property.getPropertyName()); element.setNillable(true);
/** * Lazy getter for SAX parser. */ private SAXParser getSaxParser() { if (saxParser == null) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); saxParser = factory.newSAXParser(); } catch (ParserConfigurationException | SAXException e) { String msg = "ValidationXMLReader initialization failed. Exception: " + e.getMessage(); LOGGER.severe(msg); throw new BeanValidationException(msg, e); } } return saxParser; }
/** * INTERNAL: * * Builds ConstraintViolationException with constraintViolations, but no message. * Builds BeanValidationException with fully descriptive message, containing * the ConstraintViolationException. * * @return BeanValidationException, containing ConstraintViolationException. */ @SuppressWarnings({"RedundantCast", "unchecked"}) private BeanValidationException buildConstraintViolationException() { ConstraintViolationException cve = new ConstraintViolationException( (Set<ConstraintViolation<Object>>) /* Do not remove the cast. */ constraintViolations); return BeanValidationException.constraintViolation(createConstraintViolationExceptionArgs(), cve); }
break; default: throw BeanValidationException.illegalValidationMode(prefix, beanValidationMode.toString());
throw BeanValidationException.providerNotFound(prefix, ve); } else { // mode AUTO stopSearchingForValidator = true; // Will not try to initialize validator on next tries.
if (property.isNotNullAnnotated()) throw BeanValidationException.notNullAndNillable(property.getPropertyName()); element.setNillable(true);
public void marshal(Object object, File file) throws JAXBException { try { FileOutputStream outputStream = new FileOutputStream(file); try { marshal(object, outputStream); // link to the other one } finally { outputStream.close(); } } catch (BeanValidationException bve) { throw new MarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve); } catch (Exception ex) { throw new MarshalException(ex); } }
public static BeanValidationException constraintViolation(Object[] args, Throwable internalException) { BeanValidationException bve = new BeanValidationException(ExceptionMessageGenerator.buildMessage (BeanValidationException.class, CONSTRAINT_VIOLATION, args), internalException); bve.setErrorCode(CONSTRAINT_VIOLATION); return bve; }
/** * Lazy getter for SAX parser. */ private SAXParser getSaxParser() { if (saxParser == null) { try { SAXParserFactory factory = XMLHelper.createParserFactory(false); saxParser = factory.newSAXParser(); } catch (ParserConfigurationException | SAXException e) { String msg = "ValidationXMLReader initialization failed. Exception: " + e.getMessage(); LOGGER.severe(msg); throw new BeanValidationException(msg, e); } } return saxParser; }
@Override public Object unmarshal(Source source) throws JAXBException { try { Object value = xmlUnmarshaller.unmarshal(source); return validateAndTransformIfRequired(value); // xml bindings + object } catch (XMLMarshalException xmlMarshalException) { throw handleXMLMarshalException(xmlMarshalException); } catch (BeanValidationException bve) { throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve); } }
public static BeanValidationException illegalValidationMode(String prefix, String modeName) { BeanValidationException bve = new BeanValidationException(ExceptionMessageGenerator.buildMessage (BeanValidationException.class, ILLEGAL_VALIDATION_MODE, new Object[]{prefix, modeName})); bve.setErrorCode(ILLEGAL_VALIDATION_MODE); return bve; }
@Override public Object unmarshal(Node node) throws JAXBException { try { Object value = xmlUnmarshaller.unmarshal(node); return validateAndTransformIfRequired(value); // xml bindings + object } catch (XMLMarshalException xmlMarshalException) { throw handleXMLMarshalException(xmlMarshalException); } catch (BeanValidationException bve) { throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve); } }
public static BeanValidationException providerNotFound(String prefix, Throwable internalException) { BeanValidationException bve = new BeanValidationException(ExceptionMessageGenerator.buildMessage (BeanValidationException.class, PROVIDER_NOT_FOUND, new Object[]{prefix}), internalException); bve.setErrorCode(PROVIDER_NOT_FOUND); return bve; }
@Override public Object unmarshal(File file) throws JAXBException { try { Object value = xmlUnmarshaller.unmarshal(file); return validateAndTransformIfRequired(value); // xml object } catch (XMLMarshalException xmlMarshalException) { throw handleXMLMarshalException(xmlMarshalException); } catch (BeanValidationException bve) { throw new UnmarshalException(bve.getMessage(), String.valueOf(bve.getErrorCode()), bve); } }