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

The following examples show how to use java.beans.PropertyDescriptor#getDisplayName() . 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
Source File: MetadataMBeanInfoAssembler.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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
Source File: MetadataMBeanInfoAssembler.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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
Source File: MetadataMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 File: ObjectUtil.java    From dble with 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
Source File: MetadataMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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 File: BeanAssert.java    From Cheddar with 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 File: PropertyDTO.java    From fabric8-forge with 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 File: EntityInfoWithId.java    From mongo-mapper with 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
Source File: MBeanClientInterceptorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
	return propertyDescriptor.getDisplayName();
}
 
Example 10
Source File: MBeanClientInterceptorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
	return propertyDescriptor.getDisplayName();
}
 
Example 11
Source File: MBeanClientInterceptorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
protected String getAttributeDescription(PropertyDescriptor propertyDescriptor) {
	return propertyDescriptor.getDisplayName();
}
 
Example 12
Source File: AbstractReflectiveMBeanInfoAssembler.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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
Source File: AbstractReflectiveMBeanInfoAssembler.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * 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
Source File: AbstractReflectiveMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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
Source File: AbstractReflectiveMBeanInfoAssembler.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * 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();
}