List of usage examples for org.apache.commons.beanutils PropertyUtils getWriteMethod
public static Method getWriteMethod(PropertyDescriptor descriptor)
Return an accessible property setter method for this property, if there is one; otherwise return null
.
For more details see PropertyUtilsBean
.
From source file:org.settings4j.config.DOMConfigurator.java
/** * Sets a parameter based from configuration file content. * * @param elem/*from w w w . ja va 2 s . co m*/ * param element, may not be null. * @param propSetter * property setter, may not be null. * @param props * properties */ private void setParameter(final Element elem, final Object bean, final Connector[] connectors) { final String name = elem.getAttribute(NAME_ATTR); final String valueStr = elem.getAttribute(VALUE_ATTR); try { final PropertyDescriptor propertyDescriptor = PropertyUtils.getPropertyDescriptor(bean, name); final Method setter = PropertyUtils.getWriteMethod(propertyDescriptor); Object value; if (connectors != null) { value = subst(valueStr, connectors, setter.getParameterTypes()[0]); } else { value = subst(valueStr, null, setter.getParameterTypes()[0]); } PropertyUtils.setProperty(bean, name, value); } catch (final IllegalAccessException e) { LOG.warn("Cannnot set Property: {}", name, e); } catch (final InvocationTargetException e) { LOG.warn("Cannnot set Property: {}", name, e); } catch (final NoSuchMethodException e) { LOG.warn("Cannnot set Property: {}", name, e); } }
From source file:org.wildfly.swarm.microprofile.openapi.runtime.OpenApiAnnotationScanner.java
/** * Reads the CallbackOperation annotations as a PathItem. The annotation value * in this case is an array of CallbackOperation annotations. * @param value// ww w .ja v a2 s .co m */ private PathItem readCallbackOperations(AnnotationValue value) { if (value == null) { return null; } LOG.debug("Processing an array of @CallbackOperation annotations."); AnnotationInstance[] nestedArray = value.asNestedArray(); PathItem pathItem = new PathItemImpl(); for (AnnotationInstance operationAnno : nestedArray) { String method = JandexUtil.stringValue(operationAnno, OpenApiConstants.PROP_METHOD); Operation operation = readCallbackOperation(operationAnno); if (method == null) { continue; } try { PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(pathItem, method.toUpperCase()); Method mutator = PropertyUtils.getWriteMethod(descriptor); mutator.invoke(pathItem, operation); } catch (Exception e) { LOG.error("Error reading a CallbackOperation annotation.", e); } } return pathItem; }