Java 类org.springframework.beans.NotReadablePropertyException 实例源码

项目:kansalaisaloite    文件:LocalValidatorFactoryBeanFix.java   
@Override
protected void processConstraintViolations(Set<ConstraintViolation<Object>> violations, Errors errors) {
    for (ConstraintViolation<Object> violation : violations) {
        String field = violation.getPropertyPath().toString();
        FieldError fieldError = errors.getFieldError(field);
        if (fieldError == null || !fieldError.isBindingFailure()) {
            try {
                String errorCode = violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName();
                Object[] errorArgs = getArgumentsForConstraint(errors.getObjectName(), field, violation.getConstraintDescriptor());
                // NOTE: Super implementation of getInvalidValue() failed on a nested component. 
                // E.g. LocalizedString.fi returned LocalizedString instead of String as invalidValue
                errors.rejectValue(field, errorCode, errorArgs, violation.getMessage());
            }
            catch (NotReadablePropertyException ex) {
                throw new IllegalStateException("JSR-303 validated property '" + field +
                        "' does not have a corresponding accessor for Spring data binding - " +
                        "check your DataBinder's configuration (bean property versus direct field access)", ex);
            }
        }
    }
}
项目:spring-rich-client    文件:AbstractFormModelTests.java   
public void testGetValueModelFromPAS() {
    TestBean p = new TestBean();
    TestPropertyAccessStrategy tpas = new TestPropertyAccessStrategy(p);
    AbstractFormModel fm = getFormModel(tpas, true);
    ValueModel vm1 = fm.getValueModel("simpleProperty");
    assertEquals(1, tpas.numValueModelRequests());
    assertEquals("simpleProperty", tpas.lastRequestedValueModel());
    ValueModel vm2 = fm.getValueModel("simpleProperty");
    assertEquals(vm1, vm2);
    assertEquals(1, tpas.numValueModelRequests());

    try {
        fm.getValueModel("iDontExist");
        fail("should't be able to get value model for invalid property");
    }
    catch (NotReadablePropertyException e) {
        // exprected
    }
}
项目:spring-rich-client    文件:AbstractMemberPropertyAccessor.java   
protected NotReadablePropertyException createNotReadablePropertyException(String propertyName, Exception e) {
    if (JdkVersion.isAtLeastJava14()) {
        NotReadablePropertyException beanException = new NotReadablePropertyException(getTargetClass(),
                propertyName);
        beanException.initCause(e);
        return beanException;
    }
    else {
        ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
        PrintWriter stackTraceWriter = new PrintWriter(stackTrace);
        e.printStackTrace(stackTraceWriter);
        stackTraceWriter.close();
        return new NotReadablePropertyException(getTargetClass(), propertyName,
                new String(stackTrace.toByteArray()));
    }
}
项目:spring-richclient    文件:AbstractFormModelTests.java   
public void testGetValueModelFromPAS() {
    TestBean p = new TestBean();
    TestPropertyAccessStrategy tpas = new TestPropertyAccessStrategy(p);
    AbstractFormModel fm = getFormModel(tpas, true);
    ValueModel vm1 = fm.getValueModel("simpleProperty");
    assertEquals(1, tpas.numValueModelRequests());
    assertEquals("simpleProperty", tpas.lastRequestedValueModel());
    ValueModel vm2 = fm.getValueModel("simpleProperty");
    assertEquals(vm1, vm2);
    assertEquals(1, tpas.numValueModelRequests());

    try {
        fm.getValueModel("iDontExist");
        fail("should't be able to get value model for invalid property");
    }
    catch (NotReadablePropertyException e) {
        // exprected
    }
}
项目:spring-richclient    文件:AbstractMemberPropertyAccessor.java   
protected NotReadablePropertyException createNotReadablePropertyException(String propertyName, Exception e) {
    if (JdkVersion.isAtLeastJava14()) {
        NotReadablePropertyException beanException = new NotReadablePropertyException(getTargetClass(),
                propertyName);
        beanException.initCause(e);
        return beanException;
    }
    else {
        ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
        PrintWriter stackTraceWriter = new PrintWriter(stackTrace);
        e.printStackTrace(stackTraceWriter);
        stackTraceWriter.close();
        return new NotReadablePropertyException(getTargetClass(), propertyName,
                new String(stackTrace.toByteArray()));
    }
}
项目:lams    文件:BeanPropertySqlParameterSource.java   
@Override
public Object getValue(String paramName) throws IllegalArgumentException {
    try {
        return this.beanWrapper.getPropertyValue(paramName);
    }
    catch (NotReadablePropertyException ex) {
        throw new IllegalArgumentException(ex.getMessage());
    }
}
项目:spring4-understanding    文件:BeanPropertySqlParameterSource.java   
@Override
public Object getValue(String paramName) throws IllegalArgumentException {
    try {
        return this.beanWrapper.getPropertyValue(paramName);
    }
    catch (NotReadablePropertyException ex) {
        throw new IllegalArgumentException(ex.getMessage());
    }
}
项目:kc-rice    文件:UifViewBeanWrapper.java   
/**
 * Checks whether the given property is secure.
 *
 * @param wrappedClass class the property is associated with
 * @param propertyPath path to the property
 * @return boolean true if the property is secure, false if not
 */
protected boolean isSecure(Class<?> wrappedClass, String propertyPath) {
    if (KRADUtils.isSecure(propertyPath, wrappedClass)) {
        return true;
    }

    // since this is part of a set, we want to make sure nested paths grow
    setAutoGrowNestedPaths(true);

    BeanWrapperImpl beanWrapper;
    try {
        beanWrapper = getBeanWrapperForPropertyPath(propertyPath);
    } catch (NotReadablePropertyException | NullValueInNestedPathException e) {
        LOG.debug("Bean wrapper was not found for " + propertyPath
                + ", but since it cannot be accessed it will not be set as secure.", e);
        return false;
    }

    if (org.apache.commons.lang.StringUtils.isNotBlank(beanWrapper.getNestedPath())) {
        PropertyTokenHolder tokens = getPropertyNameTokens(propertyPath);
        String nestedPropertyPath = org.apache.commons.lang.StringUtils.removeStart(tokens.canonicalName,
                beanWrapper.getNestedPath());

        return isSecure(beanWrapper.getWrappedClass(), nestedPropertyPath);
    }

    return false;
}
项目:class-guard    文件:BeanPropertySqlParameterSource.java   
public Object getValue(String paramName) throws IllegalArgumentException {
    try {
        return this.beanWrapper.getPropertyValue(paramName);
    }
    catch (NotReadablePropertyException ex) {
        throw new IllegalArgumentException(ex.getMessage());
    }
}
项目:rice    文件:UifViewBeanWrapper.java   
/**
 * Checks whether the given property is secure.
 *
 * @param wrappedClass class the property is associated with
 * @param propertyPath path to the property
 * @return boolean true if the property is secure, false if not
 */
protected boolean isSecure(Class<?> wrappedClass, String propertyPath) {
    if (KRADUtils.isSecure(propertyPath, wrappedClass)) {
        return true;
    }

    // since this is part of a set, we want to make sure nested paths grow
    setAutoGrowNestedPaths(true);

    BeanWrapperImpl beanWrapper;
    try {
        beanWrapper = getBeanWrapperForPropertyPath(propertyPath);
    } catch (NotReadablePropertyException | NullValueInNestedPathException e) {
        LOG.debug("Bean wrapper was not found for " + propertyPath
                + ", but since it cannot be accessed it will not be set as secure.", e);
        return false;
    }

    if (org.apache.commons.lang.StringUtils.isNotBlank(beanWrapper.getNestedPath())) {
        PropertyTokenHolder tokens = getPropertyNameTokens(propertyPath);
        String nestedPropertyPath = org.apache.commons.lang.StringUtils.removeStart(tokens.canonicalName,
                beanWrapper.getNestedPath());

        return isSecure(beanWrapper.getWrappedClass(), nestedPropertyPath);
    }

    return false;
}
项目:spring-rich-client    文件:AbstractPropertyAccessStrategyTests.java   
public void testWriteOnlyProperty() {
    vm = pas.getPropertyValueModel("writeOnly");

    vm.setValue("2");
    assertEquals("2" , testBean.writeOnly);

    try {
        vm.getValue();
        fail("should have thrown NotReadablePropertyException");
    } catch(NotReadablePropertyException e) {
        // expected
    }
}
项目:spring-rich-client    文件:DefaultMemberPropertyAccessor.java   
public Object getIndexedPropertyValue(String propertyName) throws BeansException {
    if (getPropertyType(propertyName) == null) {
        throw new NotReadablePropertyException(getTargetClass(), propertyName,
                "property type could not be determined");
    }
    String rootPropertyName = getRootPropertyName(propertyName);
    Member readAccessor = getReadPropertyAccessor(rootPropertyName);
    if (readAccessor == null) {
        throw new NotReadablePropertyException(getTargetClass(), propertyName,
                "Neither non-static field nor get-method exists for indexed property");
    }
    Object rootProperty = getPropertyValue(rootPropertyName);
    if (rootProperty == null) {
        if (isStrictNullHandlingEnabled()) {
            throw new NullValueInNestedPathException(getTargetClass(), propertyName);
        }
        else if (isWritableProperty(rootPropertyName)) {
            return null;
        }
        else {
            throw new NotReadablePropertyException(getTargetClass(), propertyName);
        }
    }
    Object[] indices;
    try {
        indices = getIndices(propertyName);
    }
    catch (Exception e) {
        // could not convert indices
        throw createNotReadablePropertyException(propertyName, e);
    }
    return getPropertyValue(rootProperty, indices);
}
项目:spring-richclient    文件:AbstractPropertyAccessStrategyTests.java   
public void testWriteOnlyProperty() {
    vm = pas.getPropertyValueModel("writeOnly");

    vm.setValue("2");
    assertEquals("2" , testBean.writeOnly);

    try {
        vm.getValue();
        fail("should have thrown NotReadablePropertyException");
    } catch(NotReadablePropertyException e) {
        // expected
    }
}
项目:spring-richclient    文件:DefaultMemberPropertyAccessor.java   
public Object getIndexedPropertyValue(String propertyName) throws BeansException {
    if (getPropertyType(propertyName) == null) {
        throw new NotReadablePropertyException(getTargetClass(), propertyName,
                "property type could not be determined");
    }
    String rootPropertyName = getRootPropertyName(propertyName);
    Member readAccessor = getReadPropertyAccessor(rootPropertyName);
    if (readAccessor == null) {
        throw new NotReadablePropertyException(getTargetClass(), propertyName,
                "Neither non-static field nor get-method exists for indexed property");
    }
    Object rootProperty = getPropertyValue(rootPropertyName);
    if (rootProperty == null) {
        if (isStrictNullHandlingEnabled()) {
            throw new NullValueInNestedPathException(getTargetClass(), propertyName);
        }
        else if (isWritableProperty(rootPropertyName)) {
            return null;
        }
        else {
            throw new NotReadablePropertyException(getTargetClass(), propertyName);
        }
    }
    Object[] indices;
    try {
        indices = getIndices(propertyName);
    }
    catch (Exception e) {
        // could not convert indices
        throw createNotReadablePropertyException(propertyName, e);
    }
    return getPropertyValue(rootProperty, indices);
}
项目:jdal    文件:DirectFieldAccessor.java   
@Override
public Object getPropertyValue(String propertyName) throws BeansException {
    Field field = this.fieldMap.get(propertyName);
    if (field == null) {
        throw new NotReadablePropertyException(
                this.target.getClass(), propertyName, "Field '" + propertyName + "' does not exist");
    }
    try {
        ReflectionUtils.makeAccessible(field);
        return field.get(this.target);
    }
    catch (IllegalAccessException ex) {
        throw new InvalidPropertyException(this.target.getClass(), propertyName, "Field is not accessible", ex);
    }
}