Java 类org.hibernate.validator.InvalidStateException 实例源码
项目:spring-rich-client
文件:HibernateExceptionHandlerCommand.java
@Override
protected void doExecuteCommand() {
List<InvalidValue> invalidExceptions = new ArrayList<InvalidValue>(5);
MyBean myBean = new MyBean();
invalidExceptions.add(new InvalidValue("first invalid message", MyBean.class, "firstProperty",
"first invalid value", myBean));
invalidExceptions.add(new InvalidValue("second invalid message", MyBean.class, "secondProperty",
"second invalid value", myBean));
invalidExceptions.add(new InvalidValue("third invalid message", MyBean.class, "thirdProperty",
"third invalid value", myBean));
invalidExceptions.add(new InvalidValue("fourth invalid message", MyBean.class, "fourthProperty",
"fourth invalid value", myBean));
invalidExceptions.add(new InvalidValue("fifth invalid message", MyBean.class, "fifthProperty",
"fifth invalid value", myBean));
throw new InvalidStateException(invalidExceptions.toArray(new InvalidValue[] {}));
}
项目:spring-richclient
文件:HibernateExceptionHandlerCommand.java
@Override
protected void doExecuteCommand() {
List<InvalidValue> invalidExceptions = new ArrayList<InvalidValue>(5);
MyBean myBean = new MyBean();
invalidExceptions.add(new InvalidValue("first invalid message", MyBean.class, "firstProperty",
"first invalid value", myBean));
invalidExceptions.add(new InvalidValue("second invalid message", MyBean.class, "secondProperty",
"second invalid value", myBean));
invalidExceptions.add(new InvalidValue("third invalid message", MyBean.class, "thirdProperty",
"third invalid value", myBean));
invalidExceptions.add(new InvalidValue("fourth invalid message", MyBean.class, "fourthProperty",
"fourth invalid value", myBean));
invalidExceptions.add(new InvalidValue("fifth invalid message", MyBean.class, "fifthProperty",
"fifth invalid value", myBean));
throw new InvalidStateException(invalidExceptions.toArray(new InvalidValue[] {}));
}
项目:caarray
文件:FileUploadUtils.java
/**
* Uploads a file chunk to a project.
* @param project the project the file is being uploaded in to.
* @param wrapper FileWrapper for the chunk being uploaded.
*/
private void addFileChunk(Project project, FileWrapper wrapper) throws InvalidFileException {
File file = wrapper.getFile();
String fileName = wrapper.getFileName();
try {
if (!checkDuplicateFilename(project, fileName)) {
CaArrayFile caArrayFile = getProjectManagementService().addFileChunk(project, file, fileName,
wrapper.getTotalFileSize());
if (caArrayFile.getFileStatus().equals(FileStatus.UPLOADED)) {
handleLastChunk(project, caArrayFile, fileName, wrapper.isCompressed());
} else {
result.setPartialUpload(true);
}
}
} catch (final Exception e) {
if (e.getCause() instanceof InvalidStateException) {
result.addConflictingFile(fileName);
} else {
throw new InvalidFileException(fileName, "errors.addingFile", result,
"Unable to add file tp persistent store", e);
}
}
}
项目:caarray
文件:FileUploadUtils.java
private void addEntryToProject(Project project, ZipInputStream input, String entryName)
throws InvalidFileException {
LOG.info("Adding entry " + entryName + " to project " + project.getId());
try {
final ProjectManagementService pms = getProjectManagementService();
pms.addFile(project, input, entryName);
result.addSuccessfulFile(entryName);
} catch (final Exception e) {
LOG.error("Error adding file", e);
if (e.getCause() instanceof InvalidStateException) {
result.addConflictingFile(entryName);
} else {
throw new InvalidFileException(entryName, ADDING_FILE_ERROR_KEY, result, ADDING_FILE_ERROR_MESSAGE, e);
}
}
}
项目:hql-builder
文件:HibernateValidationConverter.java
/**
* @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
*/
@Override
public ValidationException convert(Exception e) {
org.hibernate.validator.InvalidStateException ex = (InvalidStateException) e;
List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
for (org.hibernate.validator.InvalidValue iv : ex.getInvalidValues()) {
ivs.add(new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(iv.getBean(), iv.getBeanClass(), iv.getMessage(), iv
.getPropertyName(), iv.getPropertyPath(), iv.getRootBean(), iv.getValue()));
}
return new ValidationException(ex.getMessage(), ivs);
}
项目:hql-builder
文件:HibernateValidationConverter.java
/**
* @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
*/
@Override
public ValidationException convert(Exception e) {
org.hibernate.validator.InvalidStateException ex = (InvalidStateException) e;
List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
for (org.hibernate.validator.InvalidValue iv : ex.getInvalidValues()) {
ivs.add(new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(iv.getBean(), iv.getBeanClass(), iv.getMessage(), iv
.getPropertyName(), iv.getPropertyPath(), iv.getRootBean(), iv.getValue()));
}
return new ValidationException(ex.getMessage(), ivs);
}
项目:hql-builder
文件:HibernateValidationConverter.java
/**
* @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
*/
@Override
public ValidationException convert(Exception e) {
org.hibernate.validator.InvalidStateException ex = (InvalidStateException) e;
List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
for (org.hibernate.validator.InvalidValue iv : ex.getInvalidValues()) {
ivs.add(new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(iv.getBean(), iv.getBeanClass(), iv.getMessage(), iv
.getPropertyName(), iv.getPropertyPath(), iv.getRootBean(), iv.getValue()));
}
return new ValidationException(ex.getMessage(), ivs);
}
项目:hql-builder
文件:HibernateValidationConverter.java
/**
* @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
*/
@Override
public ValidationException convert(Exception e) {
org.hibernate.validator.InvalidStateException ex = (InvalidStateException) e;
List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
for (org.hibernate.validator.InvalidValue iv : ex.getInvalidValues()) {
ivs.add(new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(iv.getBean(), iv.getBeanClass(), iv.getMessage(), iv
.getPropertyName(), iv.getPropertyPath(), iv.getRootBean(), iv.getValue()));
}
return new ValidationException(ex.getMessage(), ivs);
}
项目:spring-rich-client
文件:HibernateValidatorDialogExceptionHandler.java
public Object createExceptionContent(Throwable throwable) {
if (!(throwable instanceof InvalidStateException)) {
String ILLEGAL_THROWABLE_ARGUMENT
= "Could not handle exception: throwable is not an InvalidStateException:\n"
+ throwable.getClass().getName();
logger.error(ILLEGAL_THROWABLE_ARGUMENT);
return ILLEGAL_THROWABLE_ARGUMENT;
}
InvalidStateException invalidStateException = (InvalidStateException) throwable;
String explanation = messageSourceAccessor.getMessage(EXPLANATION_KEY, EXPLANATION_KEY);
JPanel panel = new JPanel(new BorderLayout());
JLabel explanationLabel = new JLabel(explanation);
panel.add(explanationLabel, BorderLayout.NORTH);
List<String> invalidValueMessageList = new ArrayList<String>();
for (InvalidValue invalidValue : invalidStateException.getInvalidValues()) {
StringBuffer messageBuffer = new StringBuffer();
String propertyName = invalidValue.getPropertyName();
messageBuffer.append(messageSourceAccessor.getMessage(propertyName + ".label", propertyName));
messageBuffer.append(" ");
messageBuffer.append(invalidValue.getMessage());
invalidValueMessageList.add(messageBuffer.toString());
}
JList invalidValuesJList = new JList(invalidValueMessageList.toArray());
JScrollPane invalidValuesScrollPane = new JScrollPane(invalidValuesJList,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(invalidValuesScrollPane, BorderLayout.CENTER);
return panel;
}
项目:spring-richclient
文件:HibernateValidatorDialogExceptionHandler.java
public Object createExceptionContent(Throwable throwable) {
if (!(throwable instanceof InvalidStateException)) {
String ILLEGAL_THROWABLE_ARGUMENT
= "Could not handle exception: throwable is not an InvalidStateException:\n"
+ throwable.getClass().getName();
logger.error(ILLEGAL_THROWABLE_ARGUMENT);
return ILLEGAL_THROWABLE_ARGUMENT;
}
InvalidStateException invalidStateException = (InvalidStateException) throwable;
String explanation = messageSourceAccessor.getMessage(EXPLANATION_KEY, EXPLANATION_KEY);
JPanel panel = new JPanel(new BorderLayout());
JLabel explanationLabel = new JLabel(explanation);
panel.add(explanationLabel, BorderLayout.NORTH);
List<String> invalidValueMessageList = new ArrayList<String>();
for (InvalidValue invalidValue : invalidStateException.getInvalidValues()) {
StringBuffer messageBuffer = new StringBuffer();
String propertyName = invalidValue.getPropertyName();
messageBuffer.append(messageSourceAccessor.getMessage(propertyName + ".label", propertyName));
messageBuffer.append(" ");
messageBuffer.append(invalidValue.getMessage());
invalidValueMessageList.add(messageBuffer.toString());
}
JList invalidValuesJList = new JList(invalidValueMessageList.toArray());
JScrollPane invalidValuesScrollPane = new JScrollPane(invalidValuesJList,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(invalidValuesScrollPane, BorderLayout.CENTER);
return panel;
}
项目:caarray
文件:FileUploadUtils.java
private void addUploadedFile(Project project, File file, String fileName) throws InvalidFileException {
try {
final ProjectManagementService pms = getProjectManagementService();
if (!checkAlreadyAdded(project.getFileNames(), fileName)) {
pms.addFile(project, file, fileName);
result.addSuccessfulFile(fileName);
}
} catch (Exception e) {
if (e.getCause() instanceof InvalidStateException) {
result.addConflictingFile(fileName);
} else {
throw new InvalidFileException(fileName, ADDING_FILE_ERROR_KEY, result, ADDING_FILE_ERROR_MESSAGE, e);
}
}
}
项目:caarray
文件:ArrayDesignServiceIntegrationTest.java
private ArrayDesign setupAndSaveDesign(File... designFiles) throws IllegalAccessException, InvalidDataFileException {
this.hibernateHelper.getCurrentSession().save(DUMMY_ORGANIZATION);
this.hibernateHelper.getCurrentSession().save(DUMMY_ORGANISM);
this.hibernateHelper.getCurrentSession().save(DUMMY_TERM);
this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAY_TYPE);
final ArrayDesign design = new ArrayDesign();
design.setName("DummyTestArrayDesign1");
design.setVersion("2.0");
design.setProvider(DUMMY_ORGANIZATION);
design.setLsidForEntity("authority:namespace:" + designFiles[0].getName());
design.getAssayTypes().add(DUMMY_ASSAY_TYPE);
final Set<AssayType> assayTypes = new TreeSet<AssayType>();
assayTypes.add(DUMMY_ASSAY_TYPE);
for (final File designFile : designFiles) {
design.addDesignFile(getCaArrayFile(designFile));
}
design.setTechnologyType(DUMMY_TERM);
design.setOrganism(DUMMY_ORGANISM);
try {
this.arrayDesignService.saveArrayDesign(design);
} catch (final InvalidStateException e) {
e.printStackTrace();
for (final InvalidValue iv : e.getInvalidValues()) {
System.out.println("Invalid value: " + iv);
}
}
return design;
}
项目:caarray
文件:AffymetrixArrayDesignServiceIntegrationTest.java
private ArrayDesign setupAndSaveDesign(File... designFiles) throws IllegalAccessException, InvalidDataFileException {
this.hibernateHelper.getCurrentSession().save(DUMMY_ORGANIZATION);
this.hibernateHelper.getCurrentSession().save(DUMMY_ORGANISM);
this.hibernateHelper.getCurrentSession().save(DUMMY_TERM);
this.hibernateHelper.getCurrentSession().save(DUMMY_ASSAY_TYPE);
final ArrayDesign design = new ArrayDesign();
design.setName("DummyTestArrayDesign1");
design.setVersion("2.0");
design.setProvider(DUMMY_ORGANIZATION);
design.setLsidForEntity("authority:namespace:" + designFiles[0].getName());
design.getAssayTypes().add(DUMMY_ASSAY_TYPE);
final Set<AssayType> assayTypes = new TreeSet<AssayType>();
assayTypes.add(DUMMY_ASSAY_TYPE);
for (final File designFile : designFiles) {
design.addDesignFile(getCaArrayFile(designFile));
}
design.setTechnologyType(DUMMY_TERM);
design.setOrganism(DUMMY_ORGANISM);
try {
this.arrayDesignService.saveArrayDesign(design);
} catch (final InvalidStateException e) {
e.printStackTrace();
for (final InvalidValue iv : e.getInvalidValues()) {
System.out.println("Invalid value: " + iv);
}
}
return design;
}
项目:hibernate-validator-pl
文件:ValidatorTestHelper.java
public static void assertTrueOrShowErrors(HumanBeing hb, ClassValidator<HumanBeing> cv, boolean shouldFail) {
Exception exc = null;
try {
cv.assertValid(hb);
} catch (InvalidStateException ise) {
exc = ise;
}
assertTrue(showErrMsg(hb, cv),(exc == null) == shouldFail);
}