public static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception { synchronized (beanUtils) { beanUtils.setProperty(obj, "host", uri.getHost()); beanUtils.setProperty(obj, "port", uri.getPort()); beanUtils.setProperty(obj, "userInfo", uri.getUserInfo()); beanUtils.populate(obj, query); } return obj; }
@Override public void wrapper(ColumnMetadata instance, int index, String attr, Object value) { try { BeanUtilsBean.getInstance().setProperty(instance, attr, value); } catch (Exception e) { e.printStackTrace(); } }
private void setProperty(Object object, String propertyPath, Object value) { try { if (log.isTraceEnabled()) { log.trace("Applying property [{}] value [{}] on object of type [{}]", new Object[]{propertyPath, value, object.getClass().getName()}); } beanUtilsBean.setProperty(object, propertyPath, value); } catch (Exception e) { String msg = "Unable to set property '" + propertyPath + "' with value [" + value + "] on object " + "of type " + (object != null ? object.getClass().getName() : null) + ". If " + "'" + value + "' is a reference to another (previously defined) object, prefix it with " + "'" + OBJECT_REFERENCE_BEGIN_TOKEN + "' to indicate that the referenced " + "object should be used as the actual value. " + "For example, " + OBJECT_REFERENCE_BEGIN_TOKEN + value; throw new ConfigurationException(msg, e); } }
/** * <p>Set the specified property value, performing type conversions as * required to conform to the type of the destination property.</p> * * <p>For more details see <code>BeanUtilsBean</code>.</p> * * @param bean Bean on which setting is to be performed * @param name Property name (can be nested/indexed/mapped/combo) * @param value Value to be set * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @see BeanUtilsBean#setProperty */ public static void setProperty(final Object bean, final String name, final Object value) throws IllegalAccessException, InvocationTargetException { BeanUtilsBean.getInstance().setProperty(bean, name, value); }
/** * <p>Set the specified property value, performing type conversions as * required to conform to the type of the destination property.</p> * * <p>For more details see <code>BeanUtilsBean</code>.</p> * * @param bean Bean on which setting is to be performed * @param name Property name (can be nested/indexed/mapped/combo) * @param value Value to be set * * @throws IllegalAccessException if the caller does not have * access to the property accessor method * @throws InvocationTargetException if the property accessor method * throws an exception * @see BeanUtilsBean#setProperty */ public static void setProperty(final Object bean, final String name, final Object value) throws IllegalAccessException, InvocationTargetException { BeanUtilsBean.getInstance().setProperty(bean, name, value); }
setProperty(bean, name, entry.getValue());
setProperty(bean, name, entry.getValue());
public static <P> P setProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = properties.getProperty(descriptor.getName()); if (value != null) { beanUtils.setProperty(bean, descriptor.getName(), value); } } } } return bean; }
/** * Sets a property on the given bean using Common Beanutils. * * @param bean the bean * @param propName the name of the property * @param value the property's value * @throws ConfigurationRuntimeException if the property is not writeable or * an error occurred */ private static void initProperty(final Object bean, final String propName, final Object value) { if (!isPropertyWriteable(bean, propName)) { throw new ConfigurationRuntimeException("Property " + propName + " cannot be set on " + bean.getClass().getName()); } try { BEAN_UTILS_BEAN.setProperty(bean, propName, value); } catch (final IllegalAccessException iaex) { throw new ConfigurationRuntimeException(iaex); } catch (final InvocationTargetException itex) { throw new ConfigurationRuntimeException(itex); } }
private void setEndpointForClient(String name, BuilderDynaBean client, String endpoint) { try { utilsBean.setProperty(client, "endpointOverride", endpoint); } catch (IllegalAccessException | InvocationTargetException e) { log.error("Failed to set endpoint on {}", name, e); throw new IllegalStateException(e); } }
private void setRegionForClient(String name, BuilderDynaBean client, Region region) { try { utilsBean.setProperty(client, "region", region); } catch (IllegalAccessException | InvocationTargetException e) { log.error("Failed to set region on {}", name, e); throw new IllegalStateException(e); } }
public static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception { synchronized (beanUtils) { beanUtils.setProperty(obj, "host", uri.getHost()); beanUtils.setProperty(obj, "port", uri.getPort()); beanUtils.setProperty(obj, "userInfo", uri.getUserInfo()); beanUtils.populate(obj, query); } return obj; }
public static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception { synchronized (beanUtils) { beanUtils.setProperty(obj, "host", uri.getHost()); beanUtils.setProperty(obj, "port", uri.getPort()); beanUtils.setProperty(obj, "userInfo", uri.getUserInfo()); beanUtils.populate(obj, query); } return obj; }
public static <P> P setData(URI uri, P obj, Map<String, String> query) throws Exception { synchronized (beanUtils) { beanUtils.setProperty(obj, "host", uri.getHost()); beanUtils.setProperty(obj, "port", uri.getPort()); beanUtils.setProperty(obj, "userInfo", uri.getUserInfo()); beanUtils.populate(obj, query); } return obj; }
private void updateCredentials(BuilderDynaBean toUpdate, AwsCredentialsProvider primary, AwsCredentialsProvider secondary) { if (toUpdate.hasValue("credentialsProvider")) { return; } try { if (primary != null) { utilsBean.setProperty(toUpdate, "credentialsProvider", primary); } else if (secondary != null) { utilsBean.setProperty(toUpdate, "credentialsProvider", secondary); } } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException("Unable to update credentials", e); } }
@Override public void wrapper(ColumnMetadata instance, int index, String attr, Object value) { try { BeanUtilsBean.getInstance().setProperty(instance, attr, value); } catch (Exception e) { e.printStackTrace(); } }
protected static void overridePropertyFromEnv(Object conf, String prop) throws IOException { String value = System.getenv(PROPERTY_PREFIX + prop); if (StringUtils.isNotEmpty(value) && !"null".equals(value) && !value.startsWith("${")) { try { BeanUtilsBean.getInstance().setProperty(conf, prop, value); } catch (Exception e) { throw new IOException( "Could not set property '" + prop + "' with value '" + value + "' to configuration" ); } } }
public static <P> P setProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = properties.getProperty(descriptor.getName()); if (value != null) { beanUtils.setProperty(bean, descriptor.getName(), value); } } } } return bean; }
public static <P> P setProperties(P bean, Properties properties) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { synchronized (beanUtils) { PropertyDescriptor[] descriptors = beanUtils.getPropertyUtils().getPropertyDescriptors(bean); for (PropertyDescriptor descriptor : descriptors) { if (descriptor.getReadMethod() != null && isWriteable(descriptor, null)) { String value = properties.getProperty(descriptor.getName()); if (value != null) { beanUtils.setProperty(bean, descriptor.getName(), value); } } } } return bean; }
ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean(); convertUtilsBean.deregister(DateTime.class); convertUtilsBean.register(new JodaDateTimeConverter(), DateTime.class); BeanUtilsBean beanUtilsBean = new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean()); try { beanUtilsBean.setProperty(machineInfo, qName, temp); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); }