Java Code Examples for java.beans.PropertyDescriptor#getDisplayName()

The following examples show how to use java.beans.PropertyDescriptor#getDisplayName() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * 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 ? obtainAttributeSource().getManagedAttribute(readMethod) : null);
	ManagedAttribute setter =
			(writeMethod != null ? obtainAttributeSource().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 ? obtainAttributeSource().getManagedMetric(readMethod) : null);
	if (metric != null && StringUtils.hasText(metric.getDescription())) {
		return metric.getDescription();
	}

	return propertyDescriptor.getDisplayName();
}
 
Example 2
/**
 * 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 ? obtainAttributeSource().getManagedAttribute(readMethod) : null);
	ManagedAttribute setter =
			(writeMethod != null ? obtainAttributeSource().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 ? obtainAttributeSource().getManagedMetric(readMethod) : null);
	if (metric != null && StringUtils.hasText(metric.getDescription())) {
		return metric.getDescription();
	}

	return propertyDescriptor.getDisplayName();
}
 
Example 3
/**
 * 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();
}
 
Example 4
Source Project: dble   File: ObjectUtil.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 5
/**
 * 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();
}
 
Example 6
Source Project: Cheddar   File: BeanAssert.java    License: Apache License 2.0 6 votes vote down vote up
private static <T> void assertValidPublicGetterSetterPairs(final Class<T> beanClass) {
    for (final PropertyDescriptor propertyDescriptor : getPropertyDescriptors(beanClass)) {
        final Method writeMethod = propertyDescriptor.getWriteMethod();
        final Method readMethod = propertyDescriptor.getReadMethod();
        if (writeMethod == null || readMethod == null) {
            throw new AssertionError(
                    "Invalid getter/setter pair for property: " + propertyDescriptor.getDisplayName());
        }
        if (writeMethod.isAccessible()) {
            throw new AssertionError("Setter is not public");
        }
        if (readMethod.isAccessible()) {
            throw new AssertionError("Getter is not public");
        }
    }
}
 
Example 7
Source Project: fabric8-forge   File: PropertyDTO.java    License: Apache License 2.0 5 votes vote down vote up
public PropertyDTO(PropertyDescriptor propertyDescriptor) {
    name = propertyDescriptor.getName();
    displayName = propertyDescriptor.getDisplayName();
    typeClass = propertyDescriptor.getPropertyType();
    typeName = typeClass.getName();
    description = propertyDescriptor.getShortDescription();
    readable = propertyDescriptor.getReadMethod() != null;
    writeable = propertyDescriptor.getWriteMethod() != null;
}
 
Example 8
Source Project: mongo-mapper   File: EntityInfoWithId.java    License: Apache License 2.0 5 votes vote down vote up
EntityInfoWithId(Class<?> clazz, Class<?> idClass) {
    super(clazz);
    this.idClass = idClass;

    // Find ID property.
    String idColumn = null;
    for (PropertyDescriptor pd : descriptors) {

        if (pd.getReadMethod() != null && !"class".equals(pd.getName())) {
            Annotation[] declaredAnnotations = pd.getReadMethod().getDeclaredAnnotations();
            for (Annotation annotation : declaredAnnotations) {
                if (annotation.annotationType().equals(idClass) || annotation.annotationType().equals(javax.persistence.Id.class)) {
                    idColumn = pd.getDisplayName();
                    break;
                }
            }
        }
    }

    if (idColumn == null) {
        idColumn = findIdAnnotation(clazz);
        if (idColumn == null) {
            throw new MongoMapperException("No ID field defined on class " + clazz.getCanonicalName());
        }
    }

    idField = idColumn;
}
 
Example 9
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
	return propertyDescriptor.getDisplayName();
}
 
Example 10
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
	return propertyDescriptor.getDisplayName();
}
 
Example 11
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
	return propertyDescriptor.getDisplayName();
}
 
Example 12
/**
 * 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();
}
 
Example 13
/**
 * 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();
}
 
Example 14
/**
 * 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();
}
 
Example 15
/**
 * 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();
}