本文整理汇总了Java中java.beans.PropertyDescriptor.getDisplayName方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyDescriptor.getDisplayName方法的具体用法?Java PropertyDescriptor.getDisplayName怎么用?Java PropertyDescriptor.getDisplayName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.beans.PropertyDescriptor
的用法示例。
在下文中一共展示了PropertyDescriptor.getDisplayName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAttributeDescription
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
* Creates a description for the attribute corresponding to this property
* descriptor. Attempts to create the description using metadata from either
* the getter or setter attributes, otherwise uses the property name.
*/
@Override
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor, String beanKey) {
Method readMethod = propertyDescriptor.getReadMethod();
Method writeMethod = propertyDescriptor.getWriteMethod();
ManagedAttribute getter =
(readMethod != null ? this.attributeSource.getManagedAttribute(readMethod) : null);
ManagedAttribute setter =
(writeMethod != null ? this.attributeSource.getManagedAttribute(writeMethod) : null);
if (getter != null && StringUtils.hasText(getter.getDescription())) {
return getter.getDescription();
}
else if (setter != null && StringUtils.hasText(setter.getDescription())) {
return setter.getDescription();
}
ManagedMetric metric = (readMethod != null ? this.attributeSource.getManagedMetric(readMethod) : null);
if (metric != null && StringUtils.hasText(metric.getDescription())) {
return metric.getDescription();
}
return propertyDescriptor.getDisplayName();
}
示例2: copyProperties
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static void copyProperties(Object fromObj, Object toObj) {
Class<?> fromClass = fromObj.getClass();
Class<?> toClass = toObj.getClass();
try {
BeanInfo fromBean = Introspector.getBeanInfo(fromClass);
BeanInfo toBean = Introspector.getBeanInfo(toClass);
PropertyDescriptor[] toPd = toBean.getPropertyDescriptors();
List<PropertyDescriptor> fromPd = Arrays.asList(fromBean.getPropertyDescriptors());
for (PropertyDescriptor propertyDescriptor : toPd) {
propertyDescriptor.getDisplayName();
PropertyDescriptor pd = fromPd.get(fromPd.indexOf(propertyDescriptor));
if (pd.getDisplayName().equals(
propertyDescriptor.getDisplayName()) &&
!pd.getDisplayName().equals("class") &&
propertyDescriptor.getWriteMethod() != null) {
propertyDescriptor.getWriteMethod().invoke(toObj, pd.getReadMethod().invoke(fromObj, null));
}
}
} catch (IntrospectionException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
throw new RuntimeException(e);
}
}
示例3: inject
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public void inject(Object bean, BeanAccess props)
{
for (PropertyDescriptor pd : getPropertyDescriptors(bean.getClass()))
{
try
{
Method method = pd.getWriteMethod();
String name = pd.getName();
if ((method != null) && (props.propLength(name) != 0))
{
Object value;
if (pd.getPropertyType().isArray())
{
value = Array.newInstance(pd.getPropertyType().getComponentType(), props.propLength(name));
for (int i = 0; i < props.propLength(name); i++)
{
Array.set(value, i, parse(props.propGet(name, i), pd.getPropertyType().getComponentType()));
}
}
else
{
value = parse(props.propGet(name), pd.getPropertyType());
}
method.invoke(bean, value);
}
}
catch (Exception x)
{
throw new IllegalArgumentException("Failed to set property: " + pd.getDisplayName(), x);
}
}
}
示例4: getAttributeDescription
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
* Get the description for a particular attribute.
* <p>The default implementation returns a description for the operation
* that is the name of corresponding {@code Method}.
* @param propertyDescriptor the PropertyDescriptor for the attribute
* @param beanKey the key associated with the MBean in the beans map
* of the {@code MBeanExporter}
* @return the description for the attribute
*/
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor, String beanKey) {
return propertyDescriptor.getDisplayName();
}