当前位置: 首页>>代码示例>>Java>>正文


Java NullValueInNestedPathException类代码示例

本文整理汇总了Java中org.springframework.beans.NullValueInNestedPathException的典型用法代码示例。如果您正苦于以下问题:Java NullValueInNestedPathException类的具体用法?Java NullValueInNestedPathException怎么用?Java NullValueInNestedPathException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NullValueInNestedPathException类属于org.springframework.beans包,在下文中一共展示了NullValueInNestedPathException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBindingNoErrorsWithInvalidField

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
@Test
public void testBindingNoErrorsWithInvalidField() throws Exception {
	TestBean rod = new TestBean();
	DataBinder binder = new DataBinder(rod, "person");
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("name", "Rod");
	pvs.add("spouse.age", 32);

	try {
		binder.bind(pvs);
		fail("Should have thrown NullValueInNestedPathException");
	}
	catch (NullValueInNestedPathException ex) {
		// expected
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:DataBinderTests.java

示例2: getPropertyValue

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
/**
 * Returns the value for the given property growing nested paths depending on the parameter.
 *
 * @param propertyName name of the property to get value for
 * @param autoGrowNestedPaths whether nested paths should be grown (initialized if null)
 * @return value for property
 */
protected Object getPropertyValue(String propertyName, boolean autoGrowNestedPaths) {
    setAutoGrowNestedPaths(autoGrowNestedPaths);

    Object value = null;
    try {
        value = super.getPropertyValue(propertyName);
    } catch (NullValueInNestedPathException e) {
        // swallow null values in path and return null as the value
    } catch (InvalidPropertyException e1) {
        if (!(e1.getRootCause() instanceof NullValueInNestedPathException)) {
            throw e1;
        }
    }

    return value;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:24,代码来源:UifBeanWrapper.java

示例3: testGetPropertyValueNullSafe

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
@Test
  public void testGetPropertyValueNullSafe() {
DataObject dataObject = new DataObject("a", "b", 3, "one");
DataObjectWrapper<DataObject> wrap = new DataObjectWrapperImpl<DataObject>(dataObject, dataObjectMetadata,
		dataObjectService,
              referenceLinker);
      assertNull(wrap.getPropertyValue("dataObject2"));

      //wrap.setPropertyValue("dataObject2.dataObject3", new DataObject3());

      // assert that a NullValueInNestedPathException is thrown
      try {
          wrap.getPropertyValue("dataObject2.dataObject3");
          fail("NullValueInNestedPathException should have been thrown");
      } catch (NullValueInNestedPathException e) {
          // this should be thrown!
      }

      // now do a null-safe check
      assertNull(wrap.getPropertyValueNullSafe("dataObject2.dataObject3"));

  }
 
开发者ID:kuali,项目名称:kc-rice,代码行数:23,代码来源:DataObjectWrapperBaseTest.java

示例4: copyFieldValues

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
public static <T> T copyFieldValues(final List<String> fieldsToCopy, final T source, final Class<T> typeOfT) {
    try {
        final BeanWrapper src = new BeanWrapperImpl(source);
        final BeanWrapper target = new BeanWrapperImpl(typeOfT.newInstance());
        fieldsToCopy.forEach(t -> {
            try {
                Object propertyValue = src.getPropertyValue(t);
                if (propertyValue instanceof String) {
                    propertyValue = ((String) propertyValue).trim();
                }
                target.setPropertyValue(t, propertyValue);
            } catch (final NullValueInNestedPathException ignore) {
            }
        });
        return (T) target.getWrappedInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        return null;
    }
}
 
开发者ID:Appendium,项目名称:objectlabkit,代码行数:20,代码来源:CukeUtils.java

示例5: nestedBindingWithDisabledAutoGrow

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
@Test
public void nestedBindingWithDisabledAutoGrow() throws Exception {
	FieldAccessBean rod = new FieldAccessBean();
	DataBinder binder = new DataBinder(rod, "person");
	binder.setAutoGrowNestedPaths(false);
	binder.initDirectFieldAccess();
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.addPropertyValue(new PropertyValue("spouse.name", "Kerry"));

	thrown.expect(NullValueInNestedPathException.class);
	binder.bind(pvs);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:DataBinderFieldAccessTests.java

示例6: isSecure

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:35,代码来源:UifViewBeanWrapper.java

示例7: getPropertyValueNullSafe

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Object getPropertyValueNullSafe(String propertyName) throws BeansException {
    try {
        return getPropertyValue(propertyName);
    } catch (NullValueInNestedPathException e) {
        return null;
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:12,代码来源:DataObjectWrapperBase.java

示例8: extract

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
@Override
public Object[] extract(BaseData item) {
	Object[] values = new Object[names.length];
	Term extensionTerm = termFactory.findTerm(extension);
	Map<Term,String> propertyMap = DarwinCorePropertyMap.getPropertyMap(extensionTerm);
	BeanWrapper beanWrapper = new BeanWrapperImpl(item);
	for(int i = 0; i < names.length; i++) {
		String property = names[i];
		Term propertyTerm = termFactory.findTerm(property);
		String propertyName = propertyMap.get(propertyTerm);
		try {
			String value = conversionService.convert(beanWrapper.getPropertyValue(propertyName), String.class);
			if(quoteCharacter == null) {
				values[i] = value;
			} else if(value != null) {
				values[i] = new StringBuilder().append(quoteCharacter).append(value).append(quoteCharacter).toString();
			} else {
				values[i] = new StringBuilder().append(quoteCharacter).append(quoteCharacter).toString();
			}
		} catch(PropertyAccessException pae) {
			if(quoteCharacter != null) {
				values[i] = new StringBuilder().append(quoteCharacter).append(quoteCharacter).toString();
			}
		} catch(NullValueInNestedPathException nvinpe) {
			if(quoteCharacter != null) {
				values[i] = new StringBuilder().append(quoteCharacter).append(quoteCharacter).toString();
			}
		}

	}
	return values;
}
 
开发者ID:RBGKew,项目名称:eMonocot,代码行数:33,代码来源:DwcFieldExtractor.java

示例9: testBindingNoErrorsWithInvalidField

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
public void testBindingNoErrorsWithInvalidField() throws Exception {
	TestBean rod = new TestBean();
	DataBinder binder = new DataBinder(rod, "person");
	MutablePropertyValues pvs = new MutablePropertyValues();
	pvs.add("name", "Rod");
	pvs.add("spouse.age", 32);

	try {
		binder.bind(pvs);
		fail("Should have thrown NullValueInNestedPathException");
	}
	catch (NullValueInNestedPathException ex) {
		// expected
	}
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:16,代码来源:DataBinderTests.java

示例10: testChildPropertyAccessStrategy

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
public void testChildPropertyAccessStrategy() {
    final TestBean nestedProperty = new TestBean();
    testBean.setNestedProperty(nestedProperty);
    MutablePropertyAccessStrategy cpas = pas.getPropertyAccessStrategyForPath("nestedProperty");

    assertEquals("Child domainObjectHolder should equal equivalent parent ValueModel",
            pas.getPropertyValueModel("nestedProperty"), cpas.getDomainObjectHolder());

    vm = cpas.getPropertyValueModel("simpleProperty");
    assertEquals("Child should return the same ValueModel as parent",
            pas.getPropertyValueModel("nestedProperty.simpleProperty"), vm);

    Block setValueDirectly = new Block() {
        public void handle(Object newValue) {
            nestedProperty.setSimpleProperty((String)newValue);
        }
    };
    Closure getValueDirectly = new Closure() {
        public Object call(Object ignore) {
            return nestedProperty.getSimpleProperty();
        }
    };
    Object[] valuesToTest = new Object[] {"1", "2", null, "3"};

    testSettingAndGetting(valuesToTest, getValueDirectly, setValueDirectly);

    try {
        pas.getPropertyValueModel("nestedProperty").setValue(null);
        if (isStrictNullHandlingEnabled())
        	fail("Should have thrown a NullValueInNestedPathException");
    }
    catch (NullValueInNestedPathException e) {
        if (!isStrictNullHandlingEnabled())
        	fail("Should not have thrown a NullValueInNestedPathException");
    }
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:37,代码来源:AbstractPropertyAccessStrategyTests.java

示例11: testMapProperty

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
public void testMapProperty() {
    final Map map = new HashMap();
    testBean.setMapProperty(map);
    vm = pas.getPropertyValueModel("mapProperty[.key]");
    Block setValueDirectly = new Block() {
        public void handle(Object newValue) {
            map.put(".key", newValue);
        }
    };
    Closure getValueDirectly = new Closure() {
        public Object call(Object ignore) {
            return map.get(".key");
        }
    };
    Object[] valuesToTest = new Object[] {"1", "2", null, "3"};
    testSettingAndGetting(valuesToTest, getValueDirectly, setValueDirectly);

    try {
        pas.getPropertyValueModel("mapProperty").setValue(null);
        if (isStrictNullHandlingEnabled())
        	fail("Should have thrown a NullValueInNestedPathException");
    }
    catch (NullValueInNestedPathException e) {
        if (!isStrictNullHandlingEnabled())
        	fail("Should not have thrown a NullValueInNestedPathException");
    }
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:28,代码来源:AbstractPropertyAccessStrategyTests.java

示例12: getIndexedPropertyValue

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
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);
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:34,代码来源:DefaultMemberPropertyAccessor.java

示例13: getPropertyValue

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
private Object getPropertyValue(Object assemblage, Object[] indices, int parameterIndex) {
	if (assemblage == null) {
		if (isStrictNullHandlingEnabled()) {
			throw new NullValueInNestedPathException(getTargetClass(), "");
		}
		else {
			return null;
		}
	}
	Object value = null;
	if (assemblage.getClass().isArray()) {
		value = getArrayValue(assemblage, (Integer) indices[parameterIndex]);
	}
	else if (assemblage instanceof List) {
		value = getListValue((List) assemblage, (Integer) indices[parameterIndex]);
	}
	else if (assemblage instanceof Map) {
		value = getMapValue((Map) assemblage, indices[parameterIndex]);
	}
	else if (assemblage instanceof Collection) {
		value = getCollectionValue((Collection) assemblage, (Integer) indices[parameterIndex]);
	}
	else {
		throw new IllegalStateException(
				"getPropertyValue(Object, Object[], int) called with neither array nor collection nor map");
	}
	if (parameterIndex == indices.length - 1) {
		return value;
	}
	if (value == null) {
		if (isStrictNullHandlingEnabled()) {
			throw new InvalidPropertyException(getTargetClass(), "", "");
		}
		else {
			return null;
		}
	}
	return getPropertyValue(value, indices, parameterIndex + 1);
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:40,代码来源:DefaultMemberPropertyAccessor.java

示例14: getPropertyValue

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
public Object getPropertyValue(String propertyPath) {
	if (PropertyAccessorUtils.isNestedProperty(propertyPath)) {
		String baseProperty = getBasePropertyName(propertyPath);
		String childPropertyPath = getChildPropertyPath(propertyPath);
		return ((PropertyAccessor) childPropertyAccessors.get(baseProperty)).getPropertyValue(childPropertyPath);
	}
	else if (isStrictNullHandlingEnabled() && getTarget() == null) {
		throw new NullValueInNestedPathException(getTargetClass(), propertyPath);
	}
	else {
		return super.getPropertyValue(propertyPath);
	}
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:14,代码来源:AbstractNestedMemberPropertyAccessor.java

示例15: setPropertyValue

import org.springframework.beans.NullValueInNestedPathException; //导入依赖的package包/类
public void setPropertyValue(String propertyPath, Object value) {
	if (PropertyAccessorUtils.isNestedProperty(propertyPath)) {
		String baseProperty = getBasePropertyName(propertyPath);
		String childPropertyPath = getChildPropertyPath(propertyPath);
		((PropertyAccessor) childPropertyAccessors.get(baseProperty)).setPropertyValue(childPropertyPath, value);
	}
	else if (isStrictNullHandlingEnabled() && getTarget() == null) {
		throw new NullValueInNestedPathException(getTargetClass(), propertyPath);
	}
	else {
		super.setPropertyValue(propertyPath, value);
	}
}
 
开发者ID:shevek,项目名称:spring-rich-client,代码行数:14,代码来源:AbstractNestedMemberPropertyAccessor.java


注:本文中的org.springframework.beans.NullValueInNestedPathException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。