Example usage for java.beans PropertyDescriptor getValue

List of usage examples for java.beans PropertyDescriptor getValue

Introduction

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

Prototype

public Object getValue(String attributeName) 

Source Link

Document

Retrieve a named attribute with this feature.

Usage

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

/**
 * Returns true if the property does not allow JMeter expressions.
 * /*from www  .jav a 2 s .  c om*/
 * @param descriptor the property descriptor
 * @return true if the attribute {@link #NOT_EXPRESSION} is defined and equal to Boolean.TRUE;
 *  otherwise the default is false
 */
static boolean notExpression(PropertyDescriptor descriptor) {
    boolean notExpression = Boolean.TRUE.equals(descriptor.getValue(NOT_EXPRESSION));
    return notExpression;
}

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

/**
 * Returns true if the property must be defined (i.e. is required); 
 * // w w w  . jav  a 2 s.c o  m
 * @param descriptor the property descriptor
 * @return true if the attribute {@link #NOT_UNDEFINED} is defined and equal to Boolean.TRUE;
 *  otherwise the default is false
 */
static boolean notNull(PropertyDescriptor descriptor) {
    boolean notNull = Boolean.TRUE.equals(descriptor.getValue(NOT_UNDEFINED));
    return notNull;
}

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

/**
 * Returns true if the property default value is not saved
 * /*from   www.j  a v a 2s.  co  m*/
 * @param descriptor the property descriptor
 * @return true if the attribute {@link #DEFAULT_NOT_SAVED} is defined and equal to Boolean.TRUE;
 *  otherwise the default is false
 */
static boolean noSaveDefault(PropertyDescriptor descriptor) {
    return Boolean.TRUE.equals(descriptor.getValue(DEFAULT_NOT_SAVED));
}

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

/**
 * {@inheritDoc}/*from www.  j  a  v  a  2 s.  c o  m*/
 * @param map must be an instance of Map<String, Object>
 */
@SuppressWarnings("unchecked")
@Override
public void setObject(Object map) {
    propertyMap = (Map<String, Object>) map;

    if (propertyMap.size() == 0) {
        // Uninitialized -- set it to the defaults:
        for (PropertyDescriptor descriptor : descriptors) {
            Object value = descriptor.getValue(DEFAULT);
            String name = descriptor.getName();
            if (value != null) {
                propertyMap.put(name, value);
                log.debug("Set " + name + "= " + value);
            }
            firePropertyChange(name, null, value);
        }
    }

    // Now set the editors to the element's values:
    for (int i = 0; i < editors.length; i++) {
        if (editors[i] == null) {
            continue;
        }
        try {
            setEditorValue(i, propertyMap.get(descriptors[i].getName()));
        } catch (IllegalArgumentException e) {
            // I guess this can happen as a result of a bad
            // file read? In this case, it would be better to replace the
            // incorrect value with anything valid, e.g. the default value
            // for the property.
            // But for the time being, I just prefer to be aware of any
            // problems occuring here, most likely programming errors,
            // so I'll bail out.
            // (MS Note) Can't bail out - newly create elements have blank
            // values and must get the defaults.
            // Also, when loading previous versions of jmeter test scripts,
            // some values
            // may not be right, and should get default values - MS
            // TODO: review this and possibly change to:
            setEditorValue(i, descriptors[i].getValue(DEFAULT));
        }
    }
}

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

/**
 * Obtain a property descriptor's group.
 *
 * @param descriptor/*from  w w w  .  j a v a  2  s  .com*/
 * @return the group String.
 */
private static String group(PropertyDescriptor descriptor) {
    String group = (String) descriptor.getValue(GROUP);
    if (group == null) {
        group = DEFAULT_GROUP;
    }
    return group;
}

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

/**
 * {@inheritDoc}//  w w  w.  j av a2 s  .  c  om
 */
@Override
public void modifyTestElement(TestElement element) {
    // Fetch data from screen fields
    if (customizer instanceof GenericTestBeanCustomizer) {
        GenericTestBeanCustomizer gtbc = (GenericTestBeanCustomizer) customizer;
        gtbc.saveGuiFields();
    }
    configureTestElement(element);

    // Copy all property values from the map into the element:
    for (PropertyDescriptor desc : beanInfo.getPropertyDescriptors()) {
        String name = desc.getName();
        Object value = propertyMap.get(name);
        log.debug("Modify " + name + " to " + value);
        if (value == null) {
            if (GenericTestBeanCustomizer.notNull(desc)) { // cannot be null
                if (GenericTestBeanCustomizer.noSaveDefault(desc)) {
                    log.debug("Did not set DEFAULT for " + name);
                    element.removeProperty(name);
                } else {
                    setPropertyInElement(element, name, desc.getValue(GenericTestBeanCustomizer.DEFAULT));
                }
            } else {
                element.removeProperty(name);
            }
        } else {
            if (GenericTestBeanCustomizer.noSaveDefault(desc)
                    && value.equals(desc.getValue(GenericTestBeanCustomizer.DEFAULT))) {
                log.debug("Did not set " + name + " to the default: " + value);
                element.removeProperty(name);
            } else {
                setPropertyInElement(element, name, value);
            }
        }
    }
}

From source file:org.xmlactions.mapping.xml_to_bean.PopulateClassFromXml.java

public static PropertyDescriptor findPropertyDescriptor(Object object, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    PropertyDescriptor pd = null;
    PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(object);
    for (PropertyDescriptor p : pds) {
        if (p.getName().equals(name)) {
            pd = p;//from w  w w.  j  a  v a  2  s  . c  om
            break;
        }
    }
    if (pd != null) {
        log.debug("PropertyDescriptor [" + name + "] - " + " Name:" + pd.getName() + " DisplayName:"
                + pd.getDisplayName() + " ShortDescription:" + pd.getShortDescription() + " PropertyType:"
                + pd.getPropertyType() + " ReadMethod:" + pd.getReadMethod() + " WriteMethod:"
                + pd.getWriteMethod() + " Value:" + pd.getValue(name));
        // } else {
        // log.error("PropertyDescriptor [" + name +
        // "] -  not found in class [" + object.getClass().getName() + "]");
    }
    return pd;

}