Search in sources :

Example 81 with PropertyDescriptor

use of java.beans.PropertyDescriptor in project iaf by ibissource.

the class AttributeCheckingRule method begin.

public void begin(String uri, String elementName, Attributes attributes) throws Exception {
    Object top = digester.peek();
    for (int i = 0; i < attributes.getLength(); i++) {
        String name = attributes.getLocalName(i);
        if ("".equals(name)) {
            name = attributes.getQName(i);
        }
        if (name != null && !name.equals("className")) {
            // if (log.isDebugEnabled()) {
            // log.debug(getObjectName(top)+" checking for setter for attribute ["+name+"]");
            // }
            PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(top, name);
            Method m = null;
            if (pd != null) {
                m = PropertyUtils.getWriteMethod(pd);
            }
            if (m == null) {
                Locator loc = digester.getDocumentLocator();
                String msg = "line " + loc.getLineNumber() + ", col " + loc.getColumnNumber() + ": " + getObjectName(top) + " does not have an attribute [" + name + "] to set to value [" + attributes.getValue(name) + "]";
                configWarnings.add(log, msg);
            }
        }
    }
}
Also used : Locator(org.xml.sax.Locator) PropertyDescriptor(java.beans.PropertyDescriptor) INamedObject(nl.nn.adapterframework.core.INamedObject) Method(java.lang.reflect.Method)

Example 82 with PropertyDescriptor

use of java.beans.PropertyDescriptor in project entando-core by entando.

the class AbstractObjectInfoTag method getPropertyValue.

protected Object getPropertyValue(Object masterObject, String propertyValue) {
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(masterObject.getClass());
        PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
        for (int i = 0; i < descriptors.length; i++) {
            PropertyDescriptor descriptor = descriptors[i];
            if (!descriptor.getName().equals(propertyValue)) {
                continue;
            }
            Method method = descriptor.getReadMethod();
            Object[] args = null;
            return method.invoke(masterObject, args);
        }
        _logger.debug("Invalid required object property : Master Object '{}' - property '{}'", masterObject.getClass().getName(), propertyValue);
    } catch (Throwable t) {
        _logger.error("Error extracting property value : Master Object {} - property: '{}'", masterObject.getClass().getName(), propertyValue, t);
    }
    return null;
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) Method(java.lang.reflect.Method)

Example 83 with PropertyDescriptor

use of java.beans.PropertyDescriptor in project apollo by ctripcorp.

the class SpringValueProcessor method processBeanPropertyValues.

private void processBeanPropertyValues(Object bean, String beanName) {
    Collection<SpringValueDefinition> propertySpringValues = beanName2SpringValueDefinitions.get(beanName);
    if (propertySpringValues == null || propertySpringValues.isEmpty()) {
        return;
    }
    for (SpringValueDefinition definition : propertySpringValues) {
        try {
            PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(bean.getClass(), definition.getPropertyName());
            Method method = pd.getWriteMethod();
            if (method == null) {
                continue;
            }
            SpringValue springValue = new SpringValue(definition.getKey(), definition.getPlaceholder(), bean, beanName, method, false);
            springValueRegistry.register(beanFactory, definition.getKey(), springValue);
            logger.debug("Monitoring {}", springValue);
        } catch (Throwable ex) {
            logger.error("Failed to enable auto update feature for {}.{}", bean.getClass(), definition.getPropertyName());
        }
    }
    // clear
    beanName2SpringValueDefinitions.removeAll(beanName);
}
Also used : SpringValue(com.ctrip.framework.apollo.spring.property.SpringValue) SpringValueDefinition(com.ctrip.framework.apollo.spring.property.SpringValueDefinition) PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method)

Example 84 with PropertyDescriptor

use of java.beans.PropertyDescriptor in project apollo by ctripcorp.

the class BeanUtils method getNullPropertyNames.

private static String[] getNullPropertyNames(Object source) {
    final BeanWrapper src = new BeanWrapperImpl(source);
    PropertyDescriptor[] pds = src.getPropertyDescriptors();
    Set<String> emptyNames = new HashSet<>();
    for (PropertyDescriptor pd : pds) {
        Object srcValue = src.getPropertyValue(pd.getName());
        if (srcValue == null) {
            emptyNames.add(pd.getName());
        }
    }
    String[] result = new String[emptyNames.size()];
    return emptyNames.toArray(result);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) PropertyDescriptor(java.beans.PropertyDescriptor) HashSet(java.util.HashSet)

Example 85 with PropertyDescriptor

use of java.beans.PropertyDescriptor in project archi by archimatetool.

the class AbstractTool method applyProperty.

/**
 * This method is invoked from {@link #setProperties(Map)}. Sub-classes can
 * override to add support for more properties. This method should fail
 * silently in case of any error.
 * <p>
 * AbstractTool uses introspection to match any keys with properties. For
 * instance, the key "defaultCursor" would lead to the invocation of
 * {@link #setDefaultCursor(Cursor)} with the provided value.
 *
 * @param key
 *            the key; may be <code>null</code>
 * @param value
 *            the new value
 * @since 3.1
 * @see #setProperties(Map)
 */
protected void applyProperty(Object key, Object value) {
    if (PROPERTY_UNLOAD_WHEN_FINISHED.equals(key)) {
        if (value instanceof Boolean)
            setUnloadWhenFinished(((Boolean) value).booleanValue());
        return;
    }
    if (!(key instanceof String))
        return;
    try {
        PropertyDescriptor[] descriptors = Introspector.getBeanInfo(getClass(), Introspector.IGNORE_ALL_BEANINFO).getPropertyDescriptors();
        PropertyDescriptor property = null;
        for (int i = 0; i < descriptors.length; i++) {
            if (descriptors[i].getName().equals(key)) {
                property = descriptors[i];
                break;
            }
        }
        if (property != null) {
            Method setter = property.getWriteMethod();
            // setter.setAccessible(true);
            setter.invoke(this, new Object[] { value });
        }
    } catch (IntrospectionException ie) {
    } catch (IllegalAccessException iae) {
    } catch (InvocationTargetException ite) {
    } catch (SecurityException se) {
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) Method(java.lang.reflect.Method) Point(org.eclipse.draw2d.geometry.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

PropertyDescriptor (java.beans.PropertyDescriptor)836 Method (java.lang.reflect.Method)396 BeanInfo (java.beans.BeanInfo)339 IntrospectionException (java.beans.IntrospectionException)188 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)171 SimpleBeanInfo (java.beans.SimpleBeanInfo)142 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)141 InvocationTargetException (java.lang.reflect.InvocationTargetException)108 ArrayList (java.util.ArrayList)90 HashMap (java.util.HashMap)66 Field (java.lang.reflect.Field)59 Map (java.util.Map)52 Test (org.junit.Test)39 IOException (java.io.IOException)34 MockJavaBean (org.apache.harmony.beans.tests.support.mock.MockJavaBean)34 List (java.util.List)33 HashSet (java.util.HashSet)21 Type (java.lang.reflect.Type)20 Set (java.util.Set)20 LinkedHashMap (java.util.LinkedHashMap)19