use of org.springframework.beans.InvalidPropertyException in project grails-core by grails.
the class ConstrainedPropertyBuilder method createNode.
@SuppressWarnings("rawtypes")
@Override
protected Object createNode(Object name, Map attributes) {
try {
String property = (String) name;
ConstrainedProperty cp;
if (constrainedProperties.containsKey(property)) {
cp = (ConstrainedProperty) constrainedProperties.get(property);
} else {
Class<?> propertyType = classPropertyFetcher.getPropertyType(property, true);
if (propertyType == null) {
throw new MissingMethodException(property, targetClass, new Object[] { attributes }, true);
}
cp = new ConstrainedProperty(targetClass, property, propertyType);
cp.setOrder(order++);
constrainedProperties.put(property, cp);
}
if (cp.getPropertyType() == null) {
if (!IMPORT_FROM_CONSTRAINT.equals(name)) {
GrailsUtil.warn("Property [" + cp.getPropertyName() + "] not found in domain class " + targetClass.getName() + "; cannot apply constraints: " + attributes);
}
return cp;
}
for (Object o : attributes.keySet()) {
String constraintName = (String) o;
final Object value = attributes.get(constraintName);
if (SHARED_CONSTRAINT.equals(constraintName)) {
if (value != null) {
sharedConstraints.put(property, value.toString());
}
continue;
}
if (cp.supportsContraint(constraintName)) {
cp.applyConstraint(constraintName, value);
} else {
if (ConstrainedProperty.hasRegisteredConstraint(constraintName)) {
// constraint is registered but doesn't support this property's type
GrailsUtil.warn("Property [" + cp.getPropertyName() + "] of domain class " + targetClass.getName() + " has type [" + cp.getPropertyType().getName() + "] and doesn't support constraint [" + constraintName + "]. This constraint will not be checked during validation.");
} else {
// in the case where the constraint is not supported we still retain meta data
// about the constraint in case its needed for other things
cp.addMetaConstraint(constraintName, value);
}
}
}
return cp;
} catch (InvalidPropertyException ipe) {
throw new MissingMethodException((String) name, targetClass, new Object[] { attributes });
}
}
use of org.springframework.beans.InvalidPropertyException in project com.revolsys.open by revolsys.
the class ScriptExecutorRunnable method getBeanExceptionCause.
private static Throwable getBeanExceptionCause(final BeanCreationException e) {
Throwable cause = e.getCause();
while (cause instanceof BeanCreationException || cause instanceof MethodInvocationException || cause instanceof PropertyAccessException || cause instanceof PropertyBatchUpdateException || cause instanceof InvalidPropertyException) {
Throwable newCause;
if (cause instanceof PropertyBatchUpdateException) {
final PropertyBatchUpdateException batchEx = (PropertyBatchUpdateException) cause;
newCause = batchEx.getPropertyAccessExceptions()[0];
} else {
newCause = cause.getCause();
}
if (newCause != null) {
cause = newCause;
} else {
return cause;
}
}
return cause;
}
use of org.springframework.beans.InvalidPropertyException in project com.revolsys.open by revolsys.
the class ScriptTool method getBeanExceptionCause.
private static Throwable getBeanExceptionCause(final BeanCreationException e) {
Throwable cause = e.getCause();
if (cause == null) {
return e;
}
while (cause instanceof BeanCreationException || cause instanceof MethodInvocationException || cause instanceof PropertyAccessException || cause instanceof PropertyBatchUpdateException || cause instanceof InvalidPropertyException) {
Throwable newCause;
if (cause instanceof PropertyBatchUpdateException) {
final PropertyBatchUpdateException batchEx = (PropertyBatchUpdateException) cause;
newCause = batchEx.getPropertyAccessExceptions()[0];
} else {
newCause = cause.getCause();
}
if (newCause != null) {
cause = newCause;
} else {
return cause;
}
}
return cause;
}
use of org.springframework.beans.InvalidPropertyException in project opennms by OpenNMS.
the class MockForeignSourceRepositoryTest method testBeanWrapperAccess.
/**
* This test ensures that the Spring Bean accessor classes work properly
* since our REST implementation uses bean access to update the values.
*/
@Test
public void testBeanWrapperAccess() throws Exception {
createRequisition();
Requisition r = m_foreignSourceRepository.getRequisition(m_defaultForeignSourceName);
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(r);
assertEquals("AC", wrapper.getPropertyValue("node[0].category[0].name"));
assertEquals("UK", wrapper.getPropertyValue("node[0].category[1].name"));
assertEquals("low", wrapper.getPropertyValue("node[0].category[2].name"));
try {
wrapper.getPropertyValue("node[1].category[0].name");
fail("Did not catch expected InvalidPropertyException exception");
} catch (InvalidPropertyException e) {
// Expected failure
}
assertEquals(0, ((RequisitionCategory[]) wrapper.getPropertyValue("node[1].category")).length);
wrapper.setPropertyValue("node[1].categories[0]", new RequisitionCategory("Hello world"));
wrapper.setPropertyValue("node[1].categories[1]", new RequisitionCategory("Hello again"));
assertEquals(2, ((RequisitionCategory[]) wrapper.getPropertyValue("node[1].category")).length);
}
use of org.springframework.beans.InvalidPropertyException in project disconf by knightliao.
the class MyExceptionHandler method resolveException.
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) {
LOG.warn(request.getRequestURI() + " ExceptionHandler FOUND. " + e.toString() + "\t" + e.getCause());
// PathVariable 出错
if (e instanceof TypeMismatchException) {
return getParamErrors((TypeMismatchException) e);
// Bean 参数无法映射错误
} else if (e instanceof InvalidPropertyException) {
return getParamErrors((InvalidPropertyException) e);
// @Valid 出错
} else if (e instanceof BindException) {
return ParamValidateUtils.getParamErrors((BindException) e);
// 业务校验处理
} else if (e instanceof FieldException) {
return getParamErrors((FieldException) e);
} else if (e instanceof DocumentNotFoundException) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
try {
FileUtils.closeWriter(response.getWriter());
} catch (IOException e1) {
e1.printStackTrace();
}
return null;
// 用户没有请求方法的访问权限
} else if (e instanceof AccessDeniedException) {
LOG.warn("details: " + ((AccessDeniedException) e).getErrorMessage());
return buildError("auth.access.denied", ErrorCode.ACCESS_NOAUTH_ERROR);
} else if (e instanceof HttpRequestMethodNotSupportedException) {
return buildError("syserror.httpmethod", ErrorCode.HttpRequestMethodNotSupportedException);
} else if (e instanceof MissingServletRequestParameterException) {
return buildError("syserror.param.miss", ErrorCode.MissingServletRequestParameterException);
} else if (e instanceof GlobalExceptionAware) {
LOG.error("details: ", e);
GlobalExceptionAware g = (GlobalExceptionAware) e;
return buildError(g.getErrorMessage(), g.getErrorCode());
} else {
LOG.warn("details: ", e);
return buildError("syserror.inner", ErrorCode.GLOBAL_ERROR);
}
}
Aggregations