本文整理匯總了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();
}