本文整理汇总了Java中org.springframework.beans.BeanWrapper.getPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:Java BeanWrapper.getPropertyValue方法的具体用法?Java BeanWrapper.getPropertyValue怎么用?Java BeanWrapper.getPropertyValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.beans.BeanWrapper
的用法示例。
在下文中一共展示了BeanWrapper.getPropertyValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObject
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Override
public Object getObject() throws BeansException {
BeanWrapper target = this.targetBeanWrapper;
if (target != null) {
if (logger.isWarnEnabled() && this.targetBeanName != null &&
this.beanFactory instanceof ConfigurableBeanFactory &&
((ConfigurableBeanFactory) this.beanFactory).isCurrentlyInCreation(this.targetBeanName)) {
logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " +
"reference - obtained value for property '" + this.propertyPath + "' may be outdated!");
}
}
else {
// Fetch prototype target bean...
Object bean = this.beanFactory.getBean(this.targetBeanName);
target = PropertyAccessorFactory.forBeanPropertyAccess(bean);
}
return target.getPropertyValue(this.propertyPath);
}
示例2: getId
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public ID getId(T entity) {
Class<?> domainClass = getJavaType();
while (domainClass != Object.class) {
for (Field field : domainClass.getDeclaredFields()) {
if (field.getAnnotation(Id.class) != null) {
try {
return (ID) field.get(entity);
}
catch (IllegalArgumentException | IllegalAccessException e) {
BeanWrapper beanWrapper = PropertyAccessorFactory
.forBeanPropertyAccess(entity);
return (ID) beanWrapper.getPropertyValue(field.getName());
}
}
}
domainClass = domainClass.getSuperclass();
}
throw new IllegalStateException("id not found");
}
示例3: writeObjectEntry
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Copy & Paste, 无修正.
*/
private void writeObjectEntry(TagWriter tagWriter, String valueProperty, String labelProperty, Object item,
int itemIndex) throws JspException {
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(item);
Object renderValue;
if (valueProperty != null) {
renderValue = wrapper.getPropertyValue(valueProperty);
} else if (item instanceof Enum) {
renderValue = ((Enum<?>) item).name();
} else {
renderValue = item;
}
Object renderLabel = (labelProperty != null ? wrapper.getPropertyValue(labelProperty) : item);
writeElementTag(tagWriter, item, renderValue, renderLabel, itemIndex);
}
示例4: doRenderFromCollection
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Renders the inner '{@code option}' tags using the supplied {@link Collection} of
* objects as the source. The value of the {@link #valueProperty} field is used
* when rendering the '{@code value}' of the '{@code option}' and the value of the
* {@link #labelProperty} property is used when rendering the label.
*/
private void doRenderFromCollection(Collection<?> optionCollection, TagWriter tagWriter) throws JspException {
for (Object item : optionCollection) {
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(item);
Object value;
if (this.valueProperty != null) {
value = wrapper.getPropertyValue(this.valueProperty);
}
else if (item instanceof Enum) {
value = ((Enum<?>) item).name();
}
else {
value = item;
}
Object label = (this.labelProperty != null ? wrapper.getPropertyValue(this.labelProperty) : item);
renderOption(tagWriter, item, value, label);
}
}
示例5: handle
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <E> E handle(Object obj,Class<E> clz,Map<String,Strategy<?>> targetAndStrategy) throws Exception{
E bean = null;
if(clz.isAssignableFrom(obj.getClass())){
bean = (E)obj;
}else{
throw new Exception("Object obj is not an instance of Class clz");
}
BeanWrapper bw = new BeanWrapperImpl(bean);
Set<String> keySet = targetAndStrategy.keySet();
for (String key : keySet) {
@SuppressWarnings("rawtypes")
Strategy s = targetAndStrategy.get(key);
Object oldVal = bw.getPropertyValue(key);
Object handledValue = s.handle(oldVal);
bw.setPropertyValue(key, handledValue);
}
return bean;
}
示例6: getValue
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
public Object getValue(Object target) {
BeanWrapper bw = new BeanWrapperImpl(target);
Object object = bw.getPropertyValue(field.getName());
if(object == null)
return null;
boolean isEnum = object.getClass().isEnum();
if (object.getClass().isEnum() && IEnumMessage.class.isAssignableFrom(object.getClass())) {
return ((IEnumMessage) object).getValue();
}
if (object instanceof DateTime) {
DateTime dateTime = (DateTime) object;
return dateTime.toString("yyyy-MM-dd HH:mm:ss");
}
return object;
}
示例7: persist
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
public void persist(Object entity) {
// ReflectionUtils.
BeanWrapper instance = new BeanWrapperImpl(entity);
try {
Object obj = instance.getPropertyValue("identification");
if (obj == null) {
instance.setPropertyValue("identification", new Identification());
obj = instance.getPropertyValue("identification");
}
if (obj instanceof Identification) {
Identification ident = (Identification) obj;
ident.setCreated(new Date());
}
} catch (Exception e) {
log.warn(e.getMessage());
}
em.persist(entity);
}
示例8: getFieldWithAnnotation
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
public static Object getFieldWithAnnotation(Object domainObj, Class<? extends Annotation> annotationClass)
throws SecurityException, BeansException {
Object value = null;
Field field = findFieldWithAnnotation(domainObj, annotationClass);
if (field != null && field.getAnnotation(annotationClass) != null) {
try {
PropertyDescriptor descriptor = org.springframework.beans.BeanUtils.getPropertyDescriptor(domainObj.getClass(), field.getName());
if (descriptor != null) {
BeanWrapper wrapper = new BeanWrapperImpl(domainObj);
value = wrapper.getPropertyValue(field.getName());
} else {
value = ReflectionUtils.getField(field, domainObj);
}
return value;
} catch (IllegalArgumentException iae) {}
}
return value;
}
示例9: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null)
emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例10: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
public static String[] getNullPropertyNames(Object source, Set<String> notCopiedAttributes) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet(notCopiedAttributes);
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例11: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Returns an array of fields that have attributes with <i>null</i> value in
* the desired object.
*
* @param source
* {@link Object} updated object.
* @return {@link String} array of fields that have attributes with
* <i>null</i> value in the desired object.
*/
private static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例12: testBeanWrapper
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
@Test
public void testBeanWrapper(){
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
bw.setPropertyValue("name", "haoc");
Object value = bw.getPropertyValue("name");
System.out.println(value);
}
示例13: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
public static String[] getNullPropertyNames (Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for(java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例14: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
private static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例15: appendPropertyValues
import org.springframework.beans.BeanWrapper; //导入方法依赖的package包/类
/**
* Appends all property values on the given {@link StringBuilder}
*/
private void appendPropertyValues(final StringBuilder sb, final Object bean) {
if (bean == null) {
sb.append("<null>");
return;
} else if (bean instanceof String) {
sb.append(bean);
return;
}
BeanWrapper bw = new BeanWrapperImpl(bean);
boolean first = true;
for (PropertyDescriptor desc : bw.getPropertyDescriptors()) {
if (desc.getWriteMethod() == null) {
// Only log readable and writable properties
continue;
}
if (first) {
first = false;
} else {
sb.append(", ");
}
String name = desc.getName();
sb.append(name).append('=');
Object value = bw.getPropertyValue(name);
appendValue(sb, FormatObject.maskIfNeeded(name, value));
}
}