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);
}
}
}
}
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;
}
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);
}
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);
}
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) {
}
}
Aggregations