Example usage for java.beans PropertyDescriptor attributeNames

List of usage examples for java.beans PropertyDescriptor attributeNames

Introduction

In this page you can find the example usage for java.beans PropertyDescriptor attributeNames.

Prototype

public Enumeration<String> attributeNames() 

Source Link

Document

Gets an enumeration of the locale-independent names of this feature.

Usage

From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java

protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException {
    checkAdditionalProperties();/*from  w ww  .java  2 s.co  m*/
    for (int i = 0; i < properties.length; i++) {
        PropertyDescriptor property = properties[i];
        if (name.equals(property.getName())) {
            PropertyDescriptor clone = new PropertyDescriptor(name, property.getReadMethod(),
                    property.getWriteMethod());
            clone.setDisplayName(property.getDisplayName());
            clone.setShortDescription(property.getShortDescription());
            clone.setPropertyEditorClass(property.getPropertyEditorClass());
            clone.setBound(property.isBound());
            clone.setConstrained(property.isConstrained());
            clone.setExpert(property.isExpert());
            clone.setHidden(property.isHidden());
            clone.setPreferred(property.isPreferred());
            for (String attributeName : Collections.list(property.attributeNames())) {
                clone.setValue(attributeName, property.getValue(attributeName));
            }
            return properties[i] = clone;
        }
    }
    return null;
}

From source file:org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer.java

/**
 * Validate the descriptor attributes./*  ww  w. j  a v a  2 s  .com*/
 * 
 * @param pd the descriptor
 * @param pe the propertyEditor
 */
private static void validateAttributes(PropertyDescriptor pd, PropertyEditor pe) {
    final Object deflt = pd.getValue(DEFAULT);
    if (deflt == null) {
        if (notNull(pd)) {
            log.warn(getDetails(pd) + " requires a value but does not provide a default.");
        }
        if (noSaveDefault(pd)) {
            log.warn(getDetails(pd) + " specifies DEFAULT_NO_SAVE but does not provide a default.");
        }
    } else {
        final Class<?> defltClass = deflt.getClass(); // the DEFAULT class
        // Convert int to Integer etc:
        final Class<?> propClass = ClassUtils.primitiveToWrapper(pd.getPropertyType());
        if (!propClass.isAssignableFrom(defltClass)) {
            log.warn(getDetails(pd) + " has a DEFAULT of class " + defltClass.getCanonicalName());
        }
    }
    if (notOther(pd) && pd.getValue(TAGS) == null && pe.getTags() == null) {
        log.warn(getDetails(pd) + " does not have tags but other values are not allowed.");
    }
    if (!notNull(pd)) {
        Class<?> propertyType = pd.getPropertyType();
        if (propertyType.isPrimitive()) {
            log.warn(getDetails(pd) + " allows null but is a primitive type");
        }
    }
    if (!pd.attributeNames().hasMoreElements()) {
        log.warn(getDetails(pd) + " does not appear to have been configured");
    }
}